Published on

Windows PHP7 Development Setup With WSL2

Authors

I have been using Windows for PHP and JavaScript development for a few years now. I usually have two Linuxes on my computer. One with PHP 7 and PHP 8. I like that when I totally mess up a Linux, I can delete it and rebuild it. I also like

This post is about setup for PHP7 web development for Windows. This is Linux is mainly used for WordPress development. I have a similar post about setting up the PHP 8 linux. In this post I will show what I do after setting up WSL2 for PHP and JavaScript development. In this post I will show what I do after setting up WSL2 for PHP and JavaScript development.

If you do not have WSL2 installed, please checkout my post about installing Windows Linux Subsystem.

Install Ubuntu

First you will need a Ubuntu. Open the Windows start menu and type "Ubuntu 20.04 LTS". You should see an option to install through the Microsoft store.

Once Ubunutu is installed, open it up and set a root username and password. This is a good time to setup SSH and git credential managment, which I explained at the end of this post.

Install Node

I found that installing Node with NVM works the best. NVM allows switching node versions, which is cool. I had issues using Node, when isntalled with apt-get install node and never when doing it this way:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm install 14
npm install --global yarn

This installs Node 14. That includes npm. It also using npm, to install Yarn.

Test it with:

node -v
npm -v
yarn -v

Install PHP 7.4

As of when I wrote this, sudo apt install php-cli installs PHP7, not PHP8. That may change. For now, you can install PHP 7.4 with:

sudo apt install php-cli

Then you can install the PHP extensions with:

sudo apt install php7.4-{mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip}

You can add or remove extensions from that list, based on your needs.

Test it with:

php -v

Install composer

Don't forget the PHP package manager Composer

wget -O composer-setup.php https://getcomposer.org/installer
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Test it with:

composer -v

Now Code

That's all I do. From there, I can clone a project, switch to that directory, type code . and VSCode opens up. I get the same VSCode settings and keybindings as in Windows. The only difference is the terminal is bash and everything runs in Ubuntu.

Want to talk about this post? Discuss this on Twitter →

Found a typo or want to suggest an edit? Open a pull request →