PHP
PHP development environment with Laravel Herd, Docker (WSL 2) and takeout
.
INFO
This entry replaces a previous version of my Windows PHP setup: PHP (WSL 2)
Prerequisites
Install the following:
PHP
Install and launch Laravel Herd.
- Skip Herd Pro
- Enable "Automatically launch Herd on system startup"
Ubuntu
Setup Ubuntu 24:
ubuntu2404
exit
wsl --setdefault Ubuntu-24.04
wsl -t Ubuntu-24.04
ubuntu2404
Add user to Docker group:
sudo usermod -aG docker ${USER}
TIP
Make sure Docker is running if you get an error like usermod: group 'docker' does not exist
.
Takeout
Takeout is a CLI tool for spinning up docker containers for services like MySQL or Redis.
INFO
The following PHP installation is only used to set up takeout
, not for actual development.
This part can probably be replaced in the future by using the upcoming tighten/takeout docker image (waiting for tighten/takeout#326).
Setup:
sudo apt install -y php unzip
curl -sS https://getcomposer.org/installer | php \
&& sudo mv composer.phar /usr/local/bin/composer
echo 'export PATH=~/.config/composer/vendor/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
composer global require tightenco/takeout
exit
Add an alias to access takeout
from Windows:
Add-Content -Path $PROFILE.CurrentUserAllHosts -Value 'function takeout { wsl ~/.config/composer/vendor/bin/takeout @Args }'
Restart PowerShell.
takeout
VS Code
To access the Herd binaries in the integrated terminal of VS Code, add the following config:
"terminal.integrated.env.windows": {
"PATH": "${env:PATH};${env:USERPROFILE}\\.config\\herd\\bin"
},
PhpManager
Install PhpManager to install additional extensions:
Install-Module -Name PhpManager
Example usage with imagick
and PHP 8.3:
Install-PhpExtension imagick -Path $env:USERPROFILE\.config\herd\bin\php83
Enable-PhpExtension imagick -Path $env:USERPROFILE\.config\herd\bin\php83
Enable-PhpExtension
can also be used to enable default extensions such as xsl
which are disabled by default:
Enable-PhpExtension xsl -Path $env:USERPROFILE\.config\herd\bin\php83
Valet alias
Add a valet
alias for herd
in case muscle memory kicks in:
Add-Content -Path $PROFILE.CurrentUserAllHosts -Value 'function valet { herd @Args }'
Restart PowerShell.
Platform requirements
Ignore incompatible platform requirements such as ext-pcntl
, for example when installing Laravel Horizon in a cross-platform project:
Add-Content -Path $PROFILE.CurrentUserAllHosts -Value '$env:COMPOSER_IGNORE_PLATFORM_REQ = "ext-pcntl,ext-posix"'
Restart PowerShell.