Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How to Set up Xdebug in PhpStorm | PhpStorm Documentation

Vinh Jacker | 11-11-2024

How to Set up Xdebug in PhpStorm | PhpStorm Documentation

Xdebug is a PHP extension that offers many debugging and profiling features to support developers in troubleshooting and optimizing their PHP code. These features include code coverage, stack traces, profiling information, and many other capabilities.

In this article, we will walk you through how to set up Xdebug in PhpStorm to enhance your development process. Let’s dive in!

Step 1: Install the Xdebug module into PHP

Firstly, you need to ensure that PHP is installed on the system. If not, you can install it based on your operating system. For example, on Ubuntu, you can use:

sudo apt update
sudo apt install php8.3

Then, install the Xdebug extension compatible with your PHP version. You can use the following command:


sudo apt-get install php{php_version}-xdebug

Ex: sudo apt-get install php8.3-xdebug

To check your Xdebug run this command php -v

Check Xdebug

You will see the Xdebug with that version.

Step 2: Configure Xdebug in xdebug.ini

Open xdebug.ini file to edit

You can use either of the following commands:

sudo gedit /etc/php/8.3/mods-available/xdebug.ini
or
sudo nano /etc/php/8.3/mods-available/xdebug.ini

Copy and paste this content to this file

Add the following Configuration for Xdebug 3:

[Xdebug]
zend_extension="xdebug.so"
xdebug.mode=debug,develop
xdebug.start_with_request=default
xdebug.idekey=PHPSTORM
xdebug.client_port=9000 #run on port 9000
xdebug.file_link_format=phpstorm://open?%f:%l

For Xdebug 2, use the following configuration:

#zend_extension=/usr/lib/php/20151012/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9000  #run on port 9000

  • Save and close the file

  • Restart apache:

sudo service apache2 restart

Step 3: Configure PhpStorm

Configure PhpStorm

  • Open PhpStorm > Navigate to settings > select PHP

  • Go to Debug in the top left corner > set the Debug port to 9000 as specified in the xdebug.ini

Debug port Turn on listening at the configured port by clicking on the call icon

Php Debug connections

Step 4: Install the Xdebug Chrome extension

To enable Xdebug for the browser, you need to install the Xdebug Chrome extension, follow these steps to install the extension.

Xdebug chrome extension

  • In the browser, Go to Option > set the IDE KEY to PHPSTORM

ide key

  • Then, on the Magento Site, start the session of Xdebug by enabling the Chrome extension

Magento site

  • After that, refresh your Magento site and check your PHPStorm

Check Phpstorm

  • Click accept

  • Go to Setting of PHP > servers, uncheck the option specified in the text

Setting of PHP

  • Click Ok

  • Lastly, refresh your Site in the browser

Refresh the site in the browser

That is all the steps! Now you can try using keyboard shortcuts like F9, F8, F7,.. or check the variable in PhpStorm

Final Word

We hope that our blog has given you a clear understanding of how to set up Xdebug in PhpStorm. Just follow the step-by-step guide above, and you will succeed. If you encounter any challenges or have any questions, don’t hesitate to contact us.

Table of content
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services