Php get version linux

How to Check PHP Version Windows Xampp, Linux Ubuntu

Check php version xampp windows, linux ubuntu, mac; In this tutorial, you will learn how to check php in Windows, Linux, and Mac using command prompt or cmd and PHP script.

PHP is a popular programming language used for web development. If you are a developer or a system administrator, it’s important to know which version of PHP is installed on your system. In this article, we’ll show you how to check the PHP version using different methods.

How to Check PHP Version Windows Xampp, Linux Ubuntu

  • Method 1: Using the Command Line Interface
  • Method 2: Using a PHP Script
  • Method 3: Using a PHP Framework

Method 1: Using the Command Line Interface

  1. Open the command prompt (Windows) or terminal (Linux/Mac).
  2. Type the following command and press Enter:
    • php -v
  3. The PHP version installed on your system will be displayed in the output. Example output:
    • PHP 7.4.23 (cli) (built: Sep 2 2021 16:11:53) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

Method 2: Using a PHP Script

You can also check the PHP version by creating a PHP script and running it on your web server. Follow these steps:

  1. Create a new file named “phpinfo.php” in the document root directory of your web server.
  2. Open the file in a text editor and add the following code:
    • Save the file and open it in a web browser. For example, if your web server is running on localhost, you can access the file by typing “http://localhost/phpinfo.php” in the browser address bar.
    • The PHP version installed on your system will be displayed on the top of the page.
      • PHP Version 7.4.23
      • System Windows NT LAPTOP-123 10.0 build 19042 (Windows 10) AMD64
      • Build Date Sep 2 2021 16:12:01

Method 3: Using a PHP Framework

  1. Open the terminal and navigate to the root directory of your PHP project.
  2. Type the following command and press Enter:
    • php artisan —version
  3. The PHP version used by the framework will be displayed in the output.Example output (for Laravel):
    • Laravel Framework 8.55.0 PHP 7.4.23 (cli) (built: Sep 2 2021 16:11:53) ( NTS ) .

Conclusion

In this tutorial, we have shown you how to check the PHP version on your system using different methods. By knowing the PHP version, you can ensure that your web applications are compatible with the PHP version installed on your server.

Источник

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

Источник

Как узнать версию php

Язык программирования PHP — один из самых популярных языков для создания веб-сайтов и различных веб-приложений. Когда вы устанавливаете какую-либо систему управления контентом, например, WordPress, Joomla, ModX или что-либо другое, обычно у них есть требование к минимальной версии PHP.

Поэтому часто бывает необходимо узнать версию PHP, установленную на сервере. Это можно сделать несколькими способами, но в обоих случаях у вас должен быть доступ к серверу.

Просмотр версии в терминале

Для того чтобы узнать установленную версию PHP в терминале надо иметь SSH доступ к серверу. Подключитесь к серверу по SSH и выполните такую команду:

Утилита покажет информацию о сборке PHP, а также её версию. Однако, такой способ позволяет узнать версию используемую по умолчанию в консоли или php-cli. Если вы используете какую-либо панель управления сервером, то обычно панели устанавливают свои версии PHP отдельно в папку /opt. Чтобы посмотреть версию PHP установленной панелью надо использовать браузер.

Просмотр версии в браузере

Подключитесь по FTP или по SSH к серверу и перейдите в корневой каталог вашего сайта. Там создайте небольшой скрипт со следующим содержимым:

Затем откройте ваш сайт и допишите в адресной строке адрес этого файла:

Если всё сделано верно, будет выведена огромная таблица с информацией про PHP и установленные расширения, а в самом верху страницы будет версия PHP.

Если вы не хотите выводить всю таблицу с информацией о PHP, то можно вывести только версию с помощью функции phpversion. Например:

Тогда, в результате вы получите такую страницу:

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

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

How to check the PHP version on Linux

There are several possibilities to check and validate PHP version on Linux.

1. Open a bash shell terminal and use the command “php –version” or “php -v” to get the version of PHP installed on the system.

# php --version PHP 5.4.16 (cli) (built: Mar 7 2018 13:34:47) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
# php -v PHP 5.4.16 (cli) (built: Mar 7 2018 13:34:47) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

As you can see from both the command output above, the system has PHP 5.4.16 installed.

2. You can also check for the package versions installed on the system to get the PHP version.
On RedHat Based Distributions :

# rpm -qa | grep php php-common-5.4.16-43.el7_4.1.x86_64 php-pdo-5.4.16-43.el7_4.1.x86_64 php-mysql-5.4.16-43.el7_4.1.x86_64 php-mbstring-5.4.16-43.el7_4.1.x86_64 php-cli-5.4.16-43.el7_4.1.x86_64 php-gd-5.4.16-43.el7_4.1.x86_64 php-5.4.16-43.el7_4.1.x86_64

On debian based distributions :

# apt list --installed | grep php

3. Let’s create a PHP file with content as shown below. The phpinfo() function outputs a great deal of information about the state of the current PHP environment, including loaded extensions, compilation options, version, server information, and so on.

# echo "<?php phpinfo();?>" > /var/www/html/phpinfo.php

4. Now, considering that Apache is installed and working, open a browser and test PHP using address as follow:

how to check PHP version in 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.

Источник

Читайте также:  Load average linux нормальное значение
Оцените статью
Adblock
detector