In this article, I will take you through the steps to install PHP Xdebug on Ubuntu 20.04 LTS (Focal Fossa). Xdebug is a free and open source extension of PHP that provides developers a wide range of features like better error messages, advance debugging support, code coverage, profiling and so on. It also provides lot of PHP inbuilt functions which helps gather more information about the application being developed. More on official website.
- It allows us in analyzing the performance of our PHP applications using Visualization tools.
- It allows us to trace every function call with arguments and invocation location to disk.
- It provides a way to debug your code in IDE or editor while script is executing.
- It also shows us the parts of our code base that are executed during the PHP Unit testing.
- It provides an improved version of var_dump() function, stack traces for Notices, Warnings, Errors and Exceptions to highlight the code path to the error.
How to Install PHP Xdebug on Ubuntu 20.04 LTS (Focal Fossa)
Also Read: How to Install Anaconda 3 on Ubuntu 20.04 LTS (Focal Fossa)
Step 1: Prerequisites
a) You should have a running
Ubuntu 20.04 LTS Server.
b) You should have
root access to run privileged commands.
c) You should have
dpkg utility available in your Server.
Step 2: Update Your Server
Always sync the system cache with the latest available package information and updates from all the enabled repositories by using
apt update command. This will help system download any missing package updates. If any of the packages needs to be upgraded then run
apt upgrade command as well.
root@cyberithub:~# apt update Hit:1 https://dl.google.com/linux/chrome/deb stable InRelease Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Get:4 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:5 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] Get:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB] Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.4 kB] Get:8 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B] Fetched 446 kB in 2s (196 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done
Step 3: Install PHP Xdebug
In the next step, you can install PHP Xdebug package by using
apt install php-xdebug command as shown below. This will download the package along with all its dependencies from default Ubuntu Repo.
root@cyberithub:~# apt install php-xdebug Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libfwupdplugin1 libllvm11 Use 'apt autoremove' to remove them. The following additional packages will be installed: php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-phpdbg php7.4-readline Suggested packages: php-pear The following NEW packages will be installed: php-common php-xdebug php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-phpdbg php7.4-readline 0 upgraded, 8 newly installed, 0 to remove and 2 not upgraded. Need to get 4,584 kB of archives. After this operation, 20.3 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ..........................................
Step 4: Verify Installation
Once the package is installed successfully, you can verify the installed files using
dpkg -L php-xdebug command as shown below.
root@cyberithub:~# dpkg -L php-xdebug /. /etc /etc/php /etc/php/7.4 /etc/php/7.4/mods-available /etc/php/7.4/mods-available/xdebug.ini /usr /usr/lib /usr/lib/php /usr/lib/php/20190902 /usr/lib/php/20190902/xdebug.so /usr/share /usr/share/doc /usr/share/doc/php-xdebug /usr/share/doc/php-xdebug/changelog.Debian.gz /usr/share/doc/php-xdebug/copyright
Step 5: Uninstall PHP Xdebug
Once you are done with PHP Xdebug, you can uninstall the package by using
apt remove php-xdebug command as shown below.
root@cyberithub:~# apt remove php-xdebug Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libfwupdplugin1 libllvm11 php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-phpdbg php7.4-readline Use 'apt autoremove' to remove them. The following packages will be REMOVED: php-xdebug 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. After this operation, 2,174 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 190619 files and directories currently installed.) Removing php-xdebug (2.9.2+2.8.1+2.5.5-1build1) ...