How to Check PHP Version

Introduction

If you are a web developer, it is important to know what version of PHP you are running on your server. Knowing the version of PHP you are running can help you troubleshoot any issues you may be having with your website, as well as ensure that you are running the most up-to-date version of PHP. In this article, we will discuss how to check the version of PHP you are running on your server.

How to Check PHP Version

1. Log into your web hosting control panel.

2. Look for the section labeled “Software and Services” or “Software/Services”.

3. Click on the “PHP Configuration” or “PHP Info” link.

4. Look for the “PHP Version” line. The number listed is the version of PHP installed on your server.
[ad_1]

Introduction

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.

How to Check PHP Version

Prerequisites

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:

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

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:

Checking PHP version by using the phpversion command

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:

<?php 
phpinfo();

When visited in the browser, this file shows the PHP version in the upper-left corner, followed by configuration data:

Checking PHP version by using the phpinfo command

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:

<?php 
foreach (get_loaded_extensions() as $i => $ext)
{
   echo $ext .' => '. phpversion($ext). '<br/>';
}

The output shows each extension in a separate line, including the version of the PHP core:

Checking versions of loaded PHP extensions

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:

php -v

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.

Checking PHP version by using the command line in Ubuntu

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.

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.

set PATH=%PATH%;[location]
Setting the PATH variable for php.exe in Windows

2. Typing php -v now shows the PHP version installed on your Windows system.

Conclusion

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.

[ad_2]

How to Check PHP Version

If you are a web developer, it is important to know what version of PHP your server is running. Knowing the version of PHP can help you troubleshoot any issues you may be having with your website or web application. It can also help you determine if you need to upgrade your server to a newer version of PHP.

Checking PHP Version on a Linux Server

If you are running a Linux server, you can check the version of PHP by running the following command in the terminal:

php -v

This will output the version of PHP that is installed on your server. For example, if the output is “PHP 5.6.30”, then you know that your server is running PHP version 5.6.30.

Checking PHP Version on a Windows Server

If you are running a Windows server, you can check the version of PHP by running the following command in the command prompt:

php -v

This will output the version of PHP that is installed on your server. For example, if the output is “PHP 5.6.30”, then you know that your server is running PHP version 5.6.30.

Checking PHP Version in a Web Browser

If you are running a web server, you can check the version of PHP by creating a simple PHP file and accessing it in a web browser. To do this, create a file called “phpinfo.php” and add the following code to it:

<?php
  phpinfo();
?>

Save the file and upload it to your web server. Then, access the file in a web browser. This will output a page with information about your server, including the version of PHP that is installed. For example, if the output is “PHP Version 5.6.30”, then you know that your server is running PHP version 5.6.30.

Conclusion

In this article, we have discussed how to check the version of PHP that is installed on your server. We have discussed how to check the version of PHP on a Linux server, a Windows server, and in a web browser. Knowing the version of PHP can help you troubleshoot any issues you may be having with your website or web application.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00