How to Change PHP Versions in XAMPP: A Step-by-Step Guide

Joseph LweyaJoseph Lweya
3 min read

If you've ever found yourself in a situation where you developed an application using a specific PHP version, only to realize that your local server environment doesn't match, fret not!

XAMPP, a popular development environment, allows you to switch between PHP versions seamlessly. Whether you're testing a legacy project or experimenting with the latest PHP features, here's a user-friendly guide on how to change PHP versions in XAMPP.

Step 1: Identify Your Current PHP Version

Before making any changes, it's crucial to know which PHP version your XAMPP environment is currently using. This information helps you ensure that you're switching to the desired version successfully.

  1. Launch XAMPP Control Panel.

  2. Click on the "Apache" module to configure it.

  3. Select the "Config" button next to Apache and choose "PHP (php.ini)".

  4. Look for the line that begins with LoadModule php followed by the version number. This line indicates the PHP module loaded by Apache.

Make a note of this version number as you'll need it for reference later.

Step 2: Download the Desired PHP Version

Now that you know your current PHP version, it's time to download the version you want to switch to.

  1. Visit the PHP official website at php.net/downloads.php.

  2. Choose the PHP version that matches your requirements. For example, if you need PHP 7.4, locate and download the PHP 7.4.x version.

  3. Ensure you're downloading the Thread Safe (TS) version compatible with your operating system (Windows, Linux, or macOS).

Once downloaded, extract the PHP folder to a convenient location on your computer.

Step 3: Configure XAMPP to Use the New PHP Version

With the PHP version downloaded, it's time to integrate it into your XAMPP environment.

  1. Navigate to your XAMPP installation directory (typically located in C:\xampp on Windows).

  2. Inside the XAMPP directory, locate the "php" folder. Rename the existing "php" folder to something like "php_old" to keep it as a backup.

  3. Copy the downloaded PHP folder (e.g., php-7.4.x) and paste it into the XAMPP directory.

  4. Now, rename the copied PHP folder to "php" to replace the old PHP version.

Step 4: Configure Apache to Use the New PHP Version

Once you've replaced the PHP version in XAMPP, you need to configure Apache to recognize and use it.

  1. Open XAMPP Control Panel.

  2. Click on the "Apache" module to configure it.

  3. Select the "Config" button next to Apache and choose "PHP (php.ini)".

  4. In the php.ini file, update the LoadModule php line to point to the new PHP version directory. For example:

     LoadModule php_module "C:/xampp/php/php7.4.x/php7apache2_4.dll"
    

    Ensure to replace "php7.4.x" with the version you've downloaded.

Step 5: Restart Apache Server

To apply the changes, you must restart the Apache server in XAMPP.

  1. In XAMPP Control Panel, stop Apache by clicking the "Stop" button.

  2. Once stopped, start Apache again by clicking the "Start" button.

Step 6: Verify PHP Version Switch

To confirm that you've successfully switched PHP versions in XAMPP, follow these steps:

  1. Launch your web browser.

  2. Enter "localhost" in the address bar to access the XAMPP dashboard.

  3. Click on the "phpinfo()" link in the navigation menu.

  4. The PHP info page will display. Check the PHP version mentioned at the top to ensure it matches the version you intended to switch to.

You've now changed PHP versions in XAMPP. Now you can test your applications with the desired PHP environment locally, making development and debugging a breeze.

Remember, always backup your files before making significant changes to your development environment. Happy coding!

0
Subscribe to my newsletter

Read articles from Joseph Lweya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Joseph Lweya
Joseph Lweya

I am a developer trained and mentored by ALX-Africa and building solutions at Datalytika. Always learning, always building.