Install PHP7 and Composer on Windows 10

PHP7 is a general purpose scripting language well suited for web development. Composer is the defacto package manager for PHP7. This tutorial will show you how to install PHP7 and Composer on Windows 10 for use in a command prompt.

A common misconception is that you need a web server like IIS, Apache, or Nginx to get started with PHP7 development. In fact, PHP7 has its own built in web server that you can invoke at the command prompt. Modern PHP frameworks such as Opulence, Symfony, Cake, Laravel, WordPress, and many more support this.

Installing PHP7

Download the latest PHP7 (non-thread safe version) zip file from http://windows.php.net/

Extract the contents of the zip file into C:\PHP7

Copy C:\PHP7\php.ini-development to C:\PHP7\php.ini

Open the newly copied C:\PHP7\php.ini in a text editor.

Scroll down to “Directory in which the loadable extensions (modules) reside.” and uncomment: extension_dir = “ext”

Notepad++ is great.

Scroll down to the DLL extensions section and uncomment the extensions you want to use.

My current setup.

Tweak other settings as needed.

Note: Don’t forget to keep your php.ini file in a safe place when you upgrade in the future!

Add C:\PHP7 to the Windows 10 system path environment variable.

Windows 10 has finally improved this interface, yay!

In a command prompt test that the installation is successful by typing php -v

ConEmu is great.

Installing Composer

On my computer I’ve created a C:\Users\dac514\bin directory where I keep miscellaneous executables. This directory is in my user path.

Use a search engine to find a tutorial and do something similar. Optionally install composer in the C:\PHP7 directory you just created as it’s already in your path.

To get composer.phar, drop to a command prompt, cd into your target directory, and run:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

(Important! Click here for a more secure and up-to-date install snippet.)

Next, create a new composer.bat file alongside the composer.phar file so that Windows 10 can execute it more easily. (Source)

echo @php "%~dp0composer.phar" %*>composer.bat

Test that it’s working by typing composer -V

ConEmu is still great.

10 thoughts on “Install PHP7 and Composer on Windows 10”

  1. This is extremely helpful! I’ve never used Composer and was confused about where to start and how to get set up. I was done in a few minutes with your tutorial. Thank you so much for taking the time to write it!

  2. Yeah thanks, the php worked greatly, but i need to connect it with apache and mysql database client. thanks

    1. “Connecting to MySQL:” Just set your configs to point to a MySQL server. It can be downloaded, a VM, a Docker image, there many options. I personally run Vagrant, but I still need PHP on my Windows machine to do stuff. MySQL doesn’t have to be on the same server as PHP.

      “Connecting to Apache:” I don’t understand this statement. PHP has it’s own built-in web server. Other options include IIS, Nginx, Caddy… Do you need .htaccess or something?

    2. Everyone has their own preferences, but I personally prefer XAMPP for an Apache/mySQL install of PHP on Windows. For development, not Production.

  3. almost smooth sailing for me, except I had to go back and enable the openssl extension in the php.ini and then after I created that composer.bat it was just echoing the line back to me until I closed and reopened that terminal. I’m using cmder which is a nice wrapper on top of conemu, dunno if thats why. It actually says restart your terminal in the “source” you noted for creating the .bat

  4. In cmd it still says php is version 5.6.25. Do I have to delete the previous version?

Leave a Reply

Your email address will not be published. Required fields are marked *