How to install Composer and PHP on Windows

Composer is a package manager for PHP, probably the most important and well known. I prefer containerizing as much as possible in my projects, but for ease of use in local developments, sometimes it’s easier to have package managers available directly in your command line.

Yes, I still sometimes use PHP for small personal projects, as a low hanging fruit to solve basic problems. I rarely run it without docker locally, but I still want to use it’s package manager without having to execute a command inside Docker – my preferred solution for containerization.

The first thing you need is php. On Windows, we will just download php and put it in program files:

  1. Get a thread safe version from https://windows.php.net/download
  2. Unzip the contents in C:\Program Files\php, to which you can optionally add the version name;
  3. An optional step is to edit the php.ini config file and maybe enable some of the more useful extensions (e.g. the zip extension);
  4. Use the Windows start button, then type sysdm.cpl
  5. Go to Advanced and Environment Variables;
  6. Add the path to your folder in both User variables and System Variables;
  7. In the terminal, you should now be able to run php -v

For composer, you should go to the download page and just run the installer you download, by selecting the path to your freshly installed php:

It’s not always needed, but a system restart might be the solution if php and composer are not available to you in your terminal. Windows has gone a looong way since it’s first versions, but still it keeps some of it’s old habits 😈

Read more: