Debugging MediaWiki- Part 3 Using PHPStorm

Final post in this series, where we will integrate our debugger with PHPStorm.
Here is the previous post- https://crondev.wordpress.com/2014/12/14/debugging-mediawiki-part-2-installing-xdebug/

To start with, PHPStorm has been my favourite IDE for everything, it just is too clean and brilliant. Not discussing it’s frills here- check them on the website here.
And know what, Mediawiki developers get a free licensed version of PHPStorm!!

To start with, I am assuming that you have PHP and XDebug set up. If not, set up using instructions in this post.
Now download PHPStorm and install it as given in instructions. For Linux, extract it, and it can be launched using ./phpstorm in the folder where it was extracted. For OS X, simply install it and launch using icon.

Now you can create a New project and use the MediaWiki directory for the same.

Let’s integrate PHP and our debugger into it. Open Preferences->PHP and click on the button beside Interpreter. We need to add our PHP interpreter to this. Click the + button in the new window to add an interpreter. By default, it will suggest the usual path i.e. /usr/bin/php and that works usually. For windows, you might need to navigate to the correct folder.

If your debugger is installed correctly, you will see the Debugger as XDebug on this screen.
Here is a screenshot of the same
Setting up PHP interpreter

Now, click OK and we successfully installed the PHP interpreter. You may want to change the PHP language level to choose but it is optional.
Let’s make PHPStorm work with the debugger. For this, go to Debug and set the Debug port under XDebug same as what we set in the php.ini file.
Setting up debugger

Defining a PHP Server
Click on the + button in Preferences->PHP->Servers. In the host, type in localhost(or the server host for remote debugging)
New deployment server

Click on Validate Remote Environment, and Deployment server. Here we will need to create a new Server. Since, I was working with localhost, I used an In place server.
Now, go to Mappings, and map the absolute path of the application to the path of the directory. For eg I mapped /Users/kunal/Sites/Mediawiki to /~kunal/Mediawiki since it was accessible using http://localhost/~kunal/Mediawiki/index.php
Mapping paths

Click Ok and select this server. Click Validate and everything works. Here is a screenshot of the same.
Click Apply and Ok.
Validating environment

Now let’s try running Mediawiki. Create a new Run configuration using Run->Edit Configurations
Click on + button and select PHP Web Application. Add the URL that you would like to run/debug here.
Run configurations

Here is a screenshot of Special:SpecialPages application. You can now add breakpoints anywhere to stop and analyse the code. For instance, see the screenshot of debugging the Special:SpecialPages application we just created.
Debugging

If everything worked, you are good to go! The same can be applied for other PHP applications as well.

Thanks for reading this post, Signing off now.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s