Xdebug and other non compiled PHP extensions on CentOS

As some of you might know, I’m quite a fan of uberspace, a small German hosting company. They allow you a lot on a shared space like having Node.js available, running Apache, Nginx or lighttp as host and so on. But it all comes with a minor drawback: They are running on CentOS 6. The OS per se isn’t bad, it just has a lot less docs and tutorials available as opposed to Ubuntu for example.

I had a hard time figuring out how to install Xdebug properly, so I thought I might share it with you. First, when you ssh into your box, you end up in your user directory. And this is right where we will start as it is outside of your public www/html directory and a nice fit for the extension. For that we will use wget to fetch the archive from the official repository. Hint: Check the last modified date as the names might be confusing and indicate a later version when it isn’t.

; Grab Xdebug
wget http://xdebug.org/files/xdebug-2.2.5.tgz
; We could use pecl as well, but it will fail 
; due to missing permissions on uberspace
; pecl install xdebug

Depending on if we are on an uberspace-space, a VPS, your local VM or a dedicated server we will chose the next steps: Unpacking time.

; Unpack the archive
tar -xzf /home/${USER}/xdebug-2.2.5.tgz
; If we used the pecl installer, then look into the Pear downloads dir
; tar -xzf /home/${USER}/pear/download/xdebug-2.2.5.tgz

Now we should have a new folder named xdebug-2.2.5 in our user directory. Let’s cd into that folder and utilize the phpize command to prepare our environment. Upfront a quick quote from PHP.net that will give you some important insights:

Sometimes, using the pecl installer is not an option. This could be because you’re behind a firewall, or it could be because the extension you want to install is not available as a PECL compatible package, such as unreleased extensions from SVN. If you need to build such an extension, you can use the lower-level build tools to perform the build manually.

; PHPize the unpacked archive
/package/host/localhost/php-${VERSION}/bin/phpize xdebug-2.2.5

The installation task always will be the same no matter what:

make install
; Check if it worked
make test

Then we just have to adjust our php.ini file as we can read in the following quote from php.net

A successful install will have created extname.so and put it into the PHP extensions directory. You’ll need to and adjust php.ini and add an extension=extname.so line before you can use the extension.

To find our .ini file, we simply enter php --ini on the command line to get our path. Then things get even more easy.

; Open the php.ini file with nano/pico/vim
nano /home/${USER}/etc/php.ini

And at the end of that file, we add the following lines. You can configure them to your needs:

; The extension itself
; Default settings for Remote Debugging with PHPStorm


; No limits - we want it all

That’s it.