How to Check PHP Version

October 31, 2024

Introduction

Hosting providers are traditionally slow to adopt new PHP versions on their servers. Consequently, multiple different PHP versions can exist on the server 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 on a local machine, server, or WordPress website.

How to check PHP version - a tutorial.

Prerequisites

Check PHP Version by Running PHP Code

The simplest method to determine the PHP version on your website is to execute a PHP file with a code that prints the program version. Follow the steps in the sections below.

Step 1: Create PHP File

To determine the PHP version on your website, start by creating a PHP file with code that outputs the version information:

1. Open a text editor like gedit or Notepad.

2. Paste one of the following code snippets depending on the amount of information you need:

  • To obtain only the PHP version, use the following code:
<?php
echo 'PHP version: ' . phpversion();
  • For more details on your PHP configuration, such as system information, build date, server API, configuration file information, etc., create a file containing the phpinfo() function:
<?php 
phpinfo();

Note: While phpinfo() is useful for debugging, the page includes 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, use the following code:
<?php 
foreach (get_loaded_extensions() as $i => $ext)
{
   echo $ext .' => '. phpversion($ext). '<br/>';
}

3. Save the file as phpinfo.php or any other name.

Step 2: Upload the PHP File

Upload the PHP file to your website's document root directory. Use an FTP client of your choice or another method to upload the file.

Step 3: Check PHP Version

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, enter:

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.

Check PHP Version Using Command Line (Windows, Linux, and macOS)

This section outlines the steps for checking your PHP version using the command line in Windows, Linux, and macOS. Skip to the part applicable to your operating system.

Check PHP Version on Windows

Follow the steps below to check your PHP version on a Windows system:

1. Open the Command Prompt or Windows PowerShell.

2. Run the following command to check the PHP version:

php -v
Checking the PHP version in Windows.

The command outputs the PHP version installed on your computer. If you get an error that php is not recognized as internal or external command even though you have PHP installed, add PHP to the PATH environment variable.

How to Add PHP to the PATH Environment Variable

To fix the PHP is not recognized error on Windows:

1. Press the Windows key and type Environment variables. Press Enter to open the System Properties Window.

Searching for Environment variables settings in Windows.

2. In System Properties, click the Environment Variables... button.

System Properties window.

3. Find the System variables section and scroll down the list until you find the PATH variable. Select the PATH variable and click Edit:

Editing the path environment variable in Windows.

4. Click the New button and enter the path to your PHP installation path. Click OK in every window to save and apply the changes.

Adding a new environment variable to path in Windows.

5. Open the Command Prompt again and check the PHP version:

php -v

Check PHP Version on Linux

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. In the terminal, run the following command:

php -v
Checking PHP version using the command line in Ubuntu.

The command outputs the PHP version number, build date, and copyright information.

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 hosted websites.

Check PHP Version on macOS

To check the PHP version on macOS using the terminal, follow these steps:

1. Press Command + Space and type Terminal to open the Terminal app or go to Applications > Utilities > Terminal.

2. Run the following command:

php -v
Checking PHP version in macOS.

The terminal outputs the PHP version currently installed on your system.

How to Check PHP Version if You Are Using WordPress

PHP plays a fundamental role in every WordPress website's functionality and performance. It is used to write WordPress code, themes, plugins, and helps deliver dynamic web pages to visitors.

New PHP versions usually include various upgrades, often related to performance, compatibility, and security. Thus, it is important to know which PHP version your WordPress site is using.

This section shows how you can check the PHP version in WordPress.

Important: Before making any changes, backup your website. Backups allow you to revert changes in case something goes wrong. If you do not have a backup solution, use one of the many available free WordPress backup plugins.

Check PHP Version via WordPress Site Health Tool

The easiest way to check your PHP version in WordPress is from the dashboard. Follow the steps below:

1. Log in to your WordPress account and navigate to Tools > Site Health.

Accessing Site Health in WordPress.

2. The Site Health page shows the health status of your WordPress site and any available updates or recommended improvements. It also states if you are using an outdated PHP version. Click the Info tab:

Open website info in WordPress.

3. Scroll down the list and expand the Server section. This section provides a lot of details regarding your server setup, including your PHP version:

Checking PHP version in WordPress dashboard.

Check PHP Version via a WordPress Plugin

Follow the steps below to check the PHP version in WordPress using a plugin:

1. Navigate to your WordPress site and log in with an admin account.

2. From the Dashboard, select Plugins > Add New to add a system information plugin.

Adding a new plugin to WordPress.

3. In the search bar, type PHP version or similar keywords to get a list of plugins compatible with your WordPress version.

4. Choose and install a plugin from the list, for example, Display PHP Version or PHP Compatibility Checker.

PHP version plugin search in WordPress.

5. Once you install the plugin, click Activate. Depending on the plugin you install, the PHP version might be displayed in different locations within the WordPress dashboard.

Popular plugins usually show the PHP version in:

  • The At a Glance section on the Dashboard.
  • The WP-ServerInfo section.
  • The Site Health section / Info tab.
  • A new menu item, such as Query Monitor.

For this tutorial, we used Display PHP Version, which shows the PHP version in the At a Glance section on the Dashboard:

Checking PHP version in WordPress using a plugin.

Conclusion

This article showed the common ways to check the PHP version on your server, local machine, or WordPress website. The methods covered in this tutorial include running PHP code, using the command-line interface, or checking the version via plugins or WP dashboard.

Next, check out how to make a redirect in PHP or see the 4 different types of errors in PHP.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How To Install and Use PHP Composer on Ubuntu
September 5, 2024

Use Composer to specify a set of libraries for a specific project...
Read more
4 Different Types of Errors in PHP
April 4, 2024

A PHP Error occurs when something is wrong in the PHP code. An error can be simple as a missing semicolon...
Read more
PHP Error Reporting: How to Enable & Display All Errors / Warnings
April 4, 2024

If a script is not written correctly, or if something unusual happens, PHP can generate an error message....
Read more
How To Install PHP 7, 7.2 & 7.3 On CentOS 7
May 24, 2019

PHP is a programming language that's often used to automate server tasks. It's part of the LAMP...
Read more