DEV Community

Cover image for ๐Ÿš€ Create a Global phpdev Command to Launch Laravel + Vite Simultaneously
Tahsin Abrar
Tahsin Abrar

Posted on • Edited on

๐Ÿš€ Create a Global phpdev Command to Launch Laravel + Vite Simultaneously

๐Ÿ‘‹ 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
Enter fullscreen mode Exit fullscreen mode

...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 and npm 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
Enter fullscreen mode Exit fullscreen mode

2. Create the phpdev script:

nano ~/.local/bin/phpdev
Enter fullscreen mode Exit fullscreen mode

Paste this inside:

#!/bin/bash
php artisan serve & 
npm run dev
Enter fullscreen mode Exit fullscreen mode

& runs the Laravel server in the background so both commands can run concurrently.

3. Make it executable:

chmod +x ~/.local/bin/phpdev
Enter fullscreen mode Exit fullscreen mode

4. Add it to your system PATH (if needed):

In your ~/.bashrc, ~/.zshrc, or shell config, add:

export PATH="$HOME/.local/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Then reload your terminal:

source ~/.bashrc   # or source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

๐ŸชŸ 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
Enter fullscreen mode Exit fullscreen mode

2. Create the script:

nano ~/.local/bin/phpdev
Enter fullscreen mode Exit fullscreen mode

Paste the same script:

#!/bin/bash
php artisan serve & 
npm run dev
Enter fullscreen mode Exit fullscreen mode

3. Make it executable:

chmod +x ~/.local/bin/phpdev
Enter fullscreen mode Exit fullscreen mode

4. Add to your PATH:

In ~/.bashrc (or ~/.bash_profile), add:

export PATH="$HOME/.local/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Then:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

โœ… 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
Enter fullscreen mode Exit fullscreen mode

Both servers should start. No more tab switching or manual steps!

Top comments (0)