Installing and configuring PHP

If you’re a PHP developer and you’ve ever worked with Windows you probably know how much of a pain it can be to even install the language. In this article I will walk you through the installation process on a Windows 10 device.

Downloading PHP

Let’s go ahead and download PHP first. Head over to windows.php.net/download/ and select the version applicable for your system. Since I’m on a 64 bit machine with multithreading I’ll select “VC14 x64 Thread Safe” in the dropdown at the top of the page. Click “Zip” and choose a location for the .zip archive to download.

At the time of writing this article, this is the most recent release.

Installation

Installing PHP could not be simpler. Simply extract the .zip archive you just downloaded to the location where you want the language to live on your system. I chose to put mine in “C:/PHP7", but you can change this to whatever. If you navigate to the folder where you installed it you’ll see the following files except for the (highlighted) “php.ini”.

The contents of the folder where you unzipped the files.

Technically, PHP is now installed on your system. To see for yourself, go ahead and open up cmd (WIN+R → cmd) and run “C:/PHP7/php -v”. This should print the current version of PHP.

The PATH variable

PHP is now installed on your system. Yay! But why stop there? Wouldn’t it be lovely if you could run “php -v” instead of typing the entire path to the PHP executable? That’s what we’ll work on next.

First open up your control panel and click through to “System and Security”. Now go to “System” and click “Advanced system settings” in the left side of the screen. (You can also get to this screen by searching for “environment variables” in the start menu)

Next up, click “Environment Variables” near the bottom of the window and you’ll see this new window pop up:

The environment variables-management window.

We can edit the environment variables for the current user and for the entire system here. In this tutorial we’ll only be working with one of the the user variables, so you will only need the top half of the window.

Select “PATH” in the section under “User variables for <username>” and click “Edit…”. In the window that pops up, click “New” (top right) and insert the path to the folder where your PHP installation is (for me, that would be “C:/PHP7”).

Restart your command line and run “php -v”. This will print the same result as when you ran “C:/PHP7/php -v” previously.

Configuration

In the folder where you installed PHP (“C:/PHP7” for me) you should see the files “php.ini-development” and “php.ini-production”. Make a copy of the “php.ini-development”. And rename the copy to “php.ini”. Next, open it up with a text editor (Sublime Text, Notepad++, Atom…) and remove the semicolon (“;”) before the following lines (around line 870):

  • ;extension=php_curl.dll
  • ;extension=php_mbstring.dll
  • ;extension=php_mysqli.dll
  • ;extension=php_pdo_mysql.dll

You can also look around in this file for further configuration options, but once you save it you should be set to go for most frameworks and/or applications!


Closing

That was it! If you have any questions just hit me up on Twitter. I’ve copied over the contents of my php.ini file to a gist which can be found here if you can’t get yours to work. Thanks for reading!