Upgrading PHP on Windows

In my case the development environment where I wanted to upgrade PHP was an XAMPP install but there is only one step in the process that I used that is dependent on XAMPP. Most of the same steps should also work for other operating systems but I haven't tested this other than on Windows 10.

Upgrading PHP should be a lot simpler than upgrading a database as there is no actual data that needs to be upgraded for the new version of PHP to work with it. Of course you may have PHP code that was deprecated in prior versions that now no longer works but checking for that is why you upgrade PHP on your development server first before allowing it to be upgraded on your live site.

The first thing you need to do is to download a copy of the PHP version that you want and install it in a folder alongside your current PHP install (using a slightly different name of course. In my case I wanted to upgrade from PHP 5.3 to PHP 7 and so initially downloaded PHP 7. As I had some unexpected difficulties with this I then downloaded a copy of PHP 5.6 to upgrade to first only to run into the same difficulties with that version. I'll get to the difficulties I had later.

The main change that you need to make with the new download before being able to substitute it for your current version is to update the php.ini settings in the new version to copy across anything from the prior version that needs to be in the new version (such as file locations). I use a program called Meld to do file compares as this makes it really easy to copy code that is different between two files from one to the other. When copying file references across you need to remember that you will be renaming the folders so that the new version will be using the folder name the old version was using once you are finished.

When updating the new php.ini you need to make sure that any extensions your sites use have the ; removed from the front of those references in the new php.ini so that they can run there. The difficulty that I had which I mentioned earlier is that the mysqli extension refused to load (in both 5.6 and 7) even though I had uncommented the line - I eventually got it working by renaming the extension file and then renaming it back (not sure why this fixed it but it did).

Of course when upgrading to PHP 7 there is no mysql extension at all so you can't uncomment it. Of course advanced notice of the removal of this extension was given back in July 2013 so you have had plenty of time to upgrade all your database calls to use either mysqli or PDO (both of which have been around since 2004).

With the php.ini file updated, the next step is to rename the old php folder out of the way and rename the new one in its place.

If upgrading PHP on XAMPP from 5 to 7 there is one further change you need to make in the http-xampp.conf file. You need to replace the following lines:

LoadFile "C:/xampp/php/php5ts.dll"
LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"


LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php//libpq.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"

and also update

<IfModule php5_module>


<IfModule php7_module>

Note that I recommend commenting out the original loadFile and LoadModule lines and adding the new lines rather than just updating the existing ones as it makes it easier to revert back if needed. You can also have IfModule sections for both php5 and php7 in the file at the same time without it hurting anything.

The final step in upgrading is to simply stop and restart the Apache service. That will swap the version of PHP that is running. Assuming that all the extensions started correctly you should have all your PHP applications running correctly with just a few warning messages relating to things where your code does not reflect the best current practice. Once I resolved the mysqli extension loading the main warnings I got were regarding setting the timezone before trying to use date functions. You simply need to make sure that you have fixed the cause of all of these warnings before you upgrade your live site to the new PHP version. Of course if you get actual errors rather than just warnings then your code may be too far out of date and need a more significant rewrite before you can upgrade your live PHP version.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow