Cara cek php --version di cmd

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.

Cara cek php --version di cmd

Prerequisites

  • PHP installed
  • Write access to the server’s file system
  • Access to the command line

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:

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:

Cara cek php --version di cmd

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:

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

Cara cek php --version di cmd

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:

 $ext)
{
   echo $ext .' => '. phpversion($ext). '
'; }

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

Cara cek php --version di cmd

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.

Cara cek php --version di cmd

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.

Cara cek php --version di cmd

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]

Cara cek php --version di cmd

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.

Cara Mengetahui PHP versi berapa?

Caranya ketik domainanda.com/phpinfo. php. Anda akan melihat versi PHP yang digunakan pada website.

PHP terbaru versi berapa?

Versi terbaru dan stabil dari bahasa pemograman PHP saat ini adalah versi 8.0.