10 astuces de développement Magento | Épisode 1 : Xdebug
Install, configure and USE Xdébogage :
Step 1: Installing Xdébogage
First things first, let's install Xdébogage. Open up your terminal (you can find it by rechercheing in the applications menu) and type in les éléments suivants command:
sudo apt-get install php-xdebug
Cette commande will download and install Xdébogage for you. Easy peasy!
Step 2: Configuring Xdébogage
Now that Xdébogage is installed, we need to configure it. Open up your favorite text editor (like VSCode or Gedit) and open the Xdébogage fichier de configuration. Vous pouvez find it in /etc/php/<your_php_version>/mods-available/xdebug.ini.
If it doesn't work for you or the xdébogage.ini fichier is nooù be found, you can write this directly at the end of the php.ini fichier which devrait être in the parent répertoire.
Add les éléments suivants lines to the fichier:
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.mode = debug
xdebug.discover_client_host = 1
Save the fichier and close it.
Step 3: Setting Up PHPStorm
Time to jump into PHPStorm! Open up PHPStorm and navigate to File > Settings > Languages & Frameworks > PHP > Debug.
Check the box that says "Can accept external connections" and make sure the débogage port is set to 9000.
Then jump into Run > Edit Configurations.
Click '+' on the top left, then select "PHP Remote Debug".
Give it a name let's say "Dev" and check the "Filter débogage connection by IDE clé".
Type in the IDE clé "PHPSTORM" and click on the "..." button on the right of the "Server" champ to add a new one.
In the Server configuration popup click "+" again then give it a name let's say "Dev" again.
Type in the host of the current local magento installation like http://magento.local for exemple, and the port on which your apache or nginx is listening.
Click OK to close the popup, and now you can Validate your configuration by clicking on the "Validate" word in the "Pre-configuration" area.
N'oubliez pas de restart apache or nginx before you proceed.
In the validation popup check the "Local Web Server or Shared Folder" and type in the /path/to/magento/root/pub répertoire and the url of your local installation like http://magento.local:80 for exemple.
If everything is correctly configured all the lines devrait être green, otherwise try to add the missing configuration that PhpStorm is asking for.
Step 4: Configuring Magento 2
For Magento 2 specifically, we need to make sure that Xdébogage is being used by our PHP CLI. Open up your terminal and run les éléments suivants command:
sudo nano /etc/php/<your_php_version>/cli/php.ini
Add the same Xdébogage configuration lines that we added earlier to this fichier as well. Save and close the fichier.
Step 5: Configure Chrome
To make sure Chrome is sending the right IDE clé in every request made to your local Magento installation we will use the Xdébogage Helper extension which exists on both Chrome and Firefox.
Une fois installed make sure to configure it to send the "PHPSTORM" clé we typed earlier in the PHPStorm débogage configuration popup, then click on the extension to activate it while you're blignesing your website.
Step 6: Testing
To make sure everything is working smoothly, restart your web server:
sudo service apache2 restart
Maintenant, set a breakpoint in your Magento 2 code using PHPStorm. Run your Magento 2 application in the bligneser, and if everything is set up correctly, PHPStorm should catch the breakpoint and allow you to débogage your code!
And that's it! You're all set up with Xdébogage for Magento 2 development. Happy coding, friend! Si vous run into any problèmes, feel free to reach out.