{"id":9841,"date":"2021-11-07T13:54:18","date_gmt":"2021-11-07T18:54:18","guid":{"rendered":"http:\/\/prod.main.brightwhiz.com\/?p=9841"},"modified":"2021-12-03T13:28:28","modified_gmt":"2021-12-03T13:28:28","slug":"get-active-major-minor-and-release-php-version-in-linux","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/get-active-major-minor-and-release-php-version-in-linux\/","title":{"rendered":"How to get Active Major, Minor, and Release PHP Version in Linux"},"content":{"rendered":"\n
You can find the active major, minor, and release PHP version in Linux servers with simple commands. There are two simple solutions using the PHP command-line with additional parameters.<\/p>\n\n\n\n
$ php -v | grep ^PHP | cut -d' ' -f2<\/code><\/pre>\n\n\n\nWill return output similar to this:<\/p>\n\n\n\n
8.0.12<\/code><\/pre>\n\n\n\n2. Get the PHP Version Using PHP + INTERNAL PHP_VERSION CONSTANT<\/h2>\n\n\n\n$ php -r 'echo PHP_VERSION."\\n";'<\/code><\/pre>\n\n\n\nWill return output similar to this:<\/p>\n\n\n\n
8.0.12<\/code><\/pre>\n\n\n\nIn the above example you can use these other PHP constants listed here:<\/p>\n\n\n\n
- PHP_MAJOR_VERSION (int)<\/li>
- PHP_MINOR_VERSION (int)<\/li>
- PHP_RELEASE_VERSION (int)<\/li>
- PHP_VERSION_ID (int)<\/li>
- PHP_EXTRA_VERSION (string)<\/li><\/ul>\n\n\n\n
Example: In the above examples the Major, Minor, and Release versions have been returned by default. If you only want the PHP version, without the release, you can use the following command:<\/p>\n\n\n\n
$ php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION."\\n";'<\/code><\/pre>\n\n\n\nWhich will return output similar to this:<\/p>\n\n\n\n
8.0<\/code><\/pre>\n\n\n\nThe above examples return the Cli PHP version. Your intention may be to return the version of the Apache module or PHP-FPM and not CLI. Depending on the settings the versions may be different.<\/p>\n\n\n\n
Find the PHP Version Used When Using Apache or Nginx<\/p>\n\n\n\n
We have two good ways of finding the PHP version when using a web server like Apache or Nginx.<\/p>\n\n\n\n
1 Create a PHP (.php) file and add the following code:<\/strong><\/p>\n\n\n\nphpinfo();<\/code><\/pre>\n\n\n\nSave the file on your web directory and open it using a web browser. It will show the actual PHP version being used.<\/p>\n\n\n\n
2 A Better Way.<\/strong><\/p>\n\n\n\nThe above example may be too verbose or overkill. A simpler solution is to use this function instead.<\/p>\n\n\n\n
echo php_ini_loaded_file().PHP_EOL;<\/code><\/pre>\n\n\n\nThere you have it, you should be able to get the right PHP version.<\/p>\n","protected":false},"excerpt":{"rendered":"
You can find the active major, minor, and release PHP version in Linux servers with simple commands. There are two simple solutions using the PHP command-line with additional parameters. 1….<\/p>\n","protected":false},"author":1,"featured_media":10739,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,27,16],"tags":[],"yoast_head":"\n
How to get Active Major, Minor, and Release PHP Version in Linux<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\n\n\n\t\n\t\n\t\n