It’s very easy to update / upgrade your version of PHP in XAMPP without needing to re-download XAMPP again or Apache. DO NOT listen to anyone who says you have to re-download xampp for it to work. If you know what you’re doing and feel that you must re-download XAMPP, then go ahead and do what you want, but you run a higher risk of breaking something if you re-download instead of just updating PHP.
Before I show you how to update PHP, let me show you what reinstalling xampp involves.
If you have to re-install xampp, it means you must take backups of the following:
- htdocs (files)
- phpmyadmin (databases)
- php.ini (this file might include new additions in the new PHP version so you might want to copy only your changes from the old one)
- Any additional drivers in php/ext
- Virtual host configurations
- In fact, it would make sense to backup the entire xampp folder first, as e.g xamppOLD-PHPx.x before installing the new one.
But you probably don’t want to do any of that. Now let me show you how to upgrade your version of PHP without reinstalling xampp.
How To Update PHP In XAMPP
In my case, I needed to install Laravel 5.6, I went over to the documentation and saw that it required at least PHP 7.1.3, I quickly checked the version of PHP on my PC by running php -v in the console and saw that I had version 7.1.2.
I downloaded the version of PHP that I wanted (7.1.17) and then I strategically replaced the one I had in XAMPP with it. Here are the steps I followed.
- Download your desired PHP binary from here. Make sure you download the same build type as your current version. If you don’t know what this is, go ahead and download an x86 Thread Safe version since most XAMPP installations have that build. In my case, I downloaded the7.1.17 VC14 x86 Thread Safe build.
- Extract the contents of the Zip file.
- Create a backup of your current xampp/php folder. I called mine php-backup7.1.2
- Still inside /xampp, create a new php folder, then copy the contents of the extracted zip file into it.
- If you have custom configurations in the php.ini file, copy and replace it from your old php folder to the new one. If you didn’t previoisly edit the your php.ini, then skip this step. In my case I had previously installed drivers for sql server and defined them in my php.ini, so I had to copy my old php.ini over to keep all my old configuration.
- Now, follow this step only if you’re upgrading to a major version (e.g from PHP 5 to 7. I didn’t need to follow this step because I upgraded from version 7 to 7 so the code below remained the same for me.
- Open this file in a text editor. C:\xampp\apache\conf\extra\http-xampp.conf
- Find the following lines:
LoadModule php5_module “C:/xampp/php/php5apache2_4.dll”
- Replace them with:
LoadModule php7_module “C:/xampp/php/php7apache2_4.dll”
- Find and replace php5_module to php7_module everywhere it appears in this file.
- Restart Apache