How to run two versions of PHP on Windows 10

Ronaldo B.July 27, 20224 min read

In this article

When a new version of a technology is released, we tend to compare what has changed compared to the previous version. This has happened quite a bit with PHP, which had its version 8 launched at the end of last year.

To carry out the comparison of the changes in the new version, we can install two versions of the language. We have already shown how to do this with Ubuntu. You can access this content by clicking here.

In this article, we will talk again about how to install two versions of PHP, but now on Windows.

Downloading the two versions

We will first download PHP version 7.4. For this, we will use the following link: https://windows.php.net/downloads/releases/php-7.4.13-nts-Win32-vc15-x64.zip

The downloaded file will be zipped. We will extract it to the path C:/tools/php/php7.

Next, we will download PHP 8 via this other link: https://windows.php.net/downloads/releases/php-8.0.0-nts-Win32-vs16-x64.zip

We will extract this file to a similar path, changing only the final folder to php8.

We will now start the configuration of both versions, which will be the same for both. This procedure can be seen in more detail in the article PHP 8 on Windows 10 with Nginx server.

Configuring the php.ini file

We will rename the file php.ini-development to php.ini. We will make some changes to this file.

The first directive we will change is error_reporting:

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

error_reporting directive

The next directive is doc_root:

doc_root = "C:\www"

doc_root directive

Next, we will change the extension_dir and sys_temp_dir directives:

extension_dir = "ext"
sys_temp_dir = "C:\Windows\Temp"

extension_dir and sys_temp_dir directives

Finally, we will enable some PHP extensions:

extension=curl
extension=fileinfo
extension=mbstring
extension=exif
extension=mysqli
extension=openssl
extension=pdo_mysql

PHP extensions in php.ini file

Adding PHP to the system PATH

The next step involves adding the PHP executable to the system variables. This will make it possible for us to run PHP through its native command line and allow us to execute it in any folder on the computer.

We will access the folder where we extracted the PHP 7 files and rename the php.exe file to php7.exe:

Renaming PHP 7 executable file

We will repeat the same process for the PHP 8 folder:

Renaming PHP 8 executable file

We will now actually add these files to the system variables.

In Windows Explorer, find the item “This Computer” on the left panel, right-click on it and select the “Properties” option:

Accessing system properties

In the window that will open, we will select the “Advanced system settings” option:

Selecting advanced system settings

In the next window, we will click on “Environment Variables”:

Selecting environment variables

Next, we will see another window that will show the user variables and also the system variables. We will edit this second option. Select the “Path” variable, which will turn blue, and click on the “Edit” button:

Editing Path in environment variables

In the next window, click the “New” button located at the upper right corner. A new space in the Path variables will open. There, you can paste the path to the PHP 7 folder. In our case, this path is C:\tools\php\php7. Finally, just repeat this same process for the PHP 8 folder. The list of folders should look like this:

List of programs in system Path

We can close all the windows to perform our first test with these versions.

Testing the two versions of PHP

To carry out our first test, we will create a PHP file and insert the phpinfo() function into its structure.

We will open a Terminal in the folder where this file was created and execute the following command:

php7 -S localhost:80

Note that “php7” is the name of the executable file we renamed.

Now, when accessing localhost in our browser via port 80, which is the default, we see the following result:

PHP 7.4 result in the browser

Now, let's open another Terminal in the same folder and start a new PHP server, but now using another port, like 81. To do this, we will use the following command:

php8 -S localhost:81

Now, when we access the address localhost:81 in the browser, we see the following result:

PHP 8 result in the browser

Impressive! We were able to see the information of PHP 8. The most interesting thing is that localhost on port 80 continues to work normally. Are they running separately?

Conclusion

In this article, we learned how to configure two versions of PHP on Windows. We are now prepared to test the differences between the two versions of the language through the native PHP server, carrying out tests for versions 7 and 8 in the same file.

Remember that you can learn all the new features of PHP in version 8 in our course PHP 8 - The Language. ?

Until the next article :).

Keep learning with Hcode

Sign up for the course platform and follow the next blog guides.