It explains all the steps required to install PHP 7 on windows from the official site and get started with PHP development.

How To Install PHP 7 On Windows
How To Install PHP 7 On Windows
January 18, 2019

This post explains all the steps required to install PHP 7 from the official site on Windows 10. The steps should be similar on other versions of Windows.

In some cases, we need to develop or test our application against a specific version of PHP or to install it separately. In such cases, we can download it from the official site instead of using a bundled package in the form of XAMPP or WAMP. Once installed, we can configure the latest PHP to work with the web servers including Apache and NGINX.

Notes: You may also be interested in our debugging tutorials to debug PHP. These includes  How To Install NetBeans 11 for PHP on Windows, How To Debug PHP In NetBeans On Windows, How To Debug PHP Web Apps In NetBeans On Windows, How To Remote Debug PHP Web Apps In NetBeans On Windows, How To Install Eclipse for PHP on Windows, and How To Debug PHP In Eclipse On Windows.

Step 1 - Download PHP

Go to the official download link and download the required version. The distributions are provided as tar and windows binaries. While writing this tutorial, PHP 7.3.1 is the most recent one, hence we will discuss the installation steps specific to PHP 7.3.1. Click on Windows Download link and it will open the page having Binaries and Sources packaged for Windows.

PHP Download Site

Fig 1 - PHP Download Site

PHP Download Site for Windows

Fig 2 - PHP Download Site for Windows

We can see that PHP is available either as Thread Safe and Non Thread Safe. In simple terms, we can use Thread Safe PHP if we are using mod_php as worker MPM in Apache which spans multiple threads concurrently to process the requests and Non Thread Safe can be used for CGI. The Thread Safe version is required for web servers running in a multithreaded context.

The download page also provided binaries for both 32-bit and 64-bit Operating System. We will download the Zip Thread Safe version for 64-bit Operating System having the title as - VC15 x64 Thread Safe. As a regular user, we do not need the Debug Pack which is required for PHP developers.

Step 2 - Extract the Zip

Extract the downloaded zip at a specific location. It will look similar to the one having the PHP executable file as shown in Fig 3.

PHP Zip

Fig 3

Step 3 - Verify Installation

Open the command prompt and type php --version to check the available version. It will look similar to Fig 4 in case no other PHP versions are available.

Verify Installation

Fig 4

We need to configure the environment variable to access PHP from the command line. You can follow the below-mentioned steps to do so.

Right Click -> My Computer(This PC) -> Properties -> Advanced System Settings

The above steps will open the Windows settings panel as shown in Fig 5.

System Path

Fig 5

Now click on Environment Variables, select Path under System Variables section and click on Edit. We need to add a path of installed PHP to the system Path.

Click on New Button and add the path to the PHP bin which is E:\tools\php\php-7.3.1 in our case. Press OK Button 3 times to close all the windows. This sets the PHP 7 on system environment variables to access the same from the console.

Now again open the console and test the PHP version as shown in Fig 6.

Check Version

Fig 6

These are the basic steps required to install PHP 7 on Windows 10.

Step 4 - Getting Started With PHP Development

In this step, we will write a simple program and print Hello World on the console using the PHP executable configured by us in the previous step. Open your favorite editor and write the program as shown below.

<?php
// Print Hello World !!
echo "Hello World !!\n";

Now save the file as index.php and execute it using the command as shown below.

E:\tools\php\php-7.3.1>php index.php
Hello World !!

In this way, we can execute the PHP program on console. Though PHP is meant for web development, we can also use it for console based development. The latest PHP supports the modern programming concepts i.e. OOPS and it also supports strict typing.

Step 5 - Configure With Apache

You may have installed the Apache Web Server either independently or installed it as part of the bundled packages including WAMP, XAMPP, etc. In this step, we will simply configure the Apache Web Server to use the PHP installed by us in the previous steps.

Copy the file php.ini-development available at the path where we have extracted PHP and save it as php.ini at the same location.

Open the httpd.conf file of your Apache Web Server installation and search for the line having LoadModule php7_module. Now comment the line and add the path to your PHP as shown below.

#LoadModule php7_module "${INSTALL_DIR}/bin/php/php7.1.26/php7apache2_4.dll"
LoadModule php7_module "e:/tools/php/php-7.3.1/php7apache2_4.dll"
PHPIniDir "e:/tools/php/php-7.3.1"

Save the file and restart the webserver. Now create a file test.php at your webroot of the Apache server as shown below.

<?php
echo phpinfo();

Save the file, open your browser, and open the link - http://localhost/test.php. It should show the PHP settings as shown in Fig 7.

PHP Configure Apache

Fig 7

You can also enable the PHP extensions required for your project. The most important one is pdo_mysql. I have updated the php.ini file and enabled it as shown below.

....
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
....

Below mentioned is the output of phpinfo() before and after enabling the PDO extension.

PHP Windows COnfigure PDO

Fig 8

PHP Windows Configure PDO

Fig 9

We have successfully configured the latest PHP installed by us to work with the Apache Web Server.

Summary

In this tutorial, we have installed the latest PHP i.e. PHP 7.3 on Windows 10 and also configured the system path to use it from the console. We have also executed our first program in PHP to print Hello World on the console. In the last section, we have configured the PHP installation to work with the Apache Web Server and saw how to enable PHP extensions using the PDO extension example.

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS