So You Want Multiple PHPs on Windows

or How to setup multiple PHPs on Windows 10/11

·

3 min read

Update December 2022: fixed the mklink command and added the /D option. Everything else works!

First of all, if you can afford it, don't develop PHP applications on Windows. Be sensible, use Ubuntu or something.

But if you:

  1. Want to have your games and PHP development career in the same place like me, and

  2. Are reading this in an era where WSL 2 is still a clunky mess.

Then maybe my struggle and final defeat will help you. This is a guide for running php on your Windows 11 system, no Docker, no WSL, just pure. f-ing. php.

You may not need to get rid of your WSL and Docker instances completely, but just to be safe and complete in this guide, I disabled Windows' WSL feature completely and uninstalled Docker Desktop before trying to run PHP on the bare Windows 10. The idea being to make it absolutely clear to VSCode and PHPStorm that I'm not trying to do anything on Docker or WSL. A bit nuclear but if you are reading this paragraph because copying everything the first time didn't work, try this.

"Installing" PHP on Windows

I believe in not breaking Windows's way where Windows's way is well known. So I manually created a PHP folder in my Program Files folder, then I took a page from Ubuntu's book and made a version folder inside of that folder. In the end, I had:

C:\Program Files\PHP\7.4

Then I went ahead to this website for the PHP Windows builds and downloaded the Zip file where it said "VS16 x64 Non Thread Safe". I'm not sure what the difference between thread safe and non thread safe is so let me know in the comments.

I extracted that zip file into the path I mentioned above. Now that PHP is installed, we can let the operating system know about it. but wait, what about switching versions I hear you ask? Well that's the magic of symbolic links.

Open the command line as administrator, then:

mklink /D "C:\php" "C:\Program Files\PHP\7.4"

You can simply follow the steps up to here to install another version of php and replace this symlink to use some other php version.

Once done, it's time to get composer up and running, see this page. I decided to install it system-wide but for more variability, try ignoring composer.phar in your repository and running it using phar files.

I then added the C:\php path to my user's PATH variable. (Google "How to add to Windows path")

if everything has gone right, you should be able to type php -v and composer --version into your terminal and they should both show the version you've chosen.

The Configuration

At this point, I was thinking "Did I do it?". No. The PHP that you just extracted comes with almost every common extension turned off. MySQL and SQLite, fileinfo and gd were a couple of commented out ones that I ran into. Since Open Notepad as administrator, File -> Open, then open the file at C:\php\php.ini path for modifications.

I modified the permissions for my php.ini file so that I as a user could edit it by double clicking it on it, however, since this is a security risk, it's best to stick with the "Run as Administrator" approach.