You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下WSL搭建LAMP的最佳方案及跨环境代码编辑问题咨询

How to Edit WSL /var/www Files with Atom & Best Practices for LAMP Setup in WSL

Hey there! I’ve been right where you are—switching from Laragon on Windows to WSL for development felt a bit clunky at first, but once you nail the workflow, it’s way smoother. Let’s break down your two main pain points:

Editing /var/www Files with Windows’ Atom

The core here is bridging WSL’s file system with Windows apps like Atom. You’ve got two reliable options:

Option 1: Access WSL Files Directly via Windows File Explorer

WSL exposes its file system through a network path. Open File Explorer and paste this into the address bar:

\\wsl$\<YourDistroName>\var\www

Replace <YourDistroName> with your WSL distro’s name (e.g., Ubuntu, Debian). Once you’re in that folder:

  • Right-click any file and select "Open with Atom"
  • Drag the entire www folder into Atom’s window to load the whole project

Option 2: Sync WSL’s /var/www with Your Existing Windows Code Folder

If you want to keep using your old C:/laragon/www directory (no file moving required), create a symbolic link in WSL that points to your Windows folder. Open your WSL terminal and run:

sudo ln -s /mnt/c/laragon/www /var/www

Now WSL’s /var/www acts as a shortcut to your Windows www folder. Edit files in C:/laragon/www with Atom like you always did, and WSL’s LAMP stack will read them directly. Fix permissions to avoid access issues:

sudo chown -R $USER:$USER /var/www

Best Practices for Setting Up LAMP in WSL

Stick with official distro packages for stability—here’s a step-by-step for Ubuntu (the most popular WSL distro):

1. Update Your Package List

First, make sure your system is up to date:

sudo apt update && sudo apt upgrade -y

2. Install Apache

sudo apt install apache2 -y

Start the service and set it to run on boot:

sudo systemctl start apache2
sudo systemctl enable apache2

Test it by visiting http://localhost in your Windows browser—you’ll see Apache’s default welcome page.

3. Install MySQL

sudo apt install mysql-server -y

Run the security script to set a root password and lock down your installation:

sudo mysql_secure_installation

Answer "Y" to most prompts for a secure setup. Access MySQL later with:

sudo mysql -u root -p

4. Install PHP & Required Modules

sudo apt install php libapache2-mod-php php-mysql -y

Restart Apache to apply the PHP module:

sudo systemctl restart apache2

Test PHP by creating an info file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Visit http://localhost/info.php—you’ll see the PHP info page if everything works.

For multiple projects, virtual hosts let you use custom domains like myproject.local:

  1. Create a project folder (e.g., /var/www/myproject)
  2. Create a config file at /etc/apache2/sites-available/myproject.conf:
    <VirtualHost *:80>
        ServerName myproject.local
        ServerAlias www.myproject.local
        DocumentRoot /var/www/myproject/public
    
        ErrorLog ${APACHE_LOG_DIR}/myproject.error.log
        CustomLog ${APACHE_LOG_DIR}/myproject.access.log combined
    </VirtualHost>
    
  3. Enable the site and rewrite module:
    sudo a2ensite myproject.conf
    sudo a2enmod rewrite
    sudo systemctl restart apache2
    
  4. Add the domain to your Windows hosts file (C:\Windows\System32\drivers\etc\hosts):
    127.0.0.1 myproject.local
    

Pro Tips

  • Use WSL 2 instead of WSL 1—it’s way faster for file operations.
  • If Laragon is using port 80, stop its Apache service first or change WSL’s Apache port in /etc/apache2/ports.conf.
  • Manage databases with Windows apps like HeidiSQL—connect using localhost and your MySQL credentials.

内容的提问来源于stack exchange,提问作者Fil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:53:15