PHP is a popular scripting language used in the backend during web development to take the client request, process the request and respond to it, or execute MySQL queries.
Many popular CMS (content management systems), such as WordPress, Joomla, Drupal, Laravel, Magento, Symfony, and many more, are based on PHP.
As the popularity of PHP grows, each PHP version undergoes multiple changes, such as performance improvements, functionality updates, and security enhancements.
With this release, knowing the PHP version installed on your system is crucial, especially if you plan to develop a new web app based on PHP; ensure you check the PHP version on your system and strategize your development accordingly.
In this article, I’ll show you how to check the PHP (or PHP-FPM) version on Ubuntu and other Linux distros using the command line.
There are multiple ways to find out the PHP version installed on your system: I’ll show you four methods— the first three work for any Linux distribution such as Debian, Ubuntu, Red Hat, Fedora, Arch, Manjaro, etc., while the fourth method only works for Ubuntu-based distributions such as Debian, Pop!_OS, Linux Mint, etc.
The simplest way to find out the PHP version is by using the “-h” or “–help” flag with the “php” command in your command line.
$ php -v
Output:
This method will work for the majority of Linux distributions with PHP installed through a package manager.
When PHP is installed using a different method, such as source code, the previous method might not work as it relies on passing the help flag to the PHP binary file that resides in the bin folder.
If you’re using the absolute path of the PHP binary file to run your PHP script, you can create a new PHP file named “phpversion.php” and include the following content:
Then, you have two options: either run the PHP server and access the PHP file in your web browser to check the PHP version, or pass the PHP file to the absolute path of the PHP binary file and use the grep command to find the PHP version.
$ /path/to/php phpversion.php | grep "PHP Version"
Output:
This method would work for all Linux distributions, as well as Windows and macOS.
If you’ve relocated the PHP directory and can’t locate it, neither of the previous methods will work. In such cases, you can use a few command-line tools to find the PHP directory.
For example, in the given command, “locate” will search for a file or directory named PHP, “grep” will filter the results for files ending with the name PHP, and the final command is “xargs” and “ls“, which are used to follow symbolic links, taking stdin data from the previous piped command.
$ locate php | grep -P "/php$" | xargs ls -L
When you run the above command, it will return all PHP files, sometimes including the PHP version in the output, as shown.
If the PHP version isn’t displayed, you can look for a PHP file in a bin directory or use tools like the file command to identify a binary file. Then, use the absolute path to the PHP binary file along with the help option to determine the PHP version.
$ /usr/bin/php -v
Output:
This method is quite effective but might be a bit trickier for beginners, so if you’re using a Debian or Ubuntu-based distribution, you can follow the next method to verify the PHP version.
When you install a program on a Debian or Ubuntu-based distribution, it adds an entry in the APT list that you can use to check the PHP version installed on your system.
$ apt list --installed | grep php
Output:
This method would only work for Debian or Ubuntu-based distributions; if you’re uncertain about the Linux distribution you’re running, use the command “cat /etc/os-release” to identify it.
In this article, you’ve learned various methods to check the PHP version running on your Linux system. If you have any questions, feel free to ask them in the comment section.
Till then, peace!
The post How to Check PHP Version in Linux (via 4 Methods) appeared first on Linux TLDR.
The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…
Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…
Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…
Focal Fossa will reach the End of Standard Support in May 2025, also known as…
Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…
Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…