Note: If you want to install and use PHP 7 and Composer within the Windows Subsystem for Linux (WSL) using Ubuntu, I wrote a guide for that, too!
I am working a lot on Composer-based Drupal projects lately (especially gearing up for DrupalCon Nashville and my joint workshop on Drupal and Composer with Matthew Grasmick), and have been trying to come up with the simplest solutions that work across macOS, Linux, and Windows. For macOS and Linux, getting PHP and Composer installed is fairly quick and easy. However, on Windows there seem to crop up little issues here and there.
Since I finally spent a little time getting the official version of PHP for native Windows installed, I figured I'd document the process here. Note that many parts of this process were learned from the concise article Install PHP7 and Composer on Windows 10 from the website KIZU 514.
Install PHP 7 on Windows 10
- Install the Visual C++ Redistributable for Visual Studio 2015—this is linked in the sidebar of the PHP for Windows Download page, but it's kind of hidden. If you don't do this, you'll run into a rather cryptic error message,
VCRUNTIME140.DLL was not found
, andphp
commands won't work. - Download PHP for Windows. I prefer to use 7.1.x (current release - 1), so I downloaded the latest Non-thread-safe 64-bit version of 7.1.x. I downloaded the .zip file version of the
VC14 x64 Non Thread Safe
edition, under the PHP 7.1 heading. - Expand the zip file into the path
C:\PHP7
. - Configure PHP to run correctly on your system:
- In the
C:\PHP7
folder, rename the filephp.ini-development
tophp.ini
. - Edit the
php.ini
file in a text editor (e.g. Notepad++, Atom, or Sublime Text). - Change the following settings in the file and save the file:
- Change
memory_limit
from128M
to1G
(because Composer can use lots of memory!) - Uncomment the line that reads
; extension_dir = "ext"
(remove the;
so the line is justextension_dir = "ext"
). - In the section where there are a bunch of
extension=
lines, uncomment the following lines:extension=php_gd2.dll
extension=php_curl.dll
extension=php_mbstring.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_sockets.dll
- Change
- In the
- Add
C:\PHP7
to your Windows system path:- Open the System Control Panel.
- Click 'Advanced System Settings'.
- Click the 'Environment Variables...' button.
- Click on the
Path
row under 'System variables', and click 'Edit...' - Click 'New' and add the row
C:\PHP7
. - Click OK, then OK, then OK, and close out of the System Control Panel.
- Open PowerShell or another terminal emulator (I generally prefer cmder), and type in
php -v
to verify PHP is working.
At this point, you should see output like:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\jgeerling> php -v
PHP 7.0.29 (cli) (built: Mar 27 2018 15:23:04) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
This means PHP is working, yay!
Install Composer on Windows 10
Next, we're going to install Composer by downloading it and moving it into place so we can run it with just the composer
command:
- Download the Windows Installer for Composer and run it.
- Note that the Windows Installer for Composer might ask to make changes to your
php.ini
file. That's okay; allow it and continue through the setup wizard. - Close out of any open PowerShell or other terminal windows, and then open a new one.
- Run the
composer
command, and verify you get a listing of the Composer help and available commands.
That's it! Now you have PHP 7 and Composer running natively on your Windows 10 PC. Next up, dominate the world with some new PHP projects!
Comments
Nice post, Thank you very much :)
Still very useful :-) The extensions in step 4.3 have changed names a bit, but it's not hard to find the ones to enable.
Thank you so much
For those complaining about windows permissions... why not just build everything in a Docker container?
I develop locally and put everything in a folder that has a docker build process. That way when you have all your tests satisfied locally, the docker build handles creating the correct permissions and installing whatever app
I used https://chocolatey.org/ to install php
choco install php
done
This was spot on the right way to install php and composer, worked for me just fine..(-/-)
Many thanks for this. I'm an extreme novice.
I've just installed PHP8
the php.ini mods are different, but I hope they work.
Composer installed OK.
wooooow..it worked excellently
thanks brother
Thanks you