How to check php version
How to check php version
How to Check PHP Version
Home » SysAdmin » 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:
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.
1. Type the PHP command:
Fix ‘PHP is not Recognized’ Error on Windows
To solve this problem, set the PATH environment variable first.
1. Type the following command, replacing [location] with the path to your PHP installation.
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.
How to Check the PHP Version
Here are some quick tips on how to check the PHP version on your computer or server.
There are several reasons why you want to check the version of PHP which is installed on your server. For example, you might want to install PHP-based software and to check if the software requirements match the PHP version installed on your server. Or you might be a developer who wants to use a feature which is only available in specific versions of PHP.
There are a lot of different PHP versions, and they have some noticeable differences among them. With every new PHP version, new features are added and others are deprecated, so it’s always good to know the PHP version you’re using.
There are a few different ways to check the PHP version. Mainly, if you have SSH access to your server, you can use the command-line interface to check it. On the other hand, if you don’t have terminal access, I’ll show you how to check the PHP version using the phpinfo function.
Check the PHP Version by Using the Terminal
In this section, we’ll discuss how you could check the PHP version by using the command-line interface (CLI) in a terminal.
Check the PHP Version on Unix, Linux, and macOS
For *nix-based systems—Linux, Unix, and macOS—it just takes a single command to check the PHP version. Go ahead and run the following in your terminal.
You should see an output like the following:
As you can see, this gives you comprehensive information about the PHP version which is installed on your server. In the above output, the 7.2.24 version of PHP is installed on the server.
Check the PHP Version on Windows
For Windows users, the same command is used to check the PHP version. But you might get an error if you don’t set the PATH environment variable first. You can do that by running the set PATH command. Run the following commands, and make sure that you replace the
So that was a brief introduction to the CLI option to check the PHP version. In the next section, we’ll discuss how you could check your PHP version with the phpinfo function.
Check the PHP Version by Using the phpinfo Function
You can also use the phpinfo function, which prints detailed information about the PHP software on your server and its configuration.
This option is especially useful when you don’t have SSH access to the server where your site is hosted. If you want to use this option to check the PHP version on the remote server, all you need is the ability to upload a PHP file, for example with FTP or a web-based portal.
Create a file called php_version_check.php file with the following contents.
Upload this file to the root directory of your site. Once you’ve done that, you should be able to access it at the http://example.com/php_version_check.php URL (replacing example.com with your own domain name). It should produce output like that shown in the following screenshot.
phpinfo Security Risks
As you can see, the PHP version is displayed right on the top of the page. Also, it displays a lot of other important configuration information as well. This information can be very useful if you are setting up or debugging a PHP installation. It can also be very useful for hackers, allowing them to pinpoint specific vulnerabilities in your system!
That’s why I strongly recommend you remove this file from the server once you’ve finished checking the PHP version.
Learn PHP With a Free Online Course
If you want to learn PHP, check out our free online course on PHP fundamentals!
In this course, you’ll learn the fundamentals of PHP programming. You’ll start with the basics, learning how PHP works and writing simple PHP loops and functions. Then you’ll build up to coding classes for simple object-oriented programming (OOP). Along the way, you’ll learn all the most important skills for writing apps for the web: you’ll get a chance to practice responding to GET and POST requests, parsing JSON, authenticating users, and using a MySQL database.
phpinfo
(PHP 4, PHP 5, PHP 7, PHP 8)
phpinfo — Outputs information about PHP’s configuration
Description
Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.
Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system.
phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.
Parameters
The output may be customized by passing one or more of the following constants bitwise values summed together in the optional flags parameter. One can also combine the respective constants or bitwise values together with the bitwise or operator.
Return Values
Returns true on success or false on failure.
Examples
Example #1 phpinfo() Example
// Show all information, defaults to INFO_ALL
phpinfo ();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo ( INFO_MODULES );
Notes
phpinfo() outputs plain text instead of HTML when using the CLI mode.
See Also
User Contributed Notes 20 notes
After reading and trying various functions, I couldn’t find one that correctly parses all the configurations, strips any left-over html tag and converts special characters into UTF8 (e.g. ‘ into ‘), so I created my own by improving on the existing ones:
$phpinfo = array(‘phpinfo’ => array());
// Strip everything after the
Configuration
]*>\s*Configuration.*)
return array();
>
The output looks something like this (note the headers are also included but are prefixed with ‘# ‘, e.g. ‘# Directive’):
Array
(
[phpinfo] => Array
(
[0] => PHP Version 5.6.5
[System] => Darwin Calins-MBP 15.0.0 Darwin Kernel Version 15.0.0: Wed Aug 26 19:41:34 PDT 2015; root:xnu-3247.1.106
Find PHP version on windows command line
18 Answers 18
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
In command prompt type below
Where C:\path\to\php is the folder where your php.exe file is located. After this run
than you will see something like
UPDATE:
If you find that when you restart your computer, this solution will not work anymore:
Set the Path like as following:
Note: Replace your PHP installed path(e.g: C:\Program Files\php ) with the above path ♥.
You just need to find out where is your PHP folder.
PHP 5.6.11 (cli) (built: Jul 9 2015 20:55:40) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
Then go to php folder directory, Suppose your php folder is in xampp folder on your c drive. Your command would then be:
After that, check your version:
This should give the following output:
PHP 7.2.0 (cli) (built: Nov 29 2017 00:17:00) ( ZTS MSVC15 (Visual C++ 2017) x86 ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
I have uploaded a youtube video myself about checking the version of PHP via command prompt in Bangla: https://www.youtube.com/watch?v=zVkhD_tv9ck
Go to c drive and run the command as below
xampp control panel->shell->type php-v you get the version of php of your xampp installed
DB(mariadb/mysql)version type localhost/phpmyadmin in url click enter click on sql type select version(); enter to get the mysql or mariaDb version
It is most likely that php is not in your specified path.
Try to issue the php command with the full path, for example:
Please note, that this is just an example, your php installation might be in a different directory.
For Beginners to anything php, it is usually stored in the C:/ path folder of your PC (My Computer).
and viola there you’ll have the current php version that is installed in your machine
Just create a php file and write the code
and open the file in any browser. It will show the php version installed in your system.
php Version Check
How to Check if php is installed on the Web Server
and how to Detect the php Version using phpinfo()
php is installed on most hosted Linux based web servers, but it’s also available for Windows based web servers.
Check if php is installed on your Web Server
1. Create a text file, e.g. using notepad or any other text editor:
3. Upload the file to the root of your web
4. Open the file in your web browser, e.g. http://www.yourdomain.tld/version.php
5. Delete the file on your web server after you are done. You should be the only one seeing this information!
How to detect the php Version?
Run the phpinfo() script above.
It contains much more information, like:
Arclab® Web Form Builder the HTML form creation software for Windows PC to create email contact forms and php forms with ease. Build HTML forms on your PC and upload the forms to your own web site.
The forms can be integrated into normal HTML or php websites, or in WordPress, Joomla, Drupal or Typo3.
Multiple php Versions on the same Server
Some web server are pre-configured to run e.g. php4 and php5 at the same time, to ensure compatibility with older scripts and CMS systems.
If you web server is configured for multiple php versions, select the php version by using e.g.
somescript.php4 // for php4 (old) scripts
somescript.php5 // for php5 scripts
somescript.php // for the default php version
The default php version depends either on your php configuration or on your hosting package.
©1997-2022 Arclab®. All other trademarks and brand names are the property of their respective owners.