0 Shares 1947 Views 1 Comments
00:00:00
02 May

How To Install XDebug On CentOS 6.X / WHM Server, Configure PHPStorm And Forward Firewall Ports

Oliver Krautscheid Jun 04, 2015
0 1948 1

If you want to debug PHP sites, you need to install a great deal of programs and you need a decent IDE. In this guide, I will show you exactly how to install XDebug on a CentOS server and what some of the most common problems are

Tip: Do Not Install XDebug Via PECL

It may be tempting to install xdebug via PECL, by simply entering pecl install xdebug but this will not work well on most systems, including CentOS WHM servers. You will get the error failed loading xdebug.so when you do so. It is better to download and compile xdebug manually and you can be sure it will properly install xdebug as a zend extension and not a regular PHP extension

Compiling From Source: How To

1. Download the source from here – as of right now the latest is 2.2.3 (MD5: e49cec9861b45dc0b36eae33bf8a14fa)

Xdebug Source Md5

2. Open up Putty and enter cd /usr/bin, then run the code below to compile xdebug from source

Instructions for 2.2.3 (December 2013)

wget http://xdebug.org/files/xdebug-2.2.3.tgz
tar -xzvf xdebug-2.2.3.tgz
cd xdebug-2.2.3
phpize
./configure
make
make install

Configure Xdebug via PHP.ini

Alright, if you’re on a WHM server, enter

cd /usr/local/lib/
pico php.ini

Now at the top, it’s likely that you will already see zend_extension. If not, this is the most important setting to add, verify that the path is correct, don’t be lazy and check if xdebug.so actually exists

Copy and paste this at the top and modify xdebug.remote_host to match your current IP address

zend_extension = /usr/local/lib/php/extensions/xxx/xdebug.so
xdebug.remote_log="/tmp/xdebug.log"
xdebug.profiler_enable = 1
xdebug.remote_enable=on
xdebug.remote_host=YOURIP!
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.idekey=phpstorm-xdebug

A setting you may consider adding, but be warned that this has security implications and once you add this any IP addresses that requests your PHP app will be able to access the debug information

xdebug.remote_connect_back = On

Explanation from Xdebug Docs

If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request. It checks the $_SERVER[‘REMOTE_ADDR’] variable to find out which IP address to use

Confirm Xdebug is loaded properly

Enter the following into Putty / Shell:

php -i | grep xdebug

If you see that it returns “Failed loading Xdebug.so” you need to go back to the top and re-compile from scratch

Download A Good IDE: PHPStorm!

IDE’s are a must-have if you are serious about developing PHP sites. Download PHPStorm which is one of the best IDE’s on the market aside from Eclipse and NetBeans

1. Open up PHPStorm and click on File->Settings

2. Select PHP, then Debug

3. Enter the Debug port 9000 and make sure the checkbox Can accept external connections is checked

Xdebug Port

4. Now it’s time to tell PHPStorm to start listening on port 9000 (or 9001 or whatever you chose).

5. Hit ALT+SHIFT+F10

6. If you haven’t added localhost as a connection yet, do so now. Simply enter 127.0.0.1 as the host and use 9000 as the port and save the connection

7. Then hit the “green-bug-button” and check the bottom for the debugger panel

Phpstorm Listen On Port 9000.Png

Debugging Php Applications.png

Verify That Port 9000 Is Open And Your Firewall Is Forwarding It Properly

Now it’s time to see if an outside service can actually connect to your local machine on port 9000.

1. Open up http://canyouseeme.org/

2. Enter port 9000 and hit OK

Verify That Port Is Being Forwarded.png

3. Should you use a fritz, Cisco or Netgear router, make sure the router is forwarding port 9000. For testing purposes you can add an exposed host – make sure to remove this as soon as possible because it leaves you vulnerable to outside attacks (all ports are being forwarded when adding an exposed host)

Download Firefox And Chrome Extensions

A good web developer usually tests in different browsers, so download the Firefox and Chrome extensions:

Specify IDE Key

Alright, now let’s do a quick test and load a site on the server. You may have to add the correct IDE key first if you did not add the option remote_connect_back!

Firefox:
Specify Ide Key In Firefox

Chrome:
The options for the Chrome extension can be accessed via: This Link

After you have specified the key, hit F5 and if you followed all steps above correctly you should now get your first debug variables. If you don’t verify that your ports are correctly forwarded, that you set up the IDE-keys. Also restart your apache server and possibly restart your IDE and browsers, just to be sure.

Debug Variables.png

Useful Sources And Links

About Us

Webmaster .Net is your all-in-one resource for blogging tips, system administration guides, industry news and a growing community of webmasters.

Can't find something or want to tip us?Contact@webmaster.net

Bulls and Bears
  • Steve

    If you have no need of the xdebug profiler, you should set xdebug.profiler_enable = 0. Profiler files can fill up a /tmp directory FAST.

Webmaster Tutorials, Wordpress
0 shares663 views

WordPress SQL Query: Select And Delete Posts Between Two Dates

Oliver Krautscheid - Apr 08, 2017

If you are wondering how to delete posts for a certain date, you will need to know how Wordpress stores…

Advertising and Ad Networks, Copywriting
0 shares806 views

15 Tips For Increasing Facebook Ads CTR – Full Guide [2017 Update]

Cam Connor - Mar 30, 2017

In this article, we'll talk a lot about how you can write quality text ads on Facebook Ads to get…

Webmaster Tutorials
0 shares1484 views

10 Steps To Configure Nginx For WordPress, Drop Varnish And Cut Your CPU Load By 50%

Oliver Krautscheid - Oct 10, 2016

Are you using Varnish on your Wordpress blog? Possibly the Varnish script by Unixy? Great! Get rid off it. Here's…

Follow Us And get latest news

© 2016 Webmaster.Net - Property of Peakstone Media Ltd. - All rights reserved. | Privacy Policy | DMCA | Contact Us | Advertise