How to Check PHP Version in Linux Server ?

Source: Internet
Author: User
Keywords check php version linux how to check php version in linux check php version in linux
This article introduces how to check the PHP Version in Linux server: use phpinfo(), phpversion() and check the PHP version from the command line.

Preface
PHP is one of the most commonly used server-side programming languages. There are some important differences between PHP versions, so in some cases you may need to know which version is running on the server.

For example, if you want to upgrade an application or install a new application that requires a specific PHP version, you need to find out the version of the PHP server.

In this article, we will show you how to check the PHP version that the server is running. To install PHP, please refer to the method of installing PHP 7.3/7.2/7.1/7.0 and PHP 7 modules in Ubuntu 18.04/16.04.

Use phpinfo() or phpversion() to check the PHP version

The most reliable way to find out the PHP version used for a particular website is to use the phpinfo() function, which prints various information about the PHP server, including its version.

In the root directory of your website document, use an FTP or SFTP client to upload the following PHP file content (the file name is set as phpinfo.php):

<?php

phpinfo();

Open the browser, go to yourdoman.com/phpinfo.php, and the version of the PHP server will be displayed on the screen:
img
How to check PHP Version in Linux server

Once you find your version of PHP, you can delete the file or restrict access to it, because disclosing your PHP configuration to the public may pose a security risk to your application.

At the same time, you can also use another function to find the PHP version. Unlike phpinfo(), the phpversion() function only outputs the version of the PHP server, and the file name is phpversion.php:

<?php

echo'PHP version: '. phpversion();


Check the 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 PHP.

To get the server version, use the --version or -v option to call the php binary file and run the following command:

php --version

This command will output information about the PHP version and exit. In this example, the version of the PHP server is 7.3.11. The specific output information is as follows:

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 multiple PHP versions are installed on the server, when running the php command, it will display the version of the default PHP CLI, which may not be the version of PHP used on the website.

in conclusion
In this article, we introduced how to find the PHP version currently running on a Linux server, and choose one to achieve the goal. At the same time, determining the version of the PHP server is a relatively easy task.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.