Skip to content
Follow
Ubuntu Linux

Check PHP Version and Install on Ubuntu 24.04

Richard
Written by
Richard
Dec 28, 2021 Updated Jul 14, 2026 5 min read
Check PHP Version and Install on Ubuntu 24.04
Check PHP Version and Install on Ubuntu 24.04

Checking your PHP version on Ubuntu 24.04 is done by typing `php -v` in your terminal.

PHP is a programming language that powers many websites and web apps, like WordPress. It’s what makes them dynamic and interactive.

Knowing your PHP version is important because some websites need a specific version to work. For example, an application might require PHP 8.2.

Using software built for an older PHP version with a newer one can cause errors. This guide shows you how to check your current version and install PHP 8.2 or 8.3 on Ubuntu 24.04.

⚡ Quick Answer

Check your PHP version on Ubuntu 24.04 by opening a terminal and running `php -v`. If you need to install a different version, you can add a PPA using `add-apt-repository ppa:ondrej/php` and then install your desired version with `apt install phpX.X`.

Find out what version of PHP is installed

Checking the PHP version installed on your Ubuntu 24.04 system is straightforward using a command in your terminal. Running `php -v` or `php –version` will show the exact PHP version your system is currently using, along with other useful details. This command is the quickest way to find out which PHP version your Ubuntu 24.04 is running.

Run the commands below to check the PHP version in your Ubuntu Linux terminal.

🐘PHP
php -v
# OR
php --version

Once you run the command above, it should output lines similar to these:

PHP version 7.4.3 is available in the Ubuntu repository, but this fact does not guarantee that the absolute latest PHP version can be installed. Newer PHP versions often require specific system updates or manual compilation to install on Ubuntu 24.04.

More information on the installed PHP version can be found by running the commands below:

🐧Bash / Shell
apt info php

When you run the commands above, it should list output similar to this:

🐘PHP
Package: php
Version: 2:7.4+75
Priority: optional
Section: php
Source: php-defaults (75)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
💡Tip
The most reliable way of finding out what version of PHP is used for a specific website is to use the phpinfo() function. This prints various information about the PHP server, including its version.

To use this step to find the PHP version, create a file called phpinfo.php in your web server’s root directory. This is typically located here:

🐧Bash / Shell
sudo nano /var/www/html/phpinfo.php

Copy and paste the line below into the file, then save and close it.

🐘PHP
<?php phpinfo( ); ?>

Next, open your browser and go to localhost/phpinfo.php or your domain name (example.com/phpinfo.php). The PHP server version will be displayed on your screen:

Terminal window showing PHP installation process on Ubuntu 24.04 server
php install with apache ubuntu google cloud

Find out what PHP modules are installed

Once your PHP version is checked on Ubuntu 24.04, seeing which PHP modules are installed and active is possible with a specific command. The command `dpkg –get-selections | grep -i php` will show you a list of all installed PHP packages and their current status on your system. This helps you understand what PHP extensions are available.

🐘PHP
dpkg --get-selections | grep -i php

After executing the commands above, you should see output that resembles the lines shown below.

🐘PHP
libapache2-mod-php8.1				install
php-common					install
php-fpm						install
php7.4-cli					install
php7.4-common					install
php7.4-fpm					install
php7.4-json					install
php7.4-opcache					install
php7.4-readline					install
php8.1						install
php8.1-cli					install
php8.1-common					install
php8.1-opcache					install
php8.1-readline					install
ftp

The length of this list can vary based on your environment.

To list modules compiled with PHP, run the commands below:

Ubuntu 24.04 automatically installs the latest stable PHP version, but you can install a specific PHP version if your project requires it. If the needed PHP version is not in the default software sources, you must add a third-party repository to your system first. This is common when you need an older PHP version or a very new PHP version.

A third-party repository might need to be added to your system if you want to install a specific version that isn’t available in Ubuntu Linux.

Adding a repository in Ubuntu Linux lets you install specific software versions, such as PHP 8.2. Use the commands below to add this repository.

First, install the necessary commands:

🐧Bash / Shell
sudo apt update
sudo apt install software-properties-common

Next, run the commands below to add the repository.

🐧Bash / Shell
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

After that, you can search for and install a specific version of PHP.

🐘PHP
apt-cache showpkg php

Install a specific version using the command format below:

🐧Bash / Shell
sudo apt-get install php8.x=<complete version name>

Replace ‘x’ with the PHP minor version number (e.g., 2 for 8.2) and ‘<complete version number>’ with the full version number available for Ubuntu.

Here’s an example:

🐧Bash / Shell
sudo apt install php8.1=8.1.0-1+ubuntu20.04.1+deb.sury.org+1

Now the new version should reflect as shown below:

🐘PHP
PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies

That should do it!

Conclusion:

  • Understanding the PHP version running on your system is crucial for compatibility and security.
  • PHP installation on Ubuntu is straightforward and can be tailored to specific versions using third-party repositories.
  • The phpinfo() function is a helpful tool for verifying PHP configuration and installed modules.
  • Regularly checking for updates and managing PHP versions ensures optimal performance for your web applications.
  • Knowing how to list installed PHP modules enhances your ability to troubleshoot and manage your server environment effectively.

What is the default PHP version in Ubuntu 24?

What PHP version does Ubuntu 24.04 include? Ubuntu 24.04 ships with PHP 8.3 in its default repositories.

How do I check my PHP version?

And it will give you detailed information on your PHP installation and extensions.

How do I find out what version of Ubuntu 24.04 I have?

Scroll to the very bottom of the left-hand sidebar in the Settings window and select “About“. 4. Your Ubuntu version will be listed under the OS Name label (e.g., Ubuntu 24.04 LTS, Ubuntu 22.04. 5 LTS).

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04
Working with Sudo and Su Commands in Ubuntu Linux
Ubuntu Linux Working with Sudo and Su Commands in Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *