- Checking what PHP version I’m running on Linux?
- 4 Answers 4
- Check PHP Version Linux
- Conclusion
- About the author
- Omar Farooq
- How to Check PHP Version
- Check PHP Version by Running PHP Code
- Check PHP Version Using the Command Line (Windows, Linux and macOS)
- Fix ‘PHP is not Recognized’ Error on Windows
- Как узнать версию php
- Просмотр версии в терминале
- Просмотр версии в браузере
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 😛?php>
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.
Check PHP Version Linux
While working in the computer science field, you must have heard about some programming languages. One of those languages is “PHP” which can be used in various operating systems. It is used to design and create websites or their pages for a better look and feel. You can call it a server-scripting language as well. All the languages came up with many of the versions i.e., old to new. Thus, we have decided to see how we can find out the version of installed PHP on the Ubuntu 20.04 Linux operating system using simple version commands on the shell.
So, let’s just get started by the login from Ubuntu 20.04 system. After login, try to open your Ubuntu 20.04 terminal console application from its application area using the search activity bar. Write “terminal” and tap Enter. An application named “terminal” will be shown. Click on it to open it. If you want to avoid this complex and long procedure, just use the “Ctrl+Alt+T” shortcut. Let’s get started with the newly launched terminal shell and the system update in it.
For the system update, we need to make use of the “apt” package in the command along with the “update” keyword. This command must be executed with the sudo rights to avoid any issue. Within a few minutes, all the updates will be installed and applied to your Linux system. The output is attached in the appended screenshot.
Now, the system update has been done, we need to upgrade the system as well. For that, you must use the same “apt” package command with sudo rights to upgrade your system. Use the keyword “upgrade” to do so. Within a few minutes, your system will be upgraded as well. The output is attached in the appended screenshot.
Let’s start with the checking of the PHP installed version on our system using the simple and most used “version” command. For this, you have to use the word “PHP” with the flag “—version” and execute it as a single command by pressing the Enter key. On execution, we have got the below-shown output. The output is showing that the PHP has no version installed on our system and it is suggesting a command to install the newest version available for our system. So, it is clear that we must have some version of the PHP language already configured at our end. The output is attached in the appended screenshot.
We can also use the same version command with a shortcut. For this, we don’t need to use the “—version” full word flag. We can utilize the simple “-v” flag to do so as shown below.
So, before checking the installed version on our system with the command, we have to install it for sure. For installation, we require sudo rights to be used in the command. Within the query area, you have to use the “apt” package to install the “PHP” language. Also, if you don’t know any PHP version, just use the word “PHP” after the “install” keyword in the command beneath. It will start getting the necessary information regarding this installation. The output is attached in the appended screenshot.
It will show you a list in this command output that is going to be installed on our Ubuntu 20.04 system. This list contains many of the server packages, some utilities, and necessary libraries to make it usable on our Linux system.
After the above listing, the system will pause the installation process and let you know about the memory space it is going to be taken after the installation i.e., 25.9 MB. If you are willing to give such space to the PHP language on your system, then simply click “y” from the keyword and hit the key “Enter” to continue the installation process as we did beneath.
Right after your click on the Enter key, the system will start executing all the listed libraries, packages, and utilities on the Linux system. The below-shown progress will be shown and different links will be created to add PHP within the system.
Within no more than 10 minutes, the newest PHP version will be installed and successfully configured on our system. The complete output of the last processing lines is shown below.
After the PHP installation, we will take a look at its installed version through the version command with i.e., “-v” flag as below. You will see that it will display an installed version of PHP within your system i.e., 7.4.3. You will also get other information regarding the installation date and time, and the owner of PHP. The output is attached in the appended screenshot.
The same thing can be achieved by the “—version” flag in the “PHP” command as beneath. The output is attached in the appended screenshot.
These were the simplest and most used commands to get to know about the PHP version in the Ubuntu 20.04 CLI. There are other commands too. For example, we can also use the keyword “PHP” with the flag “-i” to get the PHP version and other information regarding it. After running it, the “phpinfo()” function got executed and displayed the version of PHP along with extra info. The output is attached in the appended screenshot.
You can also check out all the other utilities of PHP installed within your system along with it using the “dpkg” list command with the “—list” flag. You have to use the “grep” keyword with the “PHP” keyword. The output is attached in the appended screenshot.
Conclusion
To sum up, this was all about the checking of the PHP installed version on our Ubuntu 20.04 system. To achieve this, you need to have a mounted version of PHP on your system. If not, you have to go through the above article from start to end and you will understand everything. The details provided in this article were all quite simple and we must say will be easy to do.
About the author
Omar Farooq
Hello Readers, I am Omar and I have been writing technical articles from last decade. You can check out my writing pieces.
How to Check PHP Version
Hosting providers are traditionally slow to adopt new PHP versions on their servers. The consequence of this is that many different PHP versions exist on the web at the same time.
If you are implementing new features, installing a new PHP-based app, or trying to locate a bug on your website, it is important to know which PHP version your web server is running.
In this tutorial, you will learn how to check your PHP version by running PHP code on your server or using the command line.
Check PHP Version by Running PHP Code
The simplest method to determine the PHP version running on your website is executing a PHP file that contains the following code:
Create the file using a text editor like gedit or Notepad, and upload it to your website’s document root directory.
Then open a web browser and type the full address of the file in the address bar. For example, if you uploaded a file titled phpinfo.php to the example.com root directory, you would go to:
http://www.example.com/phpinfo.php
The code above displays the PHP version without any further details, like in the output below:
If you need more details on your PHP configuration, such as system information, build date, server API, configuration file information, etc., upload a file containing the phpinfo() function:
When visited in the browser, this file shows the PHP version in the upper-left corner, followed by configuration data:
Note: While phpinfo() is useful for debugging, the page features sensitive information about your system. Remove the file from the server once you finish using it.
For a list containing all the loaded PHP extensions and their versions, upload a file with the following code:
The output shows each extension in a separate line, including the version of the PHP core:
Check PHP Version Using the Command Line (Windows, Linux and macOS)
If you have permission to SSH into the remote server, use the command line to check the installed PHP version. This method is also useful for checking the PHP version installed locally.
2. The php -v command works on Linux, macOS, Windows, and other supported systems. Its output contains the PHP version number, build date, and copyright information.
Note: If there is more than one PHP version installed on the server, the php -v command shows the default command-line interface (CLI) version. This version is not necessarily the one that runs on the hosted websites.
Fix ‘PHP is not Recognized’ Error on Windows
On Windows, the PHP path is sometimes not recognized by the system, so the php -v command outputs the ‘php is not recognized’ error.
To solve this problem, set the PATH environment variable first.
1. Type the following command, replacing [location] with the path to your PHP installation.
2. Typing php -v now shows the PHP version installed on your Windows system.
Note: Check out our other PHP guides such as How to Make a Redirect in PHP or 4 Different Types of Errors in PHP.
This article aimed to explain the common ways to check the PHP version on your server or local machine. The methods covered in this tutorial include running PHP code and using the command-line interface.
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
A PHP Error occurs when something is wrong in the PHP code. An error can be simple as a missing semicolon.
If a script is not written correctly, or if something unusual happens, PHP can generate an error message.
Как узнать версию 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.