Install php5 alongside with php7

5,791

I know this post has been here for a long time but I would answer anyway.

You can install php5 alongside.

All you need to do is install php5.

After installing it, you would have multiple folders holding the different version of your php version.

  1. First start by adding Ondřej Surý PPA to install different versions of PHP – PHP 5.6, PHP 7.0 and PHP 7.1 on Ubuntu system.

    sudo apt install python-software-properties
    
    sudo add-apt-repository ppa:ondrej/php
    
    ##For Apache Web Server
    sudo apt install php5.6
    

    Now you can install most required PHP modules from the list.

  2. Install PHP Modules

    sudo apt install php5.6-cli php5.6-xml php5.6-mysql 
    
  3. To switch between the versions

    1. First make sure you stop your apache2 service

      sudo service apache2 stop
      sudo a2dismod php7
      
    2. I would suggest you run phpinfo() after the above steps to confirm the version running on your computer, if all went well, you should most likely get an error, as no php file would run.

    3. Enable e.g. php5.6

      sudo a2enmod php5.6
      
    4. Restart your apache2 service

      sudo service apache2 start
      
    5. check php version

      php -v
      
Share:
5,791

Related videos on Youtube

Run
Author by

Run

A cross-disciplinary full-stack web developer/designer.

Updated on September 18, 2022

Comments

  • Run
    Run almost 2 years

    I am on php7 now but I have a legacy program relies on php5 as it is using mysql instead of mysqli.

    Can I have php5 installed alongside with php7 and switch them around when either of them is needed?

    • Steve R.
      Steve R. about 7 years
      What about updating your program? Obviously that depends on the complexity of your program. I was able to update mine in a relatively short period of time, but then my program is very simple.
    • Run
      Run about 7 years
      @SteveR. im trying to now. It is modx - can't believe this program is worse than wordpress!
    • Steve R.
      Steve R. about 7 years
      You may want to look here: "PHP 7.0 (and 5.6) on Ubuntu" lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu Since I do not have this dual configuration, I have no knowledge of how good the advice is.