4 Easy Methods to Check PHP Version on Linux

Introduction

If you're working with PHP on a Linux system, knowing the PHP version installed is crucial for compatibility and debugging. Here are four simple methods to check the PHP version on your Linux machine.

1. Using the php -v Command

The easiest and most common way to check the PHP version is by using the php -v command in the terminal. This command provides detailed information about the PHP version installed.

Steps:

  1. Open your terminal.
  2. Type php -v and press Enter.
  3. You will see output similar to:
    PHP 7.4.3 (cli) (built: May 26 2020 12:24:05) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

2. Using the php --version Command

Another command that yields the same result as php -v is php --version. This command is interchangeable with the previous one and provides the same information.

Steps:

  1. Open your terminal.
  2. Type php --version and press Enter.
  3. You will see output similar to the one shown above.

3. Creating a PHP Info File

If you have access to a web server and prefer to check the PHP version via a web interface, creating a PHP info file is a good option.

Steps:

  1. Open your text editor and create a new file named info.php.
  2. Add the following line of code:
    <?php phpinfo(); ?>
  3. Save the file and upload it to your web server's root directory.
  4. Open a web browser and navigate to http://yourdomain.com/info.php.
  5. The PHP information page will be displayed, showing the PHP version and other configuration details.

4. Checking the PHP Version via Package Manager

If you installed PHP via a package manager like apt or yum, you can use these package managers to check the PHP version.

For Debian/Ubuntu-based systems:

  1. Open your terminal.
  2. Type apt show php and press Enter.
  3. Look for the Version field in the output.

For Red Hat/CentOS-based systems:

  1. Open your terminal.
  2. Type yum info php and press Enter.
  3. Look for the Version field in the output.

Conclusion

Knowing your PHP version is essential for maintaining and troubleshooting your applications. Whether you prefer using command line tools or a web interface, these methods will help you quickly determine the PHP version running on your Linux system.

By following the steps outlined in this guide, you can easily check your PHP version and ensure your environment is up-to-date and compatible with your projects. Thank you for reading the huuphan.com page!

Additional Tips

  • Regularly check for updates to ensure you're running the latest PHP version.
  • Remove the info.php file after use to prevent exposing sensitive information.

Comments

Popular posts from this blog

Bash script list all IP addresses connected to Server with Country Information

zimbra some services are not running [Solve problem]

Zimbra Client host rejected Access denied fixed