Проверить версию php linux

Checking what PHP version I’m running on Linux?

I’m running Centos 5 and I need to know what version of PHP I’m running, is there a command for this which I can run?

4 Answers 4

Try running the following at the command line.

To just get the version information:

It should give you all information you need about the php install.

Just be cautious that the CLI version of PHP (checked from command line) can be different from the one served by your webserver (shown by phpinfo())

@AkshayRaje Exactly. Most people who ask “What PHP version am I using?” are usually referring to the Apache/Nginx PHP module and not the PHP CLI stuff. The PHP CLI info has 100% nothing to do with the PHP module used by Apache/Nginx.

You can make an index.php file with

this has the advantage of working on servers you don’t have ssh access to, though personally I’ve always preferred , just for the futureproofing 😛

On any PHP website one can often see the version in the X-Powered-By header in each PHP generated HTTP response. When you don’t have SSH access, then sometimes phpshell.sourceforge.net can be used. (Though with much care, like one needs to check if a folder is writable before running a tar command.)

First, this is the answer. Most people who ask “What PHP version am I using?” are usually referring to the Apache/Nginx PHP module and not the PHP CLI stuff. The PHP CLI info has 100% nothing to do with the PHP module used by Apache/Nginx. But @Arjan also, many systems administrators disable the “X-Powered-By” header servers send out as part of security hardening. While it seems convenient for developers, headers like that put you on the “sucker list” for botnet attacks. If you run a server and the main way you are determining PHP version is via “X-Powered-By” your process is very flawed.

Читайте также:  Linux system shell command

Источник

How to Check PHP Version (Apache/Nginx/CLI)

PHP (Hypertext Preprocessor) is a popular programming language generally used for web development. It was originally developed by the Danish-Canadian programmer Rasmus Lerdorf in the year 1994. It can be used either via the command line or used with popular web servers like Apache or Nginx. Apache has a PHP module to directly run PHP files but Nginx required a PHP-FPM package to work with PHP files.

This tutorial will help you to check the PHP version installed on your system. Also, what is the active version of PHP on the command line as well as the check PHP version used by Apache or Nginx? As we can install multiple PHP versions on a single system, it can be the there are different version’s active on CLI and Web servers.

Check PHP Version (CLI)

By default, there can be one default PHP version that can use with standard binary. To check the PHP version currently active on the command line, execute the following command on the terminal:

Output
PHP 7.4.8 (cli) (built: Jul 13 2020 16:45:28) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies

On Ubuntu and Debian systems, you can also access another version by pointing their versions like: php7.2 or php7.3 etc.

Check PHP Version (Apache/Nginx)

This is fine that, the current active PHP version on the command line is different than the version used by the Apache or Nginx web servers. It’s also possible that two virtual hosts can use different-2 PHP versions by using PHP-FPM.

So, to check the currently active version for Apache or Nginx, navigate to the document root of the website to which you want to check the PHP version. For example, my document root is “/var/www/html”:

Then create and edit a PHP script file in your favorite text editor:

And, add the following content to the files. Here we used built-in phpinfo() function, which prints the active PHP version details:

Читайте также:  Kali linux the quieter you

Источник

Как проверить версию PHP

PHP — один из наиболее часто используемых языков программирования на стороне сервера. Между версиями PHP есть некоторые важные различия, поэтому в некоторых ситуациях может потребоваться знать, какая версия работает на вашем сервере.

Например, если вы обновляете свое приложение или устанавливаете новое, для которого требуется определенная версия PHP, перед началом установки вам необходимо узнать версию вашего PHP-сервера.

В этой статье мы покажем вам, как проверить, какая версия PHP работает на вашем сервере.

Проверка версии PHP с помощью phpinfo()

Самый надежный способ узнать, какая версия PHP используется для этого конкретного веб-сайта, — использовать phpinfo() , которая выводит различную информацию о сервере PHP, включая его версию.

В корневой каталог документов веб-сайта загрузите следующий файл PHP с помощью клиента FTP или SFTP :

Откройте ваш браузер, перейдите на yourdoman.com/phpinfo.php , и версия PHP-сервера отобразится на вашем экране:

Как только вы узнаете, какая у вас версия PHP, удалите файл или ограничьте к нему доступ. Предоставление публичного доступа к вашей конфигурации PHP может создать угрозу безопасности вашего приложения.

Есть еще одна функция, с помощью которой вы можете узнать версию PHP. В отличие от phpinfo() , phpversion() печатает только версию PHP-сервера.

php echo 'PHP version: ' . phpversion(); 

Проверка версии PHP из командной строки

Если у вас есть SSH-доступ к серверу, вы можете использовать двоичный файл PHP CLI для определения версии вашего PHP.

Чтобы получить версию сервера, вызовите двоичный файл php с помощью параметра —version или -v :

Команда выведет информацию о версии PHP и завершит работу. В этом примере версия PHP-сервера 7.3.11 :

PHP 7.3.11-1~deb10u1 (cli) (built: Oct 26 2019 14:14:18) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.11-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies 

Если на сервере установлено несколько версий PHP, при запуске команды php будет показана версия интерфейса командной строки PHP по умолчанию, которая может не совпадать с версией PHP, используемой на веб-сайте.

Выводы

Определение версии PHP-сервера — относительно простая задача.

В этом руководстве мы показали несколько различных вариантов того, как найти версию PHP, на которой в настоящее время работает ваш сервер.

Не стесняйтесь оставлять комментарии, если у вас есть вопросы.

Источник

phpversion

Returns a string containing the version of the currently running PHP parser or extension.

Parameters

An optional extension name.

Return Values

Returns the current PHP version as a string . If a string argument is provided for extension parameter, phpversion() returns the version of that extension, or false if there is no version information associated or the extension isn’t enabled.

Changelog

Examples

Example #1 phpversion() example

// prints e.g. ‘Current PHP version: 4.1.1’
echo ‘Current PHP version: ‘ . phpversion ();

// prints e.g. ‘2.0’ or nothing if the extension isn’t enabled
echo phpversion ( ‘tidy’ );
?>

Example #2 PHP_VERSION_ID example and usage

// PHP_VERSION_ID is available as of PHP 5.2.7, if our
// version is lower than that, then emulate it
if (! defined ( ‘PHP_VERSION_ID’ )) $version = explode ( ‘.’ , PHP_VERSION );

define ( ‘PHP_VERSION_ID’ , ( $version [ 0 ] * 10000 + $version [ 1 ] * 100 + $version [ 2 ]));
>

// PHP_VERSION_ID is defined as a number, where the higher the number
// is, the newer a PHP version is used. It’s defined as used in the above
// expression:
//
// $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
//
// Now with PHP_VERSION_ID we can check for features this PHP version
// may have, this doesn’t require to use version_compare() everytime
// you check if the current PHP version may not support a feature.
//
// For example, we may here define the PHP_VERSION_* constants thats
// not available in versions prior to 5.2.7

if ( PHP_VERSION_ID < 50207 ) define ( 'PHP_MAJOR_VERSION' , $version [ 0 ]);
define ( ‘PHP_MINOR_VERSION’ , $version [ 1 ]);
define ( ‘PHP_RELEASE_VERSION’ , $version [ 2 ]);

Notes

Note:

This information is also available in the predefined constant PHP_VERSION . More versioning information is available using the PHP_VERSION_* constants.

See Also

  • PHP_VERSION constants
  • version_compare() — Compares two «PHP-standardized» version number strings
  • phpinfo() — Outputs information about PHP’s configuration
  • phpcredits() — Prints out the credits for PHP
  • zend_version() — Gets the version of the current Zend engine

Источник

Оцените статью
Adblock
detector