Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Run Multiple PHP Versions in XAMPP

If you’re reading this it means you already know what XAMPP is and how to use it.

You also know that there isn’t an out-of-the-box feature in XAMPP that allows you to switch between Multiple Php Versions.

By the end of this post, you’re going to find out everything you need to know to install and run multiple Php Versions in a single XAMPP installation.

Let’s get started!

For this tutorial, I’m going to use XAMPP 3.2.4 which is an older version that comes with PHP 7.4.4.

Additionally, I would assume you already have a working version of PHP and some script files or a project you can use throughout the tutorial.

Download the PHP version

Let’s start by downloading a new PHP version.

Whenever I want to download a PHP version I choose windows.php.net.

Let’s download the latest version.

At the time of writing, the latest PHP version is 8.1.7.



There are a couple of things you have to be aware of here:

  1. The NTS and TS version which stands for Non-Thread Safe and Thread Safe
  2. x64 and x86 CPU architecture

Most computers nowadays have a 64-bit operating system and based processor.
But if you are unsure about it, you can check out the About your PC section in Windows.

Coming back to Non-Thread Safe and Thread Safe versions.

Before downloading any versions, I would advise you to check if you have Thread Safety enabled in your current PHP installation.

If you already have a working PHP file or a project, you can go to that script file or inside your public/index.php and use the phpinfo() function.

Now search for Thread Safety and notice if you have it enabled or not.

If you have Thread Safety enabled, then you should download the PHP version that does not contain NTS in its name.

And the opposite, if you have Non-Thread Safety enabled, you should download the version that contains NTS in its name.

If you download the wrong version, you may end up having problems with PHP and extensions.

Once the download finishes, go to XAMPP folder and create a new PHP folder.

I will name it php817 because it will contain PHP 8.1.7 version.

I strongly advise you also use the same folder naming approach to make it easier for you later.

Open the archive you’ve just downloaded and extract everything in this folder.



Configure php.ini

In the same folder, locate the php.ini-development file.

Copy and rename it to php.ini.

Open the php.ini file and remove the semicolon ; from the extension_dir = "ext" setting.

This is the directory in which the PHP extensions such as cURL, FTP, and MySQL are located.

Next up, search for extension_curland from here you can remove the semicolon ; for any extensions you’d like.

Usually, you would want to have cURL, FTP, fileinfo, MySQL, MySQLi, openssl, and pdo_sqlite enabled.

But of course, it depends very much on the project and yours may have different extension dependencies.

A quick note about these extensions is that if you’re trying to set up PHP  5.6 the name of the extensions would look like this extension=php_pdo_mysql.dll.

Set the Windows Environment variable for PHP

Skip this step if you have PHP Windows environment variable set up!

If you already have a working PHP version then most probably the Windows Environment Variable is already set up for PHP and you can skip this step.

To check the PHP version you have installed, open the command prompt and type in php -v.

Mine is 7.4.4 because this is the default version that comes out of the box with my installed version of XAMPP.

Additionally, to check where PHP is installed, you can use the where php command.

If you don’t have any PHP versions installed, but you do have a XAMPP installation, press the Windows button on your keyboard then go to Environment Variables.

Then under System variables, click the Path variable and then Edit.

Click New and add the path to your PHP folder.

Then click OK to save the changes.

To check if the environment variable is working, close all command prompts and open a new one and type in php -v and where php.

If everything looks good, it’s time to move on to the next section!

Apache configuration

Now we have to let Apache know that we have a new PHP version ready to be used.

Go to xampp > apache > conf > extra > httpd-xampp.conf file.

Preferably at the end of the file, add the following chunk of code:

This basically tells Apache where to find our specific new PHP version.

If you’ve been following the same naming convention as I recommended earlier, then replace php817with your folder’s name.

Configure your app to use a certain PHP version

Now we have to tell Apache that for a certain project we want to use a specific PHP version.

In the same file (httpd-xampp.conf) add the following piece of code:

Don’t forget to update the path and the PHP version to fit your needs.

Before we try out the new version, we have to restart Apache for the changes to take effect.

Now we can go back to the index.php file and use again phpinfo()to see what PHP version the project is using now.


That’s it!

If you want to install and configure any other PHP versions you can redo all the steps the same way.

Let me know what you think about this article through comments below, or on Twitter at @pelu_carol.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.



This post first appeared on Neutron Dev, please read the originial post: here

Share the post

Run Multiple PHP Versions in XAMPP

×

Subscribe to Neutron Dev

Get updates delivered right to your inbox!

Thank you for your subscription

×