Categories: TutorialsUbuntu

How to Check PHP Version in Linux (via 4 Methods)

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.

How to Check PHP Version in Linux (via 4 Methods)

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.

Method 1: Check PHP Version via PHP Command

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.

Method 2: Check PHP Version via PHP Script

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.

Method 3: Check PHP Version via System Path

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.

Method 4: Check PHP Version via APT Command

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.

Final Word

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.

Ubuntu Server Admin

Recent Posts

How to avoid package End of Life through backporting

In July 2025, git received CVE-2025-48384, a high vulnerability allowing arbitrary code execution when cloning…

3 days ago

Showcasing open design in action: Loughborough University design students explore open source projects

Last year, we collaborated with two design student teams from Loughborough University in the UK.…

1 week ago

Canonical Ubuntu and Ubuntu Pro now available on AWS European Sovereign Cloud

January 15, 2026 – Canonical, the publisher of Ubuntu and provider of open source security,…

1 week ago

How to install GitLab on Ubuntu 24.04

How to install GitLab on Ubuntu 24.04 will be explained in this blog post with…

1 week ago

How to Set Up OpenVPN Access Server on Ubuntu 24.04 (VM) & Connect Using OpenVPN Connect

Do you know what was always there but has increased multiple times in the last…

2 weeks ago

How to build DORA-ready infrastructure with verifiable provenance and reliable support

The Digital Operational Resilience Act (DORA) came into force across the EU on January 17,…

2 weeks ago