Home Ubuntu How to check PHP Version on Ubuntu

How to check PHP Version on Ubuntu

We'll introduce several methods to do this, including using the terminal, checking through a PHP file, or finding the version in your web server software.

by Arun Kumar
check your php version on ubuntu

I am here again, feeling equally excited and caffeinated to dive into today’s topic: “Checking PHP version on Ubuntu.” For all of you web developers and system administrators out there, this is an essential guide to understanding your PHP environment. When I say, nothing beats knowing your tool well, as I have faced too many instances where unfamiliarity with the environment led to countless debugging hours! I will be walking you through each step, supported with real-life examples and visuals for a deeper understanding. Let’s roll our sleeves up and get started.

Introduction to PHP

PHP is one of the oldest and most popular server-side scripting languages used for web development. Having been around for a couple of decades, PHP has seen many versions, each one improving upon its predecessor. It’s crucial to know which PHP version you are using because each version has different features, performance improvements, and security fixes.

Now, let’s say you’re using Ubuntu, a popular Linux distribution. How can you check your PHP version?

Checking PHP version via Command Line

Checking the PHP version on Ubuntu is a straightforward process. For all those command-line fans out there (count me in!), the Terminal is your go-to place.

To check the PHP version, open up your Terminal. You can do this by searching for it in the ‘Show Applications’ menu or using the keyboard shortcut Ctrl + Alt + T. Once the Terminal is open, type in the following command:

php -v

Press Enter, and voilà! Your PHP version will be displayed.

checking php version on ubuntu successful

Checking the PHP version on Ubuntu successful

Pro-tip: Remember to update and upgrade your Ubuntu system before you check for the PHP version. This will ensure that your software packages are up to date. You can do this by running the commands sudo apt update and sudo apt upgrade.

What if PHP is not installed?

checking php version on ubuntu

Checking the PHP version on Ubuntu not successful

If you get an error message saying “php: command not found,” it means PHP is not installed on your Ubuntu system. No worries, though! You can easily install it by using the command:

sudo apt install php
installing php on ubuntu

Installing php on Ubuntu

After installation, re-run the php -v command to check your PHP version.

Checking PHP version in a Virtual Environment

Now, let’s venture into virtual environments. Many times, especially in production environments, you may be using tools like VirtualBox or VMware Player to create isolated virtual machines (VMs).

VirtualBox

I have a soft spot for VirtualBox because of its user-friendly interface and ease of use. Here’s how to check PHP version in a VirtualBox VM.

After starting your Ubuntu VM, open the Terminal within the VM and follow the same steps as discussed earlier to check the PHP version.

Pro-tip: VirtualBox provides a “Guest Additions” feature, which offers seamless integration between the host and the VM. I recommend installing this to enhance your VM experience.

VMware Player

VMware Player is another fantastic tool for creating VMs. I must admit, I’m not the biggest fan of its interface, but its advanced features make up for it.

The process for checking the PHP version remains the same. Just ensure you have your Ubuntu VM up and running, open Terminal in the VM, and use the php -v command.

Pro-tip: VMware Tools, similar to VirtualBox’s Guest Additions, is a handy feature for better VM performance. Do not forget to install it!

As you can see, checking the PHP version in virtual machines is no different than when checking on a dedicated server or a computer. I just wanted to make a point so you don’t have doubts.

Checking PHP version via PHP script

Here’s another handy method to check your PHP version, especially for those who are more comfortable with code.

Create a new PHP file. You can name it info.php (though the name does not really matter). Open this file in your text editor and insert the following code:

<?php
phpinfo();
?>

Save and close the file. Now, move this file to your web server’s root directory. If you’re using Apache on Ubuntu, the root directory is usually /var/www/html/. You can move the file using the following command:

sudo mv info.php /var/www/html/

Now, open your web browser and navigate to http://localhost/info.php. This will display a detailed PHP information page, including the PHP version.

Pro-tip: After checking your PHP version, remember to delete the info.php file from your server, as it contains sensitive information that could be exploited if it fell into the wrong hands.

Why checking PHP version is crucial in an organization

In an organizational setup, understanding the version of PHP you’re working with assumes critical importance for several reasons. Let’s delve into why it holds such high relevance.

Code Compatibility

Different PHP versions support different features. If your codebase is built using features from a newer PHP version, it might not run correctly or at all on an older version. Therefore, understanding your PHP version can help you ensure code compatibility.

Also, there’s always the risk of deprecated features. With each new PHP release, older, less efficient features are marked as deprecated and eventually removed. If your codebase uses these deprecated features, it could lead to functionality issues. By knowing your PHP version, you can plan ahead to update or refactor your code as needed.

Performance Improvements

Each new PHP version comes with performance improvements over its predecessors. This means faster execution times and less memory usage. By knowing your PHP version, you can make an informed decision about whether or not an upgrade would significantly improve your application’s performance.

In an organizational setup where high performance is often a critical need, understanding your PHP version is therefore pivotal.

Security Fixes

The PHP community regularly releases updates to address security vulnerabilities found in older versions. Using an outdated version of PHP can leave your web application vulnerable to attacks. For an organization, this could lead to severe consequences, including data breaches and loss of customer trust.

By routinely checking your PHP version, you can ensure you’re using a secure, patched version and protect your organization from potential security risks.

Compliance Requirements

Many organizations have to meet certain compliance requirements related to the software they use. For example, a policy may require them to use only software that still receives security updates from the vendor. Since PHP stops providing security updates for older versions at some point, organizations may need to verify their PHP version to meet these compliance requirements.

Planning and Budgeting

Upgrading to a newer PHP version can sometimes be a substantial project that requires significant planning and resources. Organizations may need to allocate developer time to update and test their code, arrange for system downtime, or even purchase new server hardware.

Knowing their current PHP version helps organizations plan and budget for the upgrade process, ensuring a smooth and cost-effective transition.

Conclusion

Understanding your environment, especially the PHP version, is critical for any developer or system administrator working with web applications. In this guide, I have covered different ways to check the PHP version on Ubuntu, both in the standard system and within virtual environments using VirtualBox or VMware Player.

Although I am a big fan of command-line operations, I understand that different methods work better for different people, hence I included the PHP script method too. Remember, what’s important is not how you do it, but what you do with the information you get.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.