Xdebug is great for debugging your PHP code in real time. There are a few ways to install it on RHEL 8, but the simplest and most straightforward one utilizes packages found right in RHEL's repos.

In this tutorial you will learn:
  • How to Install the Dependencies
  • How to Install Xdebug with PECL
  • How to Configure PHP to Use Xdebug
  • How to Make Sure Xdebug is Loaded
PHP Xdebug on RHEL 8
PHP Xdebug on RHEL 8.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8
Software PHP Xdebug
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install the Dependencies

Before you can do anything, you're going to need to install a few PHP dependencies to be able to download and build Xdebug. These are probably things that you'd want anyway on a machine you're using to develop with or host PHP. They're all in the default RHEL repositories, so go ahead and install them with dnf.

# dnf install php php-devel php-pear

Install Xdebug with PECL

Next, you can install xdebug with PECL. There are a few other ways to get it, but currently, they don't seem to match up right. That might change in the future, but PECL will definitely work.


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


# pecl install xdebug

It might take a few minutes to set up, once you're done, you'll have the Xdebug PHP module.

Configure PHP to Use Xdebug

In order to use your new Xdebug module, you're going to need to add it to your PHP configuration. RHEL 8 uses a series of smaller .ini files to add modules to the complete PHP configuration. They're located in /etc/php.d. Create a new one for Xdebug at /etc/php.d/30-xdebug.ini, and open it with your favorite text editor.

Inside the Xdebug module configuration, place the following settings. Clearly, the most important one is the first line that points to the module itself.

zend_extension="/usr/lib64/php/modules/xdebug.so"
xdebug.remote_log="/tmp/xdebug.log"
xdebug.profiler_enable = 1
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=on
xdebug.idekey=editor-xdebug

When you're done, save the configuration.

Next, you're going to need to restart your server running PHP. For Apache, use the follwoing.

# systemctl restart http

If you're running PHP-FPM and Nginx, use:

# systemctl restart php-fpm

If, for some chance, that didn't work in the next step, restart your computer.

Make Sure Xdebug is Loaded

It's simple to see if Xdebug is working and loaded in PHP. Assuming your web root is /var/www/html, edit or create a new file at /var/www/html/index.php.

Inside the file, run the phpinfo() method to print out a ton of info on your system's PHP configuration.

<?php phpinfo(); ?>

Open your browser and navigate to that page. You should be able to search for xdebug and find a block detailing information about your install. If you see the block, Xdebug is loaded and working.

Conclusion

There you have it! Xdebug in installed and configured on your system. Use PECL to keep it updated, and you shouldn't encounter any issues.

ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions