CodeBriefly
Tech Magazine

How to Handle Multiple PHP Versions with Apache Server on Windows

4 23,064

Get real time updates directly on you device, subscribe now.

In this article, we will discuss “How to Handle Multiple PHP Versions with Apache Server on Windows”. As previous, I’m sharing an article where you learn how to set up Apache, PHP, and MySql on windows. So I recommend you to start with our previous article for a better understanding. Because in this article, I’m not adding the basic setup steps which are already discussed in the previous article.

Multiple PHP Versions

We need different PHP versions which we want to set up on our system. You can download it from the official PHP site and choose the Non Thread Safe releases.

Multiple PHP Version

I recommend you to create a new directory with “PHP” name and extract all the downloaded PHP versions in this directory. It’s really simple and easy to maintain for example “F:\localserver\php, and PHP versions such as 7.2.11, 7.3.0”.

After extracting the PHP versions, you need to add the PHP path into the windows environment variable. And inside each PHP version’s directory, you found php.ini-development. Create a copy of this file and saved on the same location with the name of php.ini.

There is one important update which is mandatory as given below:

; extension_dir = "ext"

// Uncomment the above mention statement and change it to

extension_dir = "F:\localserver\php\7.3.0\ext"

You need to update the extension_dir path as per the PHP version.

Update Apache

We already discussed, how to setup apache server in our previous article. So we are not adding here again. To setup of multiple version, we need a “mod_fcgid (FastCGI ASF module)”, you can download it from the Apache Lounge.

Extract the downloaded modules ZIP package. Go into the mod_fcgid-*** (*** is a version and other details) folder. Open the mod_fcgid folder, copy the file mod_fcgid.so into the Apache module directory such as F:\localserver\Apache24\modules.

Update httpd.conf

Open the httpd.conf, located at F:\localserver\Apache24\conf. Search the following modules in this file, if available then uncomment (remove the # symbol from the starting) it otherwise add those modules.

# LoadModule include_module modules/mod_include.so
# LoadModule vhost_alias_module modules/mod_vhost_alias.so
# LoadModule fcgid_module modules/mod_fcgid.so

Before adding those modules, it’s necessary to all those modules available in the module directory.

Update httpd-default.conf

Open the httpd-default.conf, located at F:\localserver\Apache24\conf\extra. Add the following code snippet at the bottom of the file.

FcgidInitialEnv PATH "F:\localserver\php\7.3.0;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 1000
FcgidMaxProcesses 50
FcgidMaxRequestLen 8131072
# Location of php.ini
FcgidInitialEnv PHPRC "F:\localserver\php\7.3.0"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
<Files ~ "\.php$">
  AddHandler fcgid-script .php
  FcgidWrapper "F:/localserver/php/7.3.0/php-cgi.exe" .php
  Options +ExecCGI
</Files>

In the above code snippet, we are just creating a default configuration of our apache server. Currently, we are setting up the PHP version 7.3 as our default PHP version.

You may change the PHP path as per your requirement such as “F:\localserver\php\7.3.0” or “F:\localserver\php\7.2.13”.

Add httpd-default.conf in the httpd.conf. Open httpd.conf and apply the changes as given below.

# Include conf/extra/httpd-default.conf

to 

Include conf/extra/httpd-default.conf

Test PHP in Browser

Create a new file phpinfo.php at F:\localserver\Apache24\htdocs with the following content.

<?php
    echo phpinfo();
?>

Open the browser and visit “http://localhost/phpinfo.php”.sho

phpMyAdmin Issue

I’m facing one strange issue in the phpMyAdmin as per the below mention screenshot.

Multiple PHP Version with Windows

It’s because phpMyAdmin still not support PHP 7.3 completely. You can read more at PHP Bug.

Setup Virtual Host for PHP Version

We already discussed Virtual Host in our previous article. Today, we create the virtual host for our different PHP versions on different Port. You need to change your host file located at C:\Windows\System32\drivers\etc to have Windows map these fake domains to your local server.

127.0.0.1 localhost:90

Update the httpd.conf

Open the file and uncomment (remove the leading hash sign) as given below.

# Include conf/extra/httpd-vhosts.conf

to

Include conf/extra/httpd-vhosts.conf

Also, add port no to start listening.

Listen 90

Now edit the F:\localserver\Apache24\conf\extra\httpd-vhosts.conf file and add the following content.

<VirtualHost *:90>
    ServerAdmin webmaster@local.web
    DocumentRoot "F:/localserver/Apache24/htdocs"
    ServerName localhost:90
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common 
    
    # Use below statement to load the specific version of php configuration
    FcgidInitialEnv PHPRC "F:/localserver/php/7.2.13/php.ini"

    <Directory "F:/localserver/Apache24/htdocs"> 
        <Files ~ "\.php$"> 
            AddHandler fcgid-script .php 
            FcgidWrapper "F:/localserver/php/7.2.13/php-cgi.exe" .php 
            Options +ExecCGI 
        </Files> 
    </Directory> 
</VirtualHost>

In the above code snippet, We are using “FcgidInitialEnv PHPRC” statement to load the specific PHP config (php.ini) file.

Everything is ready now. We can access both PHP versions with the same apache server, http://localhost for PHP version 7.3.0 and http://localhost:90 for PHP version 7.2.13.

Conclusion

In this article, we are discussing “How to Handle Multiple PHP Versions with Apache Server on Windows”. I’m trying to explain you step by step process to make setup easy. I recommend you to read our previous article for a better understanding. We will discuss more on the Virtual Host, Apache, phpMyAdmin, PHP in our future post.  Please feel free to add the comment if any query or you can submit your feedback 😉

If you like our content, please consider buying us a coffee.
Thank you for your support!
Buy Me a Coffee

Get real time updates directly on you device, subscribe now.

4 Comments
  1. Kelly B. says

    Thanks
    It’s really time saver,
    buddy 😉

  2. Rodrigo says

    Very good. It worked.
    I used PHP 5.6 as standard and I would like to put 7.3 to use via htaccess.
    I have only HTTP configured on port 80.
    I would not like to change the port when I wanted to use 7.3, I wanted to do it via htaccess.
    How could I proceed? Thanks

  3. Chris says

    Hi Pankaj, When using PHP versions, do you also change the PATH in windows pointing to a specific PHP folder, or just leave it to one setting?
    I’m not even sure which applications would be using that PATH.

    1. Pankaj Sood says

      Hi Chris, I’m using Virtual Host to differentiate the PHP versions. So you can use the different URLs for different versions.

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More