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.
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.
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.
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.
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.