How can I run multiple versions of PHP 5.x on a LAMP development server?

I need to test my PHP applications with several versions of PHP 5.x, such as PHP 5.0.0 and PHP 5.2.8.

Is there a way to set up a LAMP development server so that I can quickly test applications with multiple versions of PHP5?

+79
php lamp
Feb 07 '09 at 20:23
source share
10 answers

One way to do this is to configure your main version of php using mod_php and run all the rest using fast cgi on different ports (i.e. 81, 82, 83, etc.). This does not guarantee fully compatible behavior.

+17
Feb 07 '09 at 20:36
source share

With CentOS, you can do this using a combination of fastcgi for one version of PHP and php-fpm for another, as described here:

https://web.archive.org/web/20130707085630/http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server

Based on CentOS 5.6, Apache only

1. Enable the rpmforge and epel yum repository

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm sudo rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm sudo rpm -ivh epel-release-5-4.noarch.rpm 

2. Install php-5.1

CentOS / RHEL 5.x have php-5.1 in the field, just install it with yum, for example:

 sudo yum install php php-mysql php-mbstring php-mcrypt 

3. Compile and install php 5.2 and 5.3 from source

For php 5.2 and 5.3, we can find many rpm packages on the Internet. However, they all conflict with php, which comes with CentOS, so it’s better to build and install them from soure, it’s not difficult, you need to install php in another place.

However, when installing php as an apache module, we can use only one php version at a time. If we need to run another version of php on the same server, at the same time, for example, for another virtual host, a different version of php may be required. Fortunately, cool FastCGI and PHP-FPM can help.

Create and install php-5.2 with fastcgi enabled

1) Install the necessary developer packages

 yum install gcc libxml2-devel bzip2-devel zlib-devel \ curl-devel libmcrypt-devel libjpeg-devel \ libpng-devel gd-devel mysql-devel 

2) Compile and install

 wget http://cn.php.net/get/php-5.2.17.tar.bz2/from/this/mirror tar -xjf php-5.2.17.tar.bz2 cd php-5.2.17 ./configure --prefix=/usr/local/php52 \ --with-config-file-path=/etc/php52 \ --with-config-file-scan-dir=/etc/php52/php.d \ --with-libdir=lib64 \ --with-mysql \ --with-mysqli \ --enable-fastcgi \ --enable-force-cgi-redirect \ --enable-mbstring \ --disable-debug \ --disable-rpath \ --with-bz2 \ --with-curl \ --with-gettext \ --with-iconv \ --with-openssl \ --with-gd \ --with-mcrypt \ --with-pcre-regex \ --with-zlib make -j4 > /dev/null sudo make install sudo mkdir /etc/php52 sudo cp php.ini-recommended /etc/php52/php.ini 

3) create a wrapper fastcgi script

create file / usr / local / php 52 / bin / fcgiwrapper.sh

 #!/bin/bash PHP_FCGI_MAX_REQUESTS=10000 export PHP_FCGI_MAX_REQUESTS exec /usr/local/php52/bin/php-cgi chmod a+x /usr/local/php52/bin/fcgiwrapper.sh Build and install php-5.3 with fpm enabled wget http://cn.php.net/get/php-5.3.6.tar.bz2/from/this/mirror tar -xjf php-5.3.6.tar.bz2 cd php-5.3.6 ./configure --prefix=/usr/local/php53 \ --with-config-file-path=/etc/php53 \ --with-config-file-scan-dir=/etc/php53/php.d \ --enable-fpm \ --with-fpm-user=apache \ --with-fpm-group=apache \ --with-libdir=lib64 \ --with-mysql \ --with-mysqli \ --enable-mbstring \ --disable-debug \ --disable-rpath \ --with-bz2 \ --with-curl \ --with-gettext \ --with-iconv \ --with-openssl \ --with-gd \ --with-mcrypt \ --with-pcre-regex \ --with-zlib make -j4 && sudo make install sudo mkdir /etc/php53 sudo cp php.ini-production /etc/php53/php.ini sed -i -e 's#php_fpm_CONF=\${prefix}/etc/php-fpm.conf#php_fpm_CONF=/etc/php53/php-fpm.conf#' \ sapi/fpm/init.d.php-fpm sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm sudo chmod a+x /etc/init.d/php-fpm sudo /sbin/chkconfig --add php-fpm sudo /sbin/chkconfig php-fpm on sudo cp sapi/fpm/php-fpm.conf /etc/php53/ 

Configure php-fpm

Change / etc / php53 / php-fpm.conf, change some options. This step is mainly to uncomment some settings, you can adjust the value if you want.

 pid = run/php-fpm.pid listen = 127.0.0.1:9000 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 20 

Then run fpm

 sudo /etc/init.d/php-fpm start 

Install and configure mod_fastcgi, mod_fcgid

 sudo yum install libtool httpd-devel apr-devel wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz tar -xzf mod_fastcgi-current.tar.gz cd mod_fastcgi-2.4.6 cp Makefile.AP2 Makefile sudo make top_dir=/usr/lib64/httpd/ install sudo sh -c "echo 'LoadModule fastcgi_module modules/mod_fastcgi.so' > /etc/httpd/conf.d/mod_fastcgi.conf" yum install mod_fcgid 

Configuring and testing virtual hosts

1) Add the following line to / etc / hosts

 127.0.0.1 web1.example.com web2.example.com web3.example.com 

2) Create the root of the web document and remove the index.php under it, to show phpinfo switch to the root user, run

 mkdir /var/www/fcgi-bin for i in {1..3}; do web_root=/var/www/web$i mkdir $web_root echo "<?php phpinfo(); ?>" > $web_root/index.php done 

Note. An empty / var / www / fcgi -bin directory is required, DO NOT REMOVE IT LATER

3) Create an Apache configuration file (add to httpd.conf)

 NameVirtualHost *:80 # module settings # mod_fcgid <IfModule mod_fcgid.c> idletimeout 3600 processlifetime 7200 maxprocesscount 17 maxrequestsperprocess 16 ipcconnecttimeout 60 ipccommtimeout 90 </IfModule> # mod_fastcgi with php-fpm <IfModule mod_fastcgi.c> FastCgiExternalServer /var/www/fcgi-bin/php-fpm -host 127.0.0.1:9000 </IfModule> # virtual hosts... ################################################################# #1st virtual host, use mod_php, run php-5.1 ################################################################# <VirtualHost *:80> ServerName web1.example.com DocumentRoot "/var/www/web1" <ifmodule mod_php5.c> <FilesMatch \.php$> AddHandler php5-script .php </FilesMatch> </IfModule> <Directory "/var/www/web1"> DirectoryIndex index.php index.html index.htm Options -Indexes FollowSymLinks Order allow,deny Allow from all </Directory> </VirtualHost> ################################################################# #2nd virtual host, use mod_fcgid, run php-5.2 ################################################################# <VirtualHost *:80> ServerName web2.example.com DocumentRoot "/var/www/web2" <IfModule mod_fcgid.c> AddHandler fcgid-script .php FCGIWrapper /usr/local/php52/bin/fcgiwrapper.sh </IfModule> <Directory "/var/www/web2"> DirectoryIndex index.php index.html index.htm Options -Indexes FollowSymLinks +ExecCGI Order allow,deny Allow from all </Directory> </VirtualHost> ################################################################# #3rd virtual host, use mod_fastcgi + php-fpm, run php-5.3 ################################################################# <VirtualHost *:80> ServerName web3.example.com DocumentRoot "/var/www/web3" <IfModule mod_fastcgi.c> ScriptAlias /fcgi-bin/ /var/www/fcgi-bin/ AddHandler php5-fastcgi .php Action php5-fastcgi /fcgi-bin/php-fpm </IfModule> <Directory "/var/www/web3"> DirectoryIndex index.php index.html index.htm Options -Indexes FollowSymLinks +ExecCGI Order allow,deny Allow from all </Directory> </VirtualHost> 

4) restart apache. visit 3 sites respectfully to view phpinfo and confirm the result. i.e:

 http://web1.example.com http://web2.example.com http://web3.example.com 

If everything is OK, you can use one of 3 virtual hosts as a template to create a new virtual host with the required php version.

+22
May 25 '13 at 15:51
source share

Having multiple instances of apache + php never tickled my imagination, but this is probably the easiest way to do this. If you don't feel kiss ... here is an idea.

Get your apache and execute it, and try to configure it as debian and ubuntu, for example, to have directories for loaded modules. Your apache conf can use the following lines:

 Include /etc/apache2/mods-enabled/*.load Include /etc/apache2/mods-enabled/*.conf 

Then create your first php version and give it a prefix with an explicit version number, for example, / usr / local / php / 5.2.8, / usr / local / php / 5.2.6 ...

Conf / download will look something like this:

php5.2.6.load

 LoadModule php5_module /usr/local/php/5.2.6/libphp5.so 

php5.2.8.load

 LoadModule php5_module /usr/local/php/5.2.8/libphp5.so 

To switch versions, all you have to do is change the download and conf files from the directory in which apache includes inclusion for other versions. You can automate this with a simple bash script (delete the actual file, copy the alternative version file in place and restart apache.

One of the advantages of this setting is that everything is consistent, so you save php.ini the same way in terms of options and modules (which you still have to do with CGI). They all go through SAPI. Your applications will not need any changes and should not use relative URLs.

I think this should work, but again, I have not tried it, and I can’t do it, because I don’t have the same requirements as yours. Make a comment if you ever try.

+10
Feb 12 '09 at 7:00
source share

Note. The following method will work on Windows.

An alternative method (if you normally run one version of PHP at a time) is to define several Apache services, each of which will use a different version of PHP.

First of all, use the conditions in the Apache configuration file:

  <ifdefine php54> SetEnv PHPRC C:/apache/php54/ ScriptAlias /php/ "C:/apache/php54/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php-cgi.exe" </ifdefine> <ifdefine php55> SetEnv PHPRC C:/apache/php55/ ScriptAlias /php/ "C:/apache/php55/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php-cgi.exe" </ifdefine> 

Now, using httpd.exe, create two separate services from the command line (upgraded to administrator):

 httpd.exe -k install -n Apache224_php54 -D php54 httpd.exe -k install -n Apache224_php55 -D php55 

Now you can start one of the above services at a time (if you close one of them before starting the other).

If you previously installed Apache as a service, you can remove it using the following command (replace the service name with the one you used):

 apache -k uninstall -n Apache224 

Another observation is that I personally use the “notification area icon program” called “Seobiseu” to start and stop services as needed. I added two of the above services to it.

+8
Jul 20 '15 at 9:19
source share

Understanding that you are probably talking about a local / desktop computer and probably want to continue talking about a local / desktop machine, I will throw an alternative for you just in case it can help you or someone else

Set up multiple virtual server instances in the cloud and share your code between them as a git repository (or mercurial, I suppose, although I have no personal experience, all you really need is something decentralized). This gives you the opportunity to get as close as possible to production experience, and if you have experience configuring servers, then it is not so difficult (or expensive, if you just want to spin the server, do what you need to do, then deploy it again, then you talk about a few cents to say 50 cents, up to a few dollars if you just leave it operational).

Nowadays, I do all my project development in the cloud, and it was much easier for me to manage the infrastructure than ever when I use local / non-virtualized installations, and this makes this kind of side effect, the scenario is pretty straightforward. I just wanted to give up this idea if you weren't considering it.

+4
May 23 '13 at 12:39
source share

I just successfully abandoned PHP5.3 on Ubuntu 10.

For this, I used the following script:

 #! /bin/sh php_packages=`dpkg -l | grep php | awk '{print $2}'` sudo apt-get remove $php_packages sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list sudo mkdir -p /etc/apt/preferences.d/ for package in $php_packages; do echo "Package: $package Pin: release a=karmic Pin-Priority: 991 " | sudo tee -a /etc/apt/preferences.d/php done sudo apt-get update sudo apt-get install $php_packages 

For those who don’t know how to run scripts from the command line, here is a short tutorial:

 1. cd ~/ 2. mkdir bin 3. sudo nano ~/bin/myscriptname.sh 4. paste in the script code I have posted above this 5. ctrl+x (this exits and prompts for you to save) 6. chmod u+x myscriptname.sh 

These 6 steps create a script in a folder named "bin" in your home directory. Then you can run this script by calling the following command:

 ~/bin/myscriptname.sh 

Oulia

Hope this helps some of you!

For reference, this is where I got the script: PHP5.2.10 for Ubuntu 10

There are a few people who all confirm that this works, and it worked for me.

+3
Aug 10 '10 at
source share

Rasmus Lerdorf, who created PHP, supports an active roaming solution that seems to solve your needs. It allows you to quickly switch between versions of PHP, currently supports more than 20 different versions. It goes out of the box with the nginx server, but can be easily switched to apache2 with a pre-configured configuration. It also supports MySQL out of the box.

Thus, you will have access to all versions of PHP that can be deployed on two main web servers, in a good firewall, supported by a big man for PHP.

For more information, I would like to refer to the message given by Mr.. Lerdorf at https://youtu.be/6XnysJAyThs?t=2864

The github repository containing the Vagrant solution is at https://github.com/rlerdorf/php7dev

+2
Dec 06 '16 at 7:53 on
source share

Here is a link describing the procedure . This is the best I've met so far. Currently, I am successfully using PHP 5.4 for an old project, PHP 5.6 for new projects, Testing Wordpress on both HHVM and PHP 7. It took me a while to set up with many hits and trial versions, but now it works smoothly. My next approach is to learn how to move them to dockers.

0
Jun 03 '15 at 4:35
source share

For testing, I just run multiple instances of httpd on different IP addresses, so I have php7 working on 192.168.0.70 and php5.6 working on 192.168.0.56. In production, I have a site running the old oscommerce with php5.3, and I just have another conf file for the site

httpd -f / etc / apache2 / php70.conf httpd -f / etc / apache2 / php53.conf

It is also a clean way to have different php.ini files for different sites. If you just have several sites, if you have a good way to stay organized, and you don’t need to worry about more than one site at a time when you update something

0
Dec 31 '16 at 22:05
source share

I have several projects working on my mailbox. If you have already installed several versions, this bash script should help you switch easily. At the moment I have php5, php5.6 and php7.0, which I often swtich back and forth depending on the project I'm working on. Here is my code.

Feel free to copy. Make sure you understand how the code works. This is for webhostin. my local mailbox my mods are stored in / etc / apache 2 / mods-enabled /

  #!/bin/bash # This file is for switching php versions. # To run this file you must use bash, not sh # # OS: Ubuntu 14.04 but should work on any linux # Example: bash phpswitch.sh 7.0 # Written by Daniel Pflieger # growlingflea at g mail dot com NEWVERSION=$1 #this is the git directory target #get the active php enabled mod by getting the array of files and store #it to a variable VAR=$(ls /etc/apache2/mods-enabled/php*) #parse the returned variables and get the version of php that is active. IFS=' ' read -r -a array <<< "$VAR" array[0]=${array[0]#*php} array[0]=${array[0]%.conf} #confirm that the newversion veriable isn't empty.. if it is tell user #current version and exit if [ "$NEWVERSION" = "" ]; then echo current version is ${array[0]}. To change version please use argument exit 1 fi OLDVERSION=${array[0]} #confirm to the user this is what they want to do echo "Update php" ${OLDVERSION} to ${NEWVERSION} #give the user the opportunity to use CTRL-C to exit ot just hit return read x #call a2dismod function: this deactivate the current php version sudo a2dismod php${OLDVERSION} #call the a2enmod version. This enables the new mode sudo a2enmod php${NEWVERSION} echo "Restart service??" read x #restart apache sudo service apache2 restart 
0
Feb 14 '17 at 4:38 on
source share



All Articles