官方文档仅提供VSCode操作指引,如何使用PhpStorm访问Laravel Sail创建的文件?
Hey there! I’ve got you covered when it comes to working with Laravel Sail files in PhpStorm. Let’s walk through the simplest and most reliable methods:
1. Use the Local Project Directory (Recommended)
Laravel Sail uses Docker volume mounting to sync your local project folder with the container’s /var/www/html directory by default. This means you don’t need to connect directly to the container—just:
- Make sure your Sail containers are running:
sail up -d - Open PhpStorm, then select
File > Openand choose your local Laravel project root folder.
Any changes you make in PhpStorm (local files) will automatically sync to the Sail container, and vice versa.
Fixing Permission Issues
If you run into file permission errors (common on Linux/macOS), update your .env file with your local user’s UID and GID:
- Run these commands in your terminal to get your user IDs:
id -u # Gets your UID id -g # Gets your GID - Add these lines to your
.envfile:WWWUSER=your_uid_here WWWGROUP=your_gid_here - Restart the Sail containers to apply the changes:
sail down && sail up -d
2. Connect Directly to the Sail Container (Advanced)
If you need to access files directly in the Docker container (not recommended for daily use), set up a remote interpreter in PhpStorm:
- Open
File > Settings > Languages & Frameworks > PHP > CLI Interpreter - Click the
+button and selectFrom Docker, Vagrant, VM, WSL, Remote... - Choose
Dockeras the environment, then select your Sail container (usually namedlaravel.test) - Set the PHP interpreter path to
/usr/bin/php(the default path in Sail’s PHP container) - Once configured, you can use the Remote Host tool window in PhpStorm to browse and edit files directly in the container.
Troubleshooting Tips
- If files aren’t syncing, double-check your
docker-compose.ymlto confirm the volume mount is set correctly (default is./:/var/www/html) - Ensure Sail containers are running without errors—use
sail logsto check for issues - If PhpStorm doesn’t detect changes, try refreshing the project (
File > Reload All from Disk)
Hope these steps help you work seamlessly with Laravel Sail in PhpStorm!
内容的提问来源于stack exchange,提问作者Lamantinoss

