Using “php artisan serve” with xdebug and PHPStorm

This is more of a person note for myself. This posts assumes some knowledge of php, Laravel, artisan, Homebrew, and xdebug.

I’ve been using php artisan serve to serve Laravel applications locally. It’s quick and it works well.

It’s probably not a great solution if you’re working with other people on a project, or if you want to implement a good CD/CI workflow. Having said that, it’s what I’m using today, so I figured I’d document how I got xdebug working with it (on my Mac).

Step 1: Install PHP with xdebug

Actually, I’ll just post my initial “prepare for Laravel development” setup steps.

Step 2: Configure xdebug

Find which php.ini file Laravel is using by dropping a phpinfo(); at the top of one of your routes. There may be an easier way, but this is pretty straightforward and won’t lead you to the wrong ini file.

Add these lines to the ini file:

Restart php to make sure the xdebug settings are applied. You can use php artisan serve for this.

Step 3: Start the Server

You can do this several few ways.

If you want your system (or is it Laravel’s artisan?) to pick the port automatically, use php artisan serve .

If you want to change the port, you can either set an env variable: export SERVER_PORT="8080" php artisan serve or you can set SERVER_PORT=8100  in your .env  file and use php artisan serve normally.

If you prefer the start the server through PHPStorm, use Run > Edit Configurations… to add a new “PHP Built-in Web Server”:PHPStorm run configuration

Step 4: Configure xdebug in PHPStorm:

Open Preferences > PHP > Debug and configure as shown below. I’ve highlighted the most important settings.

PHPStorm settings

Step 5: Test!

Start the server (e.g., php artisan serve )

Click the Run > Start Listening for PHP Debug Connections.

You will need to start and stop when you want to listen or stop listening.

The server will respond faster if you stop listening when you’re not needing to use xdebug.

Next, visit the site in your browser.

You should see a popup like this in PHPStorm, almost immediately:

Path mapping promptAfter you accept you should be able to drop a breakpoint in your code and PHPStorm should catch it.

You may want to rename the auto-configured server in Preferences > PHP > Servers. For example, I changed mine from  to mysite .

Leave a Reply

Your email address will not be published.