How to setup Xdebug for Laravel in PHPSTORM
Integrating Xdebug with Laravel in PHPStorm can significantly enhance your debugging experience. Here’s a step-by-step guide to achieve this effortlessly:
Prerequisites
- Ensure PHP, Composer, and Laravel are installed on your system.
- Install PHPStorm, a popular IDE for PHP development.
Step 1: Install Xdebug
Install Xdebug: Depending on your PHP version, install Xdebug using PECL or Composer.
pecl install xdebug
Configure php.ini: Add the following lines to your
php.ini
file to enable Xdebug. You can download php_xdebug.dll file from https://xdebug.org/ by pasting your php.ini details. Run the command ‘php -i’ in the command line, then copy the output and paste it into this URL to get the php_xdebug.dll file.
[xdebug]
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
xdebug.mode=debug,develop
xdebug.idekey=PHPSTORM
xdebug.client_host=127.0.0.1
xdebug.client_port=9000
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.start_with_request=yes
Step 2: Set Up Laravel Project in PHPStorm
- Open Laravel Project: In PHPStorm, open your existing Laravel project or create a new one.
- Configure PHP Interpreter: Go to
File > Settings > PHP
and set the PHP interpreter to the version where Xdebug is installed.
Step 3: Configure Xdebug in PHPStorm
- Enable Xdebug Integration: Go to
Run > Edit Configuration > + > PHP Web Page.
2. Click on Server and set the configuration as shown in the below image. If you’re using Laravel, there’s no need to define path mappings.
3. Select the server just created recently and press OK.
4. Select the configuration setting here in the editor.
Step 4: Set Up Path Mappings
- Set Path Mappings: For a local environment, you don’t need to map anything if you are doing for laravel, If it is a normal PHP application then you can map your root folder.
Step 5: Install a Browser Extension
- Install the Xdebug Helper extension for Chrome. This extension allows you to easily start and stop debugging directly from your browser.
- After installing the extension, click on its icon in the Chrome toolbar.
- Go to
Options
and set the IDE key toPHPSTORM
. This ensures that the extension communicates correctly with PhpStorm.
Step 6. Configure PhpStorm to Listen for Debug Connections
- Open PhpStorm.
- Click on the “Start Listening for PHP Debug Connections” button.
- Also, enable break at the first line in PHP scripts as shown in the screenshot.
Run your laravel server and enable the start Listening for PHP to debug connections as shown in the screenshot above. That’s it.
Finally, run the below command or the below command if your debugger is not working.
set XDEBUG_CONFIG=remote_enable=1 remote_mode=req remote_host=127.0.0.1
remote_port=9000 remote_connect_back=0