How to check the PHP version?
While using any programming language, it's always advisable to use new versions. New versions are often faster, secure, and supported by the developer. If you are looking forward to implementing new features and improvements on your website, the first thing you must know is your current PHP version.
Here are two simple methods to check your PHP version.
By running PHP code
This is the simplest method to determine the current PHP version on your website. This method involves executing a PHP file that contains the following code:
echo 'PHP version: ' . phpversion();
Create the necessary file with the help of a text editor such as Gedit or Notepad. Then, upload this file to your website’s document root directory.
Now, open a web browser and type the full address of the file in the address search bar. For example, if your uploaded file has the title phpinfo.php in the example com root directory, you would go to:
Running the code above will display the PHP version without the core details. For instance, PHP 7.4. If you want further information on this PHP configuration, such as system information, etc., upload a file containing the phpinfo() function.
Visiting this file in the browser will show the PHP version with respective configuration data.
Using the Command Line (Windows, Linux, and macOS)
You can use the command line method to check the current PHP version only if you have permission to SSH into the remote server. This method is generally effective for checking the PHP version installed locally.
- Type the PHP command:
- The php -v command works on most operating systems. Running the command above will output the PHP version number, build date, and copyright information.