Windows 10自带Ubuntu子系统搭建PHP项目及相关开发问题咨询
Hey there! Let's break down your questions one by one to clear things up, based on my experience with WSL (Windows Subsystem for Linux):
1. Can you install all the tools you mentioned in WSL Ubuntu?
Let's go through each tool:
- Laragon/Wamp: These are Windows-native tools that rely on Windows system services and environment. You can't install them directly in WSL Ubuntu. Instead, use Ubuntu's native LAMP stack (Apache + MySQL/MariaDB + PHP) which works perfectly in WSL and serves the same purpose.
- PhpStorm: While you can install the Linux version of PhpStorm in WSL (requires setting up an XServer like VcXsrv for GUI), it's far more practical to install the Windows version of PhpStorm. You can then use its built-in WSL remote development features to connect to your WSL PHP environment—this gives you a smoother UI experience and easy access to both Windows and WSL files.
- Google Chrome: The
chromium-browseryou installed is a Linux build. To open it from WSL, you need to:- Install an XServer on Windows (like VcXsrv) and start it.
- In WSL, run
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0to set the display variable. - Now run
chromium-browserto launch it.
That said, using the Windows version of Chrome is way simpler—you can still access your WSL-hosted Apache services from it (more on that below).
- PostgreSQL: Your command
sudo apt-get install postgresql postgresql-contribis correct! PostgreSQL runs flawlessly in WSL, and you can even connect to it from Windows tools if needed.
2. Where to place your project files?
You have two main options, with a clear performance winner:
- WSL file system (recommended): Store projects in paths like
/home/your-username/projects/. WSL has better performance when accessing its own file system, and Linux permissions work natively with services like Apache. This avoids the overhead of WSL reading/writing to Windows drives. - Windows file system: If you need to share files with Windows apps, you can place them in
/mnt/c/Users/your-username/projects/(maps to your Windows C:\Users folder). Just note that you'll need to adjust file permissions for Apache to access these files (e.g.,sudo chown -R www-data:www-data /mnt/c/.../your-project/), and performance will be slower for frequent file operations.
3. Can you mix Windows and WSL features (e.g., WSL Apache + Windows Chrome)?
Absolutely—this is one of WSL's best features!
- WSL 2 automatically forwards localhost traffic between Windows and the subsystem. So if your WSL Apache is running (start it with
sudo service apache2 start), you can open Windows Chrome and navigate tohttp://localhostto access your WSL-hosted websites. - You can also use Windows tools like PhpStorm to edit files stored in the WSL file system directly, or connect to WSL's PHP interpreter for debugging.
4. How to set up a PHP project in WSL Ubuntu?
Here's a quick step-by-step:
- Install PHP and essential extensions:
sudo apt-get install php libapache2-mod-php php-mysql php-pgsql php-cli php-curl php-gd - Restart Apache to enable the PHP module:
sudo service apache2 restart - Test PHP works: Create a file
info.phpin Apache's default root directory (/var/www/html/) with this content:
Open Windows Chrome and go to<?php phpinfo(); ?>http://localhost/info.php—you should see the PHP info page if everything's set up right. - For custom projects:
- Create a project folder in your WSL home directory, e.g.,
/home/your-username/projects/my-php-app/. - Set up an Apache virtual host by creating a config file in
/etc/apache2/sites-available/my-php-app.conf(pointDocumentRootto your project folder). - Enable the site with
sudo a2ensite my-php-app.confand restart Apache. - Adjust folder permissions for Apache:
sudo chown -R www-data:www-data /home/your-username/projects/my-php-app/
- Create a project folder in your WSL home directory, e.g.,
内容的提问来源于stack exchange,提问作者Joshua Kisanga
相关产品推荐
相关产品推荐

