Checking php version on server

How to Check the PHP Version

PHP is one of the most used server-side programming languages. There are some important differences between PHP versions, so knowing which version is running on your server might be necessary in some situations.

For example, if you are upgrading your application or installing a new one that requires a specific PHP version before starting with the installation, you’ll need to find out the version of your PHP server.

In this article, we’ll show you how to check what version of PHP your server is running.

Checking PHP version with phpinfo() #

The most reliable way of finding out what version of PHP is used for that specific website is to use the phpinfo() function, which prints various information about the PHP server, including its version.

In your website document root directory upload the following PHP file using a FTP or SFTP client:

Open your browser, go to yourdoman.com/phpinfo.php ,and the version of the PHP server will be displayed on your screen:

Once you find out what PHP version you have, either remove the file or restrict the access to it. Exposing your PHP configuration to the public can pose a security risk to your application.

There is also another function that you can use to find out the PHP version. Unlike phpinfo() , the phpversion() function prints only the version of the PHP server.

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

Checking PHP version from the Command Line #

If you have SSH access to the server, you can use the PHP CLI binary to determine the version of your PHP.

To get the server version, invoke the php binary using the —version or -v option:

The command will output information about the PHP version and exit. In this example the version of the PHP server is 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 

If there are multiple PHP versions installed on the server, when you run the php command, it will show the version of the default PHP CLI, which may not be the version of PHP used on the website.

Conclusion #

Determining the version of the PHP server is a relatively easy task.

In this guide, we have shown several different options about how to find the version of PHP that your server is currently running.

Feel free to leave a comment if you have any questions.

Источник

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:

2. Save the file as «version.php». Make sure, that the extension is .php (not .txt)

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:

  • php Version
  • Build Date
  • Configuration
  • .
  • Installed php Modules
  • php Variables

Multiple php Versions on the same Server

Some web server are pre-configured to run e.g. php5 and php8 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.php5 // for php5 (old) scripts
somescript.php8 // for php8 scripts
somescript.php // for the default php version

The default php version depends either on your php configuration or on your hosting package.

Disclaimer: The information on this page is provided «as is» without warranty of any kind. Further, Arclab Software OHG does not warrant, guarantee, or make any representations regarding the use, or the results of use, in terms of correctness, accuracy, reliability, currentness, or otherwise. See: License Agreement

  • ©1997-2023 Arclab®. All other trademarks and brand names are the property of their respective owners.
  • info_outline
  • fingerprint Cookies & Privacy

Источник

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

Источник

Читайте также:  Html href with image and text
Оцените статью