Linux what version of php

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

Источник

How to Check Which PHP Version is Installed on Linux: A Comprehensive Guide

Learn how to check the PHP version installed on Linux with the «version» command, phpinfo(), executing a PHP file with specific code, and more. Ensure compatibility and performance for your website with this comprehensive guide.

  • Using the “version” command
  • Using phpinfo()
  • Executing a PHP file with specific code
  • Checking loaded extensions with PHP
  • Selecting the correct PHP version for a website
  • Other quick code examples for checking PHP version installed on Linux
  • Conclusion
  • How to check the PHP version in Linux?
  • How do I tell what version of PHP is installed?
  • How do I know what PHP extensions are installed Linux?
  • Where is PHP installed Linux?
Читайте также:  Компас 3d viewer linux

PHP is a popular scripting language used for web development, and it’s essential to know which version is installed on Linux to ensure compatibility and performance. There are several methods to check the PHP version, and in this blog post, we will cover them all. We’ll also highlight the importance of using the correct version and provide some helpful tips for troubleshooting and updating.

Using the “version” command

The “version” command is a quick and easy way to check the PHP version installed on Linux. Simply open the command line terminal and type “php -v”. The output will show the version number, as well as other useful information such as the PHP build date and copyright.

Using phpinfo()

Another method to check the PHP version on Linux is to use the phpinfo() function. This function generates a detailed report of all PHP settings and configurations, including the version number. To use phpinfo(), create a PHP file with the following code:

Save the file as “phpinfo.php” and upload it to the web server. Then, open the file in a web browser, and the PHP version will be displayed at the top of the page.

Executing a PHP file with specific code

Running a simple PHP file can also provide information about the PHP version installed on Linux. Create a PHP file with the following code:

Save the file as “version.php” and upload it to the web server. Then, open the file in a web browser, and the PHP version will be displayed on the page.

Checking loaded extensions with PHP

To check all loaded extensions by PHP, use the command php -r «print_r(get_loaded_extensions());» . This command will display a list of all PHP extensions that are currently loaded on the server.

php -r "print_r(get_loaded_extensions());" 

Selecting the correct PHP version for a website

Multiple versions of PHP can be installed on Linux, and it’s important to ensure the correct version is being used for a specific website. The Select PHP Version menu or PHPinfo() function can be used to check the PHP version set for the account. To change the PHP version, simply select the desired version and click “Set as current”.

Select PHP Version menu

Other quick code examples for checking PHP version installed on Linux

In Php case in point, check the php version in ubuntu code example

In Php case in point, checking PHP version code sample

In Php , for instance, how to check php version in php code example

In Php , for example, php version command linux code example

# 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

In Php case in point, php version command linux code example

# 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

In Php , for example, check php version code example

Читайте также:  Ubuntu linux руководство пользователя

Conclusion

Checking the PHP version installed on Linux is essential for web developers to ensure compatibility and performance. There are several methods to check the PHP version, including the “version” command, phpinfo(), and executing a PHP file with specific code. It’s important to use the correct version for each website, and tools like Select PHP Version can help with this. Keeping PHP updated is also crucial for security and performance improvements.

Frequently Asked Questions — FAQs

What is the importance of checking the PHP version installed on Linux?

It’s important to check the PHP version installed on Linux to ensure compatibility and performance for your website. Different PHP versions may have different features and requirements, and using the correct version can prevent errors and security issues.

How do I check the PHP version using the «version» command on Linux?

Simply open the command line terminal and type «php -v». The output will show the version number, as well as other useful information such as the PHP build date and copyright.

What is the phpinfo() function, and how can I use it to check the PHP version on Linux?

The phpinfo() function generates a detailed report of all PHP settings and configurations, including the version number. To use phpinfo(), create a PHP file with the following code: . Save the file as «phpinfo.php» and upload it to the web server. Then, open the file in a web browser, and the PHP version will be displayed at the top of the page.

Can I check the loaded extensions of PHP on Linux?

Yes, you can use the command «php -r «print_r(get_loaded_extensions()));» to display a list of all PHP extensions that are currently loaded on the server.

How do I select the correct PHP version for my website on Linux?

Multiple versions of PHP can be installed on Linux, and it’s important to ensure the correct version is being used for a specific website. The Select PHP Version menu or PHPinfo() function can be used to check the PHP version set for the account. To change the PHP version, simply select the desired version and click «Set as current».

Why is it important to keep PHP updated on Linux?

Keeping PHP updated is crucial for security and performance improvements. Newer versions of PHP may have security patches and bug fixes that can prevent vulnerabilities and improve performance.

Источник

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

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

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

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

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

Читайте также:  Brave browser linux mint 20

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

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

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

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

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

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

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

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

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

Источник

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.

Источник

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