w3resource

Install PHP on Windows

Obtaining PHP

  • Download latest version of PHP from http://www.php.net/downloads.php.
  • You can also download the .msi package i.e. windows installer of PHP from sourceforge.net

Prerequisite and running on your Windows system, else you will not be able to run PHP Scripts.

Alternatively, you can install WAMP server or AMPPS server to install PHP, MySQL, and Apache Web Server on your Windows machine.

Options for installing PHP on Windows

  • You can install php on windows manually.
  • You can run the .msi package, i.e. windows installer for php to install php.
  • Besides full installation, you can install php extensions on an existing installation of PHP.
  • You can upgrade to a higher version of PHP from an existing version.

Install PHP on Windows manually

You have to download zipped binary version of PHP from http://www.php.net/downloads.php.

Extract the downloaded file to php folder which must be created at the root of any of your windows drives (e.g. c:\php or d:\php).

Enter php folder and rename the file php.ini-recommonded to php.ini.

Open the file php.ini with any text editor and find extension_dir within the file.

Change the extension directory, i.e. if you have installed php in php folder of D drive, setting will be extension_dir=D:\php.

Now you open Environment Variables (MyComputer -> System Properties -> Environment Variables), under system variables, select Path and click Edit,
in the Variable value, go to the end of the list and put a semicolon, then  add  D:\php;D:\php\ext assuming D:\php is the location of your php installation.

Then Click on New under system variable and add PHPRC against Variable name and D:\php against Variable value.

Restart your system.

Install PHP on Windows using Windows installer 

Simply run the .msi Windows installer file and follow the installation wizard.

Testing if PHP is installed properly

Create a php file containing code <?php echo phpinfo(); ?> and save it as test.php.
Run this file on your web server and if you get an output like this:

install PHP on Windows
then you have installed PHP properly.

Install PHP extensions on Windows

What is a PHP extension?

A PHP extension is a piece of code which is not part of the core PHP and you need it to explore certain functionalities of PHP (e.g. for using mysql you need mysql extension of PHP).

Many extensions are available out of the box in the PHP installer downloaded from php.net or in the .msi package. But many need to be obtained separately from php.net.

In Windows, extensions come in the form of a  .dll file which you can download from php.net.

How do you configure an extension on Windows?

You need to change the setting of extension dir in php.ini file. For example, If you are using PHP 5.0.3, and you have installed php in c:\php, then you have to set extension_dir = C:\php\ext in your php.ini file.

After downloading the files needed, you have to open php.ini and enable a line pointing to an extension in question.

For enabling extensions, you have to uncomment a line in your php.ini file. For example, for enabling mysql extension, you have to change; extension = php_mysql.dll to extension = php_mysql.dll in your php.ini file.

You also need to restart your web server and php in order to complete the installation of a specific extension.

Sample php.ini

Previous: PHP Home
Next: Install php on Linux



Follow us on Facebook and Twitter for latest update.