๐ The Real-Life Developer Struggle
A few weeks ago, I sat down to work on a clientโs Laravel project. Like always, I opened my terminal, typed php artisan serve
, then in another tab, ran npm run dev
. ๐คฆโโ๏ธ
Thatโs fine for once or twice โ but if youโre hopping between multiple Laravel projects daily, this gets really repetitive.
I thought to myself:
"Why not create a custom terminal command that launches both servers at once?"
So I built a global phpdev
command. Now I just type:
phpdev
...and both my backend and frontend fire up instantly.
Hereโs how you can set it up too โ step-by-step and OS-friendly.
๐ ๏ธ What We'll Do
- Create a script that runs
php artisan serve
andnpm run dev
in parallel - Make it globally accessible as a
phpdev
command - Ensure cross-platform compatibility (Linux, macOS, Windows)
๐งช Prerequisites
- Laravel installed (
php artisan
must work) - Node.js installed (
npm run dev
must work) - A terminal environment (e.g., Terminal, Git Bash, WSL, or Command Prompt)
๐ง For Linux & macOS Users
1. Create the script directory (if it doesn't exist):
mkdir -p ~/.local/bin
2. Create the phpdev
script:
nano ~/.local/bin/phpdev
Paste this inside:
#!/bin/bash
php artisan serve &
npm run dev
&
runs the Laravel server in the background so both commands can run concurrently.
3. Make it executable:
chmod +x ~/.local/bin/phpdev
4. Add it to your system PATH (if needed):
In your ~/.bashrc
, ~/.zshrc
, or shell config, add:
export PATH="$HOME/.local/bin:$PATH"
Then reload your terminal:
source ~/.bashrc # or source ~/.zshrc
๐ช For Windows Users (Using Git Bash or WSL)
1. Open Git Bash or WSL
Create a directory for scripts if not present:
mkdir -p ~/.local/bin
2. Create the script:
nano ~/.local/bin/phpdev
Paste the same script:
#!/bin/bash
php artisan serve &
npm run dev
3. Make it executable:
chmod +x ~/.local/bin/phpdev
4. Add to your PATH:
In ~/.bashrc
(or ~/.bash_profile
), add:
export PATH="$HOME/.local/bin:$PATH"
Then:
source ~/.bashrc
โ
Now you can type phpdev
in any Laravel project folder using Git Bash or WSL.
๐ Final Test
Navigate to any Laravel project:
cd ~/Projects/my-laravel-app
phpdev
Both servers should start. No more tab switching or manual steps!
Top comments (0)