in Web Development

Alias To Enable Disable xdebug

In this tutorial we're going to create a command line alias to quickly enable or disable xdebug.

When you install xdebug you will need to register the extension in your php.ini file. This will need to point to the xdebug extension file.


This will ensure that xdebug is enabled, the problem with this is that when running your unit tests it will be very slow. Therefore if you want to speed up running your tests a quick solution is to disable xdebug if it's not needed.

An easy way to disable xdebug is to rename the extension so that it can't be found, therefore we can create two scripts that will enable or disable xdebug, then we can create command line aliases making it very easy for us to switch xdebug on or off.

Disable xdebug script

This script will rename the xdebug file by adding a .disabled to the end of the file name, this will make sure the php.ini file can not find the extension file and therefore turn off xdebug.

Then it will restart php by using a homebrew command brew services restart php71.

Enable xdebug script

This script will do the opposite of the above and rename to just this will allow php.ini file to find the extension and enable xdebug again.

Then again it will restart php by using a homebrew command brew services restart php71.

Command Line Alias

Next we can make sure we can quickly run these scripts from any project we're working on by creating a command line alias to run these. Open your .bash_profile file and paste in the following.

Now we can run exd from the command line to enable xdebug and dxd to disable xdebug.

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email