8

How can I setup PHP5 and PHP7 on one Fedora system?

As I see, PHP in fedora is not one directory, it's spread in OS.

On Windows systems, PHP is one folder, so I can just rename it when I need a specific version of PHP. What about Fedora?

Maybe there are some useful links but I haven't found them.

Also, it will be php5+apache(httpd) and php7+nginx, but I don't think it matters for now.

Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
Kirill Fimchenko
  • 157
  • 1
  • 2
  • 7
  • Typically when you want to maintain two separate php versions on a single system you do that in one of two ways: 1. you use one version as http server module, the other one as cgi or fastcgi application. That way you can use the standard paths. Or you pack each version in a separate folder, craft individual configuration files (adapting the paths) and switch between versions by simply specifying the configuration files location on CLI or inside the http server configuration. – arkascha Mar 06 '16 at 17:34
  • Possible duplicate of [How can one run multiple versions of PHP 5.x on a development LAMP server?](http://stackoverflow.com/questions/524508/how-can-one-run-multiple-versions-of-php-5-x-on-a-development-lamp-server) – castis Mar 06 '16 at 17:58

4 Answers4

7

I suggest you to install remi repository. I assume you use fedora 23.

sudo dnf install http://rpms.remirepo.net/fedora/remi-release-23.rpm

After installing remi repository, you have to edit /etc/yum.repos.d/remi.repo file and enable it. Finally you can install various versions of php. for example:

sudo dnf install php70-php php56-php

You can use them as php70 and php56 along with option or php file you want to run.

IAmAliYousefi
  • 1,132
  • 3
  • 21
  • 33
  • You can install both php70-php php56-php (which is mod_php) but only once, will work. Better to use php70-php-fpm and php56-php-fpm, as you can run 2 services, 1 per version. – Remi Collet Mar 07 '16 at 07:40
  • i installed mine without the version number, like `install php` and it was the version 7 that popped up –  Apr 30 '16 at 12:08
  • I have F29 and I installed the repo but it does not have the links for php56 only php73 – ateebahmed Nov 05 '18 at 20:13
  • @ateebahmed Did you see http://rpms.remirepo.net/wizard/ just like remi-collet mentioned? – IAmAliYousefi Nov 07 '18 at 17:09
  • yes, I followed till I install the repo after that since it does not have urls for 5 it gives 404, already checked elsewhere about this and it seems they don't support 5 now, thanks anyway I am using laravel right now, needed it for CI. Hope that doesn't break anywhere – ateebahmed Nov 07 '18 at 17:46
5

Following directions in Remi RPM repo blog worked for me. I can now run php55 or php70. https://blog.remirepo.net/post/2016/04/16/My-PHP-Workstation

Few things that it took to switch to php55:

 module unload php70
 module load php55

 yum install php55-php-fpm

 systemctl start php55-php-fpm
 systemctl enable php55-php-fpm

now both php --version in command line shows PHP 5.5 and also in your browser you will see that phpinfo() shows PHP 5.5.

Tim Hysniu
  • 1,446
  • 13
  • 24
  • This answer is very helpful in addition to the selected answer and I actually use the details in here as well, thanks! – BobChao87 Jan 10 '18 at 18:08
2

You can install as many versions as PHP as you want. Just download the source code and compile whichever version you want into separate directories.

./configure --prefix='/usr/local/php-7.0.4'
make
make install

Using fpm, you can set up different sockets or TCP ports for each version of PHP which can be used inside your web server config (nginx fastcgi or something like mod_fastcgi for apache)

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
1

Yes Software Collections is the current best solution for parallel installations of various PHP versions.

As SCL are not yet allowed in Fedora official repository, you have to use the "remi" repository.

See the Configuration Wizard on http://rpms.remirepo.net/wizard/

Also see

Remi Collet
  • 6,198
  • 1
  • 20
  • 25