29
Jul

How to Install, Configure, and Debug Magento 2 code with XDEBUG & PHPSTROM.

PHPStorm is one of the best IDE from JetBrains for PHP web development. In this article, I am going to show you how to install PHPStorm on Ubuntu 20.04 LTS. So, let’s get started.

Installing Ubuntu Make

You can easily install PHPStorm IDE using Ubuntu Make on Ubuntu 20.04 LTS. Ubuntu Make is available in the official package repository of Ubuntu 20.04 LTS.

Now, install Ubuntu Make with the following command:

Install-PHPSTROM

To confirm the installation, press Y and then press <Enter>.

Now, run the following command to check if the umake command is available:

unamek-version

Installing PHPStorm

You can easily install PHPStorm using the following umake command:

Unmake-Ide-PHPSTROM

At this point, PHPStorm should be installed.

Now, add execute permission to the PHPStorm desktop file as follows:

PHPSTROM-PERMISSION

Finally, reboot your computer for the changes to take effect.
Execute the below command after given the permission.

sudo reboot

Once your computer boots, you can access PHPStorm from the Application Menu of Ubuntu 20.04 LTS.

PHPSTROM

Now, Click on New Project.
Select from your computer and set the location.

Click-New-Project

After clicking on Open button, You’ll see the below display.

Project-Open

Now, let's install Magento Coding Standard.

Moreover, You’ve to install Magento Coding Standard.
GO through google
Search for how to install magento coding standard using Github repo.
Execute the highlighted command.
You can also install via composer.

Magento-Coding-standadrd install

Now Installation is completed.
How To verify its Installed or not?
Execute the below command to verify.

Magento-Coding-Standard-Verification

How to configure Magento Coding Standard with PHPSTROM

Go To the PHPSTROM.
Go through FIle -> Setting -> Language & Framework -> PHP -> Quality Tools -> PHP Codesniffer

Phpstrom-coding-stand-configuration

Go through FIle -> Setting ->Editor -> Inspections -> PHP_CodeSniffer validation -> Coding Standard  —- Select Magento 2
Now Click on Apply Button.

MAgento2-coding-standard

Why do we need Xdebug?

In the development process, we have several existing codes with a number of functionalities. We don’t have to create that functionality from the core every time.  We can rather use the existing code and make simple modifications that will save our time and energy. Product development processes work the same. Before modifying the existing code, we need to know how they work and which codes have which functionality.

How To install Xdebug

  • Now, moving ahead to install the Xdebug.
    How to install it?
    Lets’s have a look on it.
    Execute the below commands for the installation of Xdebug.
  • sudo apt -y install php7.4-dev php-pear
  • sudo pecl channel-update pecl.php.net
  • sudo apt update
  • sudo apt install php-xdebug
  • php -v
  • sudo nano /etc/php/7.4/cli/conf.d/20-xdebug.ini
    [xdebug]
    zend_extension=”xdebug.so”
    xdebug.mode=”debug”
    xdebug.start_with_request=trigger
    xdebug.client_port=9003
    xdebug.log=”/home/d45-bt/logs/xdebug.log”
    xdebug.start_with_request=”yes”
  • sudo service apache2 restart

Now, You’ve successfully configured the Xdebug.
Let’s Have a look on How it works.

xdebug

Final Words

In that article we tried to explain how PHP storm, Magento coding standard, and XDebug work & install, I think this is crucial for using it. Furthermore, it is always worth it to understand how things work under the hood.
The configuration described in that article is only one possible way, that works well in my case. If you have another situation, you may need another configuration. Anyway, if you have problems with configuring XDebug, please feel free to ask below in the comments. This debugging of code using Xdebug and PhpStorm can be beneficial for your development in the debug process, thus helping you save the amount of time spent searching on Google.

Born Techies –Digital Commerce agency offers ShopifyShopwareMagento, and Bigcommerce development with the latest technologies.

Do you want to receive a free consultation about how to optimize your store and generate more sales? Reach us out at [email protected] or contact us, and we will be more than happy to help you out.