Current Location: Home> Latest Articles> How to Quickly Check PHP Version on CentOS System

How to Quickly Check PHP Version on CentOS System

gitbox 2025-07-02

Why It's Important to Know Your PHP Version

In a CentOS server environment, knowing the current PHP version is essential for developers and system administrators. Confirming the PHP version helps ensure system security by avoiding potential vulnerabilities, while also maintaining compatibility and meeting the functional needs of your applications.

Multiple Ways to Check PHP Version on CentOS

Quickly Check via Command Line

The simplest and most direct method is to open a terminal and enter the following command:

php -v

After running this, you will see output similar to the following:

PHP 7.4.16 (cli) (built: Feb 23 2021 10:17:19) ( NTS )

The first line displays the PHP version you are currently using.

Use the phpinfo() Function for Detailed Configuration

If you need more comprehensive PHP configuration information, you can use the phpinfo() function. Follow these steps:

Create a new PHP file in your website's root directory, for example info.php, with the following content:

<?php phpinfo(); ?>

Save the file and then visit it in your browser (e.g., http://yourdomain.com/info.php). You will see a page showing detailed PHP version and environment information.

Check Installed PHP Version Using YUM Package Manager

If your PHP was installed via YUM, you can check the installed PHP version with this command:

yum list installed | grep php

This command lists all installed PHP-related packages along with their versions, allowing you to verify them quickly.

Summary

Checking the PHP version on a CentOS system is straightforward. Whether through the command line, phpinfo() function, or YUM package manager, you can easily obtain accurate version information. Keeping your PHP version updated helps improve server security and performance.