How to Check PHP Version: 2 Easy Ways

check php version

Compatibility is a critical reason why PHP scripts deployed on a server fail and break the deployed applications. 

Developers and admins can avoid most of these issues if they check the current PHP version installed on the server before proceeding with updates and new installations. This simple check guarantees that the developers and admins can avoid compatibility issues for their preferred PHP frameworks and web applications. 

Checking the current PHP version is also a critical server maintenance check because PHP is an evolving language, and each new release introduces new features, security fixes, and enhancements. 

As a result, knowing how to check the current PHP version is essential, whether you work as a web developer or system administrator or are just inquisitive about the setup of your PHP server version.

In this tutorial, we’ll look at a couple of ways to check PHP version is installed on your server.  Once you have read through it, you will have multiple ways in your toolkit that you can apply as you see fit.  

Table Of Contents

  1. How to Check PHP Version on Your Server
    1. Prerequisites
    2. Method #1: Run the PHP Code Snippet to Verify the PHP Version
    3. Method #2: Use the Command Line to Verify the Version of PHP on Windows, Linux, and macOS
  2. Conclusion
  3. FAQs

How to Check PHP Version on Your Server

If you are managing a production server or working in a local development environment, use the following techniques to check the current PHP version on your server. But before that, let’s look at the techniques’ prerequisites.  

Prerequisites

Before you try the techniques mentioned in this tutorial, we suggest you have the following:

  • Ensure PHP is installed  on the target system/server.
  • Administrator access to the server. 
  • Access to command line or terminal.

Method #1: Run the PHP Code Snippet to Verify the PHP Version 

The simplest way to check the current PHP version on your website is to run a simple PHP code snippet in the browser to display current PHP version information.

Use your preferred text editor to create a new file in the document root of the server. Next, add the following code to the file and save it. 

<?php

echo 'PHP version: ' . phpversion();

?>

Next, launch the web browser and enter the file’s complete address in the address bar. For instance, if your address is example.com, you can go to 

http://www.example.com/phpinfo.php

The output displays the current PHP version without any further information:

php version 7.4.33

This very basic information is good for non-technical users. However, developers often need more details about the PHP configuration (like build date, system information, server API, and configuration file). Fortunately, the phpinfo() function can provide these details.

php version 7.4.33 (2)

You can get even more details by adding the following code to the file you uploaded to the server’s document root. This code snippet displays  a list of all the loaded PHP extensions, along with their versions:

<?php

foreach (get_loaded_extensions() as $i => $ext)

{

   echo $ext .' => '. phpversion($ext). '<br/>';

}

?>

The output displays the version of the PHP core along with all extensions:

php cores with extension

Method #2: Use the Command Line to Verify the Version of PHP on Windows, Linux, and macOS

If you have SSH access to a remote server, you can use the command line to verify the installed PHP version. This method works on all systems that support the command line PHP query, like Windows, Linux, and macOS.

Additionally, you can use this command to find the PHP version of the local system.

Launch the terminal (local or SSH) and enter the following command:

# php -v

php -v

Resolve “PHP is not recognized.” Windows Error

In some instances, the php -v command can produce the php is not recognized error when Windows does not recognize the PHP path.

php recognition in windows

You can easily resolve this issue by setting the PATH environment variable by following these steps:

  1. Enter the following command (remember to replace [location] with the full path to your PHP installation).

set PATH=%PATH%;[location]

replace location with full path

  1. Verify that the PATH variable has been set by rerunning the php -v command.

path variable

Conclusion 

Web developers and administrators must know what PHP version is installed on your server. This tutorial covered a variety of techniques that let users easily check php versions, including web-based methods and command-line tools. Knowing and checking your PHP  update version frequently for security, compatibility, and performance is essential. 

RedSwitches, your global dedicated hosting partner, can help you improve your hosting environment. So, if you’re looking for a robust server for your business projects, RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated servers, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. How do I check PHP version on my server?

You can check PHP version using a command-line interface. Simply run the command php -v to display the installed PHP version.

Q. Is there a web-based method to check PHP version?

You can use the code <?php phpinfo();?> to create a simple  PHP file and use a web browser to access it. This will give comprehensive details, including the version of PHP.

Q. Why is it important to know my PHP version?

It’s essential to know your PHP version to work with web applications. This check guarantees that you can make are informed about security patches, updates, and possible problems.

Q. Can I upgrade my PHP outdated version if it’s?

You can use your PHP  update version for the most recent features and security updates. Make sure, though, that your web apps work with the most recent version of PHP.

Q. What are the potential security risks of using an outdated PHP version?

Outdated PHP versions can affect performance and expose your website to security flaws. Updating PHP is necessary to maintain a safe and effective online environment.

Q. Does RedSwitches provide support for the PHP updates?

RedSwitches offers dedicated hosting services with support for PHP version management. Our team ensures that your server environment is up-to-date and secure.

Q. How often should I check my PHP version?

We recommend checking the PHP version regularly, especially before making significant updates to your web applications. Staying proactive is critical to maintaining a secure and high-performing server environment.