HOW TO INSTALL PHP ON WINDOWS COVER

HOW TO: install PHP 7.2 on Windows

You can install PHP on a Windows machine in multiple ways. It all depends on your needs/requirements.

XAMPP and WampServer are great for beginners or people that want to build something really quick and have less experience with PHP and Apache environments. By installing them you get a ‘ready to go’ development environment that includes: PHP, Apache, MySQL and more…

In most cases though, you might just be interested to install just PHP, to use it in different development environments. Below I will show you step by step what you have to do to install PHP 7.2 on a Windows machine.

  1. How to install PHP on Windows?
  2. Test PHP is installed
  3. What extensions do I need?
  4. How to enable extensions?
  5. Check what PHP extensions you have installed
  6. How to start a localhost on Windows
  7. Conclusion



How to install PHP on Windows?

First, go and download PHP 7.2 .zip file from here. Choose the version you need for your machine, x64 or x86. I usually install the Non Thread Safe version.

Read this for more info about What is thread safe or non-thread safe in PHP?

Download PHP
Download PHP

Choose where you want to install PHP and make a new folder called PHP. I usually install it in /C.

Create PHP Folder
Create PHP Folder

Export the php zip contents into the /PHP folder you have just made.

Export zip file to PHP folder
Export zip file to PHP folder

Go into the /PHP folder, make a copy of the php.ini-development file (literally, copy and past that file again into the folder). Rename the file you just copied to php.ini.

Create php.ini file
Create php.ini file

Open php.ini file in any code editor and search (ctrl + f) for extension_dir = “ext”. Uncomment that line by removing the semicolon, as below:

Set extension directory
Set extension directory

HOW TO: use Git to start a project and commit files

Open Environment Variables (Windows Search for ‘env’)  and open Edit the system environment variables. Click Environment Variables.

Edit environment variables
Edit environment variables

Under System Variables, select PATH and click Edit.

Edit PATH
Edit PATH

Add two new entries in that variables list. Click New and add the location of your /PHP folder (C:\PHP) in my case. Next, add the location of your extension folder (C:\PHP\ext) in my case. Click OK.

Add env variable
Add env variable

Under System Variables click New and add PHPRC for the name and C:\PHP for the value of this new system variable. Click OK and then OK again.

Add new system variable
Add new system variable

The next thing you want to do is to reboot/restart your computer.

Test PHP is installed

Once your machine restarted, the simplest way to check if PHP was installed correctly is to:

Open cmd by windows searching for cmd. This will open your terminal.

Open cmd
Open cmd

Run php -v and you should see a similar output, depending on the version of PHP you have installed.

Check php -v
Check php -v

You can also run php -i for a lot more information about the PHP you have installed or create a index.php file on your localhost containing the following code:

<?php 

echo phpinfo();

 ?>
PHP info file on localhost
PHP info file on localhost

How to install PHP, Apache and MySQL on Ubuntu

What extensions do I need?

You don’t need all the extensions to be enabled. Every developer will use different extensions, based on what they develop. Here is a good resource when it comes PHP extensions.

There are a few basic extensions that you will need to enable though:

  1. Depending on what database service you want to use, enable pdo_sqlite; pdo_mysql or pdo_pgsql.
  2. Enabling curl and mbstring is also something I usually do.

How to enable extensions?

Open php.ini in any code editor and search (ctrl + f) for ‘;extension=curl’. Or just scroll down until you see the list below:

PHP extensions
PHP extensions

NOTE**: Make sure you enable openssl as well.

Uncomment the extensions you wish to enable and save the file.

Check what PHP extensions you have installed

In your terminal (cmd) run the following command. That will show you what modules/extensions you have enabled and loaded.

php -m

or

php -r "print_r(get_loaded_extensions());"
Check php modules
Check php modules

Top 3 free coding editors

How to start a localhost on Windows

Open terminal (cmd) and cd (go to) the folder where you want to start the localhost. This is usually project folder or where your index.php file is located.

Once you’re there, run the following command in the terminal:

php -S localhost:8000

More info from the documentation here.

PHP run localhost
PHP run localhost

Check if your localhost works by opening this link into the browser:

http://localhost:8000/

Conclusion

As you have probably figured out, installing PHP on Windows is not as hard as it may seem. Just make sure you don’t miss a step along the way and everything should work perfectly fine by the end of this tutorial. If you face any problems or errors, just comment below your error code and I’ll help you through this process.

Support this blog by subscribing to the newsletter. There will be no spam, just a few emails from time to time.

Yes, I want to support this blog for more awesome content. 

4 thoughts on “HOW TO: install PHP 7.2 on Windows

  1. You have missed a step after clicking “edit” on “path” in environmental settings. Clicking edit prompts the user to edit the path. Creating a new path is not possible at that point. Whatever you are trying to advise, it falls apart at that error.

    1. Thanks for pointing that out mate, but I just checked everything again on my machine and it works fine. As shown in the tutorial. Under ‘System variables’ you select ‘Path’ and then click the ‘Edit’ button. Prompts you with another dialogue box called ‘Edit environment variable’. There you add the new ones and so on…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.