Install and switch to PHP 8.3 in WSL 2
Martijn | Developer
Follow the steps below to install and switch to PHP 8.3 in WSL 2.
Step 1 - Update your package list
Run sudo apt update
.
Step 2 - Install PHP 8.3
Run sudo apt install php8.3
. This will install PHP 8.3 alongside PHP 8.2.
You can still use PHP 8.2 if you need it for certain projects.
Step 3 - Update your alternatives
Run the following commands to let WSL 2 use PHP 8.3 as default.
sudo update-alternatives --set php /usr/bin/php8.3
sudo update-alternatives --set phpize /usr/bin/phpize8.3
sudo update-alternatives --set php-config /usr/bin/php-config8.3
Step 4 - Verify the installation (PHP)
Run php -v
to verify that PHP 8.3 is now being used.
Step 5 - Install additional extensions (optional)
You need to manually install extensions that you use for the new version.
This can be done by running the following command.
sudo apt install php8.3-cli php8.3-bcmath php8.3-curl php8.3-mbstring php8.3-mysql php8.3-tokenizer php8.3-xml php8.3-zip php8.3-fpm php8.3-redis
Not all are required, please check and see which extensions you need.
Step 6 - Verify the installation of extensions (optional)
Run php -m
to get the list of all the compiled and loaded PHP modules/extensions.
Check if the extensions that you have installed during step 5 are shown in this list.
Fixing issues
After installing PHP 8.3, I noticed that there was a problem with port 80.
It turned out that Apache was assigned to it automatically (instead of nginx), causing issues for Laravel Valet.
Tip
Not using Laravel Valet in WSL 2 yet? Make sure to check out this article.
You might be interested in this article if you also encounter a port-related issue.