Working with PHP on Windows has its challenges, especially when it comes to instant application testing and line-by-line debugging. In the past, setting up a PHP development environment on Windows involved complex configurations using tools like XAMPP and Eclipse. However, with the advent of Windows Subsystem for Linux (WSL) in Windows 10, it’s now possible to streamline the process and run Apache, PHP, and MySQL with greater ease. In this guide, we’ll explore how to set up a PHP development environment on WSL for efficient PHP scripting and debugging.
Before diving into PHP development on WSL, you need to install and configure WSL itself. Follow these steps:
Once you have Ubuntu up and running within WSL, proceed to set up the LAMP (Linux, Apache, MySQL, PHP) stack for PHP development:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install lamp-server^
(Note: The ^ symbol at the end is intentional.)
sudo echo "phpinfo(); " > /var/www/html/phpinfo.php
sudo /etc/init.d/apache2 restart
http://localhost/phpinfo.php
to confirm that Apache and PHP are operational.With your LAMP stack in place, it’s time to set up your PHP development environment for efficient scripting and debugging.
c:\websites\mysite
. Run the following command to create the link:
ln -s /mnt/c/websites/mysite /var/www/html/mysite
http://localhost/mysite/
, with PHP fully functional.sudo cp /usr/lib/php/7.0/php.ini-development /etc/php/7.0/apache2/php.ini
sudo /etc/init.d/apache2 restart
sudo apache2ctl start
For comprehensive debugging capabilities, you can utilize Visual Studio Code with the PHP Debug extension. Here’s how to set it up:
sudo apt-get install php-xdebug
sudo apache2ctl restart
In Visual Studio Code, install the PHP Debug extension. – Within Ubuntu, create a path mapping in your PHP project settings to bridge the gap between Linux and Windows file paths. Access the launch.json
file in your project and add a mapping like this: json "pathMappings": { "/mnt/c/websites/mysite": "${workspaceFolder}" }
– Set breakpoints in your PHP code within Visual Studio Code, start debugging, and open your PHP page in the browser.
Using Windows Subsystem for Linux (WSL) to set up your PHP development environment offers several advantages, including lightweight convenience. However, it’s important to note that WSL is not as isolated as a traditional virtual machine (VM). Therefore, you might encounter unique issues related to WSL. Additionally, some users have reported occasional crashes in other Windows applications when using WSL.
Nonetheless, WSL is a non-intrusive solution that allows you to develop and debug PHP applications seamlessly on Windows. It’s worth exploring and evaluating for your PHP development needs.
© 2013 - 2025 Foreignerds. All Rights Reserved