Oct 9, 2023 3 min read

How to Check the PHP Version

Check the PHP Version with our step-by-step tutorial. PHP is a popular server-side programming language. PHP creates dynamic web pages.

Check the PHP Version
Table of Contents

Introduction

Before we begin talking about how to check the PHP version, let's briefly understand – What is PHP?

PHP is a popular server-side programming language. It is used to create dynamic and interactive web pages by embedding PHP code within HTML code. PHP code runs on the server, generating HTML output that is then sent to the user's browser.

Knowing which version of PHP is installed on your server may be vital in particular circumstances because there are some significant variations between them. For example, if you are upgrading an application or installing a new one that requires a specific PHP version, you must first find out the version of your PHP server.

In this tutorial, you will use check the PHP version. We will also address a few FAQs on how to check the PHP version.

Checking the PHP version with phpinfo()

Use the phpinfo() function, which prints various details about the PHP server, including its version, to determine what version of PHP is in use for that particular website.

Using an FTP or SFTP client, upload the following PHP file to the document root directory of your website:

<?php

phpinfo();

When you open a browser and navigate to yourdoman.com/phpinfo.php, the PHP server's version will be displayed on your screen.

PHP server's version

Once you know what version of PHP you are running, either delete the file or put access restrictions on it. Revealing your PHP configuration to the public can put your application's security at risk.

You can also use another function to determine the PHP version. Unlike phpinfo(), the phpversion() function simply returns the PHP server's version.

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

Checking the PHP version from the Command Line

You can check the version of your PHP by using the PHP CLI binary if you have SSH access to the server.

Invoke the php binary with the --version or -v option to obtain the server version:

php --version

After printing out the PHP version information, the command will terminate. The PHP server version used in this example is 7.3.11:

Output
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

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

FAQs to Check the PHP Version

How do I create a PHP script to check the PHP version? 

Create a new file with a .php extension, insert the phpinfo() function into the file, save it, and then access it through a web browser.

Can I check the PHP version from the command line? 

Yes, you can run the php -v command in the command line to check the PHP version installed on your system.

What if I don't have access to server configurations? 

You can ask your hosting provider to provide you with the PHP version information or use a third-party tool to determine the PHP version of a website.

Is it important to know the PHP version when developing or running a website? 

Yes, knowing the PHP version is crucial for compatibility and security reasons, as different PHP versions may have varying features and requirements.

Can I upgrade my PHP version to a newer release? 

Yes, upgrading the PHP version depends on your hosting environment or server configuration. Contact your hosting provider to inquire about upgrading options.

How frequently should I check and update my PHP version? 

It is recommended to check for PHP updates regularly, and update to the latest stable version to ensure security fixes, performance improvements, and compatibility with newer technologies.

Conclusion

Identifying the PHP server version is a simple procedure.

In this tutorial, we have covered several methods for determining the PHP version your server is currently using.

If you have any suggestions or queries, kindly leave them in the comments section.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.