Moving the location of PHP on your hard drive
In this article, we'll be moving our installation of PHP 4.4.2 from c:\php\ to c:\php4\. We'll be doing this primarily because we may like the ability to run multiple versions of PHP at one time, on our development server.
This will pave the way for our future installation of PHP 5.1.4 (or the current version of PHP 5.x). The added benefit is that we'll have an idea of just how many documents are involved in a relatively simple change.
Renaming the directory
The first thing we'll do is stop the Apache service. By doing this, anyone who attempts to visit our site, which is primarily us in this case, will see the same error message. On the other hand, if we were to move PHP without stopping Apache, it's possible that we could have a security hole – PHP code served as plaintext. While it's not too big of a concern for our development server, it could be a concern in a production environment, so we may as well just learn things right the first time.
Once Apache has stopped, we'll rename our directory from c:\php to c:\php4.
If you attempt to start Apache now, it won't work; Apache just won't want to start. We know why, but if you want the specifics, you can go to the Application errors under Event Viewer. If you followed the tutorial where we setup a Microsoft Management Console, then you can do this rather easily.
The next thing to change is the httpd.conf file(s). If you've got a number of these, then you'll probably want to change them all at the same time. However, you'll want to make a backup copy first.
Head over to C:\Program Files\Apache Group\Apache\conf\, or where ever your install directory is, backup each httpd.conf file that you need to (I had four to backup – one current, one backup, and two more for two versions of ColdFusion). Once you've backed these up, open them up.
If we look back at our PHP install tutorial, it looks like we have one thing to change in this document – we must find and correct the following line.
LoadModule php4_module "c:/php/php4apache.dll”
Make the change in each of the httpd.conf files that you backed up, at the same time. It makes more sense to do it this way, unless you'd like to test each of the httpd.conf files now. (Id est, in order to verify our correction, we'd technically have to test each configuration now, to verify that we made the correction correctly. However, if we just carefully make each change at the semi-same time, we'll cut a corner and not need to test each configuration now. Of course, we really should, and if we have the time, we should.)
If you'll recall, when we installed PHP we also copied some files into the c:\windows\ folder, and it looks like we do have one other modification to make with a file there.
There's one other change involving the c:\windows\php.ini file. Backing up this file is optional, depending upon how often you accidentally change more than you should ;) Open this file and correct the following line.
extension_dir = "C:\php\extensions\"
Save this file. If you've installed Zend Optimizer, you may also want to immediately make this change in the backup php.ini file(s) as well. We should now be ready to start Apache.
If you followed the above correctly, you should now be able to start Apache successfully. If you have any problems, make sure you check the Application errors in the Event Viewer.
Go to your phpinfo file and verify that the page comes up correctly. Go to any of your other PHP files to verify that they also come up (like phpMyAdmin, and the like).
And with that, you've setup PHP to use a different directory. As stated above, this will allow you to install PHP5 as well (in c:\php5, for example).
Support This Site
If my blog was helpful to you, then please consider visiting my Amazon Wishlist.