I'd like to run PHP7 and PHP8 on the same computer

I have a Windows 10 laptop with Apache, PHP8 and MariaDB, but I need to develop a site with PHP7. I’ve never run two different versions of PHP on the same machine before, so if anyone can help please chime in. :slight_smile:

There’s an article here about that, though it recommends Nginx instead of Apache:

Then I also found a newer post at SO:

1 Like

Thanks. I can’t seem to find anything Windows-specific. I’m better off simply downgrading to 7.4.x. Apparently Microsoft is pulling support for 8 anyway, so no point going there. Disappointing.

Some search results was about running multiple WAMP or XAMPP on the same box.

If that could solve anything? :slight_smile:

1 Like

You could look at Laragon, although at present swapping to v8 isn’t quite as easy as it should be. :frowning:

1 Like

For some reason I could never get WAMP or XAMPP running on any machine I ever owned. I build the server environment on my own from scratch, and it works. :man_shrugging:

1 Like

I’ve decided to roll back to PHP7, since 8 isn’t widely supported yet, and because of Microsoft’s odd decision.

Thanks for the input guys. :+1:

1 Like

Laragon would be the the easiest solution for installing multiple Php versions. While switching between Php 7 and 8 currently has a slight flaw, it is only a minor inconvenience to switch between the two.

For Php8 to work in Laragon edit C:\laragon\etc\apache2\mod_php.conf change php8_module to php_module

The file is auto-generated so you will have to edit it everytime you switch to another Php version and then back to version 8

Apache must be stopped and then started, not restarted

1 Like

I understood the php.ini file also needs editing.

When you you use the Laragon GUI to switch the version, it reads from the ini that is in the version xxx dir. Each version has it’s own .ini. The only edit needed to use version 8 is just what I posted.

If you want the same settings between versions, then you may need to edit each versions ini.

Actually depends on which operating system you’re using. I don’t use Windows anymore and rarely use Linux, but on macOs, you can theoretically change between different versions using Homebrew. I actually think it’s possible for all operating systems in simple terms.

I’ve created a topic thread a while back on how to manually install PHP using the method I use. Switching between PHP versions on Windows is pretty easy if you install it the way I did in the topic. All you really need to do is download the PHP binaries from the official PHP website. Then just rename the folder to PHP whenever you want to switch to a different version and restart Apache. Simply put, the folder for PHP in the demo videos on that topic points to C:\dev\progs\PHP.

So in theory, the only hard part about this is renaming the folders. :slight_smile: And I’m pretty sure you know how to do that. But if you’re talking about running both PHP 7 and PHP 8 on different instances and have them run at the same exact time, I don’t really know if that’s possible.

1 Like

From the OP…

1 Like

I use WAMP so I can easily switch between versions.

Possible by the use of virtual machines (different virtual machine for each HP version being used)

That still means they’re on different machines since each VM is instances of separate operating systems.

Now that I think about it, I think it is actually possible to run 2 PHP instances on the same computer. When you install Apache, you just need to rename the service. Then you’d need to download and install another Apache service under a different name and different port. The reason is because it all boils down to the DLL file you’re loading in for PHP. They have to be from different locations if you want to run 2 different PHP instances. Hence why it theoretically work with 2 different instances of Apache.

1 Like

If I could interject, yes, Microsoft is no longer going to support newer versions of PHP going forward, however, the PHP team still makes binaries for Windows:

https://windows.php.net/download/

3 Likes

After finally being available after a few days, I tested my theory and turns out it is possible to run 2 versions of PHP simultaneously. The first instance of Apache (has the php8apache2_4.dll file) runs on the default port 80 while the second instance of Apache (has the php7apache2_4.dll file) runs on port 8080.

4 Likes

Nice work! Thanks for making the video. Guess I can keep my 7 and add the 8 again. :+1:

If you have a spare 20Gb on your hard-drive then consider installing a dual Boot Linux Operating System. Most Linux operating systems can be first tried using a USB and then installed alongside Windows.

I use Ubuntu and swap PHP versions using the following batch files run from the command line::

file: php-7.sh

#!/bin/bash 

# Usage:  ~/./php-7.sh

sudo a2dismod php8.0
sudo a2enmod  php7.4

systemctl restart apache2

file: php-8.sh

#!/bin/bash 

# Usage:  ~/./php-8.sh

sudo a2dismod php7.4
sudo a2enmod  php8.0

systemctl restart apache2
1 Like

@spaceshiptrooper I’m having a hard time seeing what you’re doing in the video. It’s blurry.

Are you simply changing Apache’s port when you want to run a different version of PHP?

Kind of. So this setup doesn’t use XAMPP or WAMP. It’s a fully customized setup where you can simply change things out whenever you’d like.

To install this setup, it’s relatively easy to do. I should advise you that you should make a backup of your database and your PHP files first if you really want to try out this method. There’s more to it then just moving things around and typing in a few commands. You have to modify the .ini files in both Apache and PHP if you have specific use cases for those modifications.

In the video, I’ve basically downloaded 2 Apache folders that have the exact same configurations. The only difference is the port that 1 of the Apache listens to is port 8080. This was the PHP 7 setup. Also, the DLL file that’s required and needs to be different is php7apache2_4.dll. This file allows you to run PHP via Apache. For PHP 8, it’s called php8apache2_4.dll. So both versions have to run on different ports. That’s how you can run them simultaneously without having to change things back and forth if you wanted to switch from 1 version to another. With what majority of the guys/gals in this thread have proposed is running just 1 version of PHP, but just changing the configurations so you can swap them in and out whenever you’d like.

1 Like