I have searched hundreds of forum threads, blogs and info channels searching for the ultimate way to run PHP4 and 5 together on an Apache web-server, so I can test and play at the same time. I am on Windows at home. My web server is Linux, but what the hell, this could be close enough for me. This article was originally published on 227net.
After failed attempts at running PHP5 as a CGI with PHP4 running as a module, I followed the path of services, and saw some comments about being able to run multiple instances of Apache. Perhaps this was the way forward. With lots of snippets of information at hand, the PHP and Apache manuals open in tabs (Firefox), command prompt running, windows explorer open and point to C:\Program Files\Apache Group\Apache2 and a large cup of coffee I got started.
This article makes the assumption that you already have Apache and are running it as a service currently. I used 2.0.48 (win32) installer. If you haven't already installed it, please RTFM, don't blame me. Please make sure that you stop the service before proceeding - just to be on the safe side.
It also assumes that you have already downloaded PHP.
If you don't, then you can just follow the steps for PHP 5x and change names accordingly. the article doesn't go in depth into
PHP installation,
only a couple of suggestions - the rest is up to you!
The following steps work on Windows XP and 2000. You need admin rights for the PC, this is essential.
It does help if you can use ms-dos a little, can copy & paste and make back-ups first!
So we have made the basic installations, we have Apache running. PHP 4x and 5x have been downloaded, but ini files not changed yet.
The base installation directories are as follows:
If you have Apache2 running already, go to the next step!
Open Windows Explorer and go to your Apache directory and look for your httpd.default.conf file. It will be located somewhere like C:\Program Files\Apache Group\Apache2\conf. Highlight or select that file, then make a copy by using
Ctrl+C, then Ctrl+P to paste. Right-click on your copy of httpd.default.conf file and rename it to httpd.conf. Now we can open the file and make the relevant changes.
We need to ensure php module is running. To do this we need to locate the Dynamic Shared Object support section of file we have open. If you have the file open in notepad, you can use Ctrl+F and search LoadModule just at the end of section 1. Add the following 2 lines, changing the location to match your systems set-up.
Next we make sure that anything with a php extension .php runs as an application. After the AddCharset section there are some applications added, for example AddType application/x-gzip .gz .tgz. Below this, write the following:
You may want also to have index.php as a possible default directory index. If so, then Ctrl+F and search DirectoryIndex and it whatever filename(s) you want.
The previous steps were all PHP releted. We have two major Apache tasks still to complete. In this example for PHP4
we will just check, we will make the change in php5.httpd.conf. We need to check what port Apache is listening to. By default it is port 80. Ctrl+F and search for Listen and verify that it is 80. You can it if you want, it is not necessary though. The second task it to set a unique Pidfile for the server. From the httpd.conf file: "The file in which the server should record its process identification number when it starts."
That is essentially it. Now we will do the very same for php5.
OK, we haven't made this one yet, but follow the first few steps as we did with httpd.conf.
httpd.default.confcopy of httpd.default.conf to php5.httpd.confOK, hopefully that was pretty simple. You may want to change the extensions to .php5 to differentiate between you php code - that is up to you. Do not start Apache yet - it will fail as the php.ini files haven't been created yet. That is the next step.
Using windows explorer, navigate to PHP 4x installation directory. It should be simliar to the one listed above. In this folder, there should be 2 files with ini in the filename - php.ini-dist and php.ini-recommended. Make a copy of php.ini-recommended using Ctrl+C & Ctrl+P, then rename the file to php.ini.
Open the file using notepad or wordpad or your favorite text editor (NOT MS Office). We need to make a couple of minor changes so there are no conficts between the 2 versions of PHP we will have running. We are firstly looking for include_path. This is optional, but you want to have something like the following:
The main change is the extension_dir. Uncomment and add the following:
Then we do the same steps in the PHP5 folder.
Exactly the same process as with the PHP4, but the extension directory should be as follows in your newly-created
php.ini.
Please note that there are many configuration changes that you may want to make. These instructions only cover the extension_dir.
Almost there. The final steps are to create windows services for Apache.
If you have previously had Apache running as a service, you will know that the configuration file that Apache reads from is httpd.conf. What we now want is for Apache to look for different config files dependent on which service is running. We want each service to point to its respective config file.
A very quick way to bring up the DOS command window is to windows key+R -> Type command. Alternatively, Start -> Run -> Type command. Navigate to the bin directory in your Apache folder:
We now want to create a service for each version of PHP. Copy, Ctrl+P and paste the following at the command line in the directory as listed above. As you should have a service called Apache2 already available through the default installation, we can ignore the first code block below!
We then do the same for PHP5.
Now open your services monitor to see the status of the services you have created. Modify them as you wish.
If you have Apache Monitor running, you should now be able to see these 2 services by right clicking the icon in the task bar, and Open Monitor. You can then start your servers.
Create a php file, eg: info.php and insert the following:
Then type in the following urls directly into your address / location bar or follow the links below if your server is running both / either service:
That's it. You should now have 2 versions of PHP running concurrently on your Apache server. Have fun!!
As previously stated, please back up relevant files before following these instructions. The instructions do not cover any aspect of server security and PHP set-up and security. Make sure you follow this up.
Comments
But where is the Article itself ?
Hey, Its so depressing everywhere i go on the net they say your site has the best solution to running 2 Versions of PHP as Apache Modules BUT where is the article ? i mean the page for that on your site is this and it just gives a small preface but where to i see the method to do so ? very frustrating.
Maybe i am over looking, but can you help me please ?
Sorry
My server just got migrated recently and it appears that the article is no longer where it used to be.
I will check out my back-ups tonight and post as soon as possible.
Probably means that there is more articles missing, need to check that too.
Stay tuned and sorry again for the inconvenience.
Br
Jamie
Mobile Movie Database
Back
Found the file, and the page works again.
Sorry about that!!
Br
Jamie
Mobile Movie Database