Install multiple versions of PHP on shared hosting
Background
I am wanting to become involved in PHP a bit more, and in doing so will require me to run multiple versions of PHP. The first idea that came to mind is setting up multiple installations on one of my home machines. Since I don’t want to have a full development setup on my laptop (poor little guy isn’t powerful enough), I decided to install multiple installations on my shared hosting at dreamhost.com. There are several reasons that you would want to run multiple versions, such as:
- Want to try out the latest from CVS
- Your host doesn’t support the version you want to use
- Want to test something in a newer version
- Want to configure an installation with different packages/extensions
I’m fairly certain that somebody may be able to stumble upon this and get some helpful tips out of it. In writing this, I assume that the reader has some UNIX knowledge, and is fairly comfortable with the command line.
The Setup
First, you need to download whichever version you want. Make sure you get the source version.
Next, untar/unzip these into a directory. For myself, I chose ~/PHP/$VERSION for each version I am using.
Now, you will want to make a few directories. I myself am treating my home directory as though it is the root of a normal UNIX machine. So I have created the following directories:
~/usr/local/bin <--For all of your executables
~/usr/local/include <--For any include files that PHP needs to create
~/usr/local/man <--For PHP's man pages
~/usr/local/lib <--For PHP's libraries
After doing this, you will need to configure it. My configuration line was the following:
./configure --prefix=~/usr/local --enable-fastcgi --enable-debug --disable-short-tags --with-openssl --with-mysqli --with-xsl --enable-zip --without-pear
Your results may vary on what you need. I was able to compile and make everything without having to get more packages with my host.
Then you will have to run your make to make
make
And then install it
make install
Once that is done, you will need to copy over the PHP.ini file to ~/usr/local/etc
cp php.ini-dist ~/usr/local/etc/php.ini
Go to the web root, and create a directory called cgi-bin (if it doesn't already exist).
mkdir cgi-bin
chmod 755 cgi-bin
Link the executable to there
ln -s ~/usr/local/bin/php cgi-bin/php512.cgi
Go to the root of your web directory and create an htaccess file. In it, you will have to add the following (obviously I was installing PHP 5.1.2):
AddHandler php5_1_2 .php5_1_2
Action php5_1_2 /cgi-bin/php5_1_2.cgi
This should be good to go by then.
2 Responses to “Install multiple versions of PHP on shared hosting”
Have you tried using a vmware appliance or something along those lines? You could get some different images of different setups and swap them in and out using vmware-player for simulating multiple testing environments.
Correct me if I am wrong here, but you are suggesting I make multiple images with different PHP versions? Although I can set up full images with VMWare, it would need much more memory and processing power for me to do what I want. It is quite overkill for my needs. I am only wanting to change PHP versions at this time, not change much of anything else. A virtual machine, Eclipse, Firefox, IE, Outlook, and ITunes doesn’t go very fast on my current laptop albeit I have done this a few times.
This kind of testing may become much more important and valuable when my projects mature and I need to take into account different server environments, but for now, I was mostly needing this to test a documentation bug in PHP when it was referenced to an older PHP version.