- Published on
Windows PHP8 Development Setup With WSL2
- Authors
- Name
- Josh Pollock
- @josh412
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.
This post is about setup for PHP 8 web development for Windows. This Linux is mainly for Laravel development. I have a similar post about setting up the PHP 7 linux. 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 Debian. Open the Windows start menu and type "Debian". You should see an option to install through the Microsoft store.
Once Debian is installed, open it up and set a root username and password.
Debian does not include Git or curl, or wget. You will need those:
sudo apt update && sudo apt upgrade
sudo apt install curl
sudo apt install wget
sudo apt-get install git
Now that git is installed, you should setup SSH and git credential managment. I explained how to do that 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 the version 14 of Node. That includes npm. It also using npm, to install Yarn.
Test it with:
node -v
npm -v
yarn -v
Install PHP 8
As of when I wrote this, sudo apt install php-cli
installs PHP7, not PHP8. I used this article to figure out How to install PHP8 on Debian.
sudo apt update
sudo apt -y upgrade
sudo reboot
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo apt update
sudo apt install php8.0 -y
sudo apt install php8.0-{mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip}
php -v
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
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
wget -O composer-setup.php https://getcomposer.org/installer
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 →