jinzo avatar

How to use multiple PHP versions with Apache on Windows

jinzo

Published: 31 Dec 2017 › Updated: 31 Dec 2017How to use multiple PHP versions with Apache on Windows

How to use multiple PHP versions with Apache on Windows

icon.php.png

In this tutorial where are going to explain how to use multiple php versions with our localhost in a pervious tutorial I've explained how to create your own localhost for windows

before starting make sure you've the following installed:

Apache Lounge

Must installed it and tested it is running correctly.

Download:
http://www.apachelounge.com/download/

I'm going to use v2.4.29 the lastest version for that tutorial date.

Any PHP version (Thread Safe)

Download:
http://windows.php.net/downloads

Create a directory such as C:php
Unzip a version of php (example php5.6 the zipped binary version, not the one with the installer), into a subdirectory of c:php)

Prepare any code editor

I'm going to use Notepad++ but you can use any other code editor. It should be fine.

Notepad++

Download:
https://notepad-plus-plus.org/

If the Apache service is running, stop it. In properties set it startup type to ‘Manual’.

First uninstall any pervious Apache service by using command prompt:

httpd.exe -k uninstall

Move any pervious version at C:\php to a sub folder for example if you've php7 version move it to C:\php\php7 after creating a new sub folder.

In this tutorial I'm going to use php7 as well as php5

So I've created 2 sub folders.

screenshot_sub_folders
Unzip the other version of php (eg. 5.6) into a subdirectory.

Install PHP 7

Go to php7 folder rename php.ini-development to php.ini

Go to C:\Apache24\conf Edit httpd.conf

httpd.conf

Add this for php after all modules:

and add the following at the end:

AddType application/x-httpd-php .php
# Choice between php versions

<ifdefine php7>
LoadModule php7_module C:/php/php7/php7/php7apache2_4.dll
    DirectoryIndex index.html index.php
    AddHandler application/x-httpd-php .php
# configure the path to php.ini
    PHPIniDir "C:/php/php7"
</ifdefine>

Then open command prompt install and install the service:

httpd.exe -k install -n Apache_php7 -D php7
Refresh the services list, then there will be one named ‘Apache_php7′.

Test it by using:
<?php phpinfo() ?> in info.php file.

Browse to your localhost url:
localhost/info.php

Install PHP 5

Go to php5 folder rename php.ini-development to php.ini

Add this for php5 after php7 module:

<ifdefine php5>
LoadModule php5_module "C:/php/php5/php5apache2_4.dll"
    DirectoryIndex index.html index.php
    # configure the path to php.ini
    PHPIniDir "C:/php/php5"
</ifdefine>

Then open command prompt install and install the service:
httpd.exe -k install -n Apache_php5 -D php5
Refresh the services list, then there will be one named ‘Apache_php5′.

Test it by using:
<?php phpinfo() ?> in info.php file.

Browse to your localhost url:
localhost/info.php

You can find the two services at C:\Apache24\bin Then open ApacheMonitor.exe.

That is it, you will have 2 versions of PHP installed that you can switch between. Just stop 1 service and start the other.

Pervious tutorials:

Setup your own Apache MariaDB PHP phpMyAdmin on Windows!



Posted on Utopian.io - Rewarding Open Source Contributors

Leave How to use multiple PHP versions with Apache on Windows to:

Written by

Read more #utopian-io posts


Best Posts From jinzo

We have not curated any of jinzo's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From jinzo