如何在Windows 10下通过Git Bash/命令行打开PhpStorm项目?
Hey there! I’ve been in your exact situation before—using Windows 10, Homestead, and PhpStorm 2017.3, and wanting to quickly fire up projects straight from Git Bash or the command line. Here’s how I got it working smoothly:
1. Add PhpStorm to Windows System Path
First, we need to make Windows recognize the PhpStorm executable from any command line window:
- Locate your PhpStorm 2017.3
binfolder. The default path is usuallyC:\Program Files\JetBrains\PhpStorm 2017.3\bin - Open Windows Settings, search for Environment Variables, then click "Edit the system environment variables"
- In the System Variables section, find the
Pathvariable, click "Edit" - Click "New" and paste the full path to the PhpStorm
binfolder, then save all windows - Test it: Open a regular Command Prompt and type
phpstorm—PhpStorm should launch right away
2. Configure Git Bash to Use the
phpstorm Command Git Bash uses a Unix-style path system, so we’ll set up an alias to make it work seamlessly:
- Open Git Bash and run this command to add the alias to your bash profile:
echo 'alias phpstorm="phpstorm.exe"' >> ~/.bashrc - Refresh the bash profile to apply changes immediately:
source ~/.bashrc - Now you can use it two ways:
- Open the current directory as a project:
phpstorm . - Open a specific project path (use Git Bash’s path format—replace
C:\with/c/):phpstorm /c/Users/YourUsername/Projects/your-awesome-project
- Open the current directory as a project:
3. Using PhpStorm from Homestead
If you’re working inside the Homestead VM, we need to connect it to your Windows PhpStorm instance via an X server:
- First, install an X server tool like VcXsrv on your Windows machine. When launching it, make sure to check Disable access control
- In Homestead, edit your shell profile (either
~/.bashrcor~/.zshrcdepending on your shell) and add these lines:export DISPLAY=host.docker.internal:0.0 alias phpstorm="/mnt/c/Program\ Files/JetBrains/PhpStorm\ 2017.3/bin/phpstorm.exe" - Refresh the profile:
source ~/.bashrc - Now you can open projects directly from Homestead:
phpstorm /home/vagrant/code/your-project
Bonus Quick Tips
- Open a single file directly in PhpStorm:
phpstorm path/to/your-file.php(works in all command line environments) - If you ever forget the alias, just check your
~/.bashrcfile to confirm the setup
内容的提问来源于stack exchange,提问作者Rasel
相关产品推荐
相关产品推荐

