Skip to content
Follow
Ubuntu Linux

Check PHP Version and Install on Ubuntu 24.04

Richard
Written by
Richard
Dec 28, 2021 Updated Sep 15, 2026 4 min read
Check PHP Version and Install on Ubuntu 24.04
Check PHP Version and Install on Ubuntu 24.04

Checking the PHP version on Ubuntu 24.04 takes just one quick command in your terminal. PHP is a programming language that powers popular websites and platforms like WordPress to make them run properly.

Advertisement

Type php -v to see your exact version instantly. Knowing your version helps you avoid errors when you run software that needs a specific update like PHP 8.2 or 8.3.

⚡ 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`.

Advertisement

Find out what version of PHP is installed

To check your PHP version on Ubuntu 24.04, open your terminal and run the command php -v or php –version. This displays the currently active PHP version along with build details and the release date directly on your screen, letting you confirm your setup in seconds.

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

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.

Advertisement

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

apt info php

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

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
💡TipThe most reliable way of finding out what version of PHP is used for a specific website is to use the phpinfo() function.

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 named phpinfo.php in your web server's root directory (the main folder holding your website files). This is typically located here:

Advertisement
sudo nano /var/www/html/phpinfo.php

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

<?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

To check installed PHP modules on Ubuntu 24.04, run the command dpkg --get-selections | grep -i php in your terminal. This lists every PHP package currently present on your system so you can see which extensions and modules are active.

dpkg --get-selections | grep -i php

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

Advertisement
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 installs the latest stable PHP version by default. Projects requiring a different release need a third-party software source added first. This is common when you need an older PHP version or a very new PHP version.

Add a third-party repository if you need to install a version not available in the default Ubuntu repositories.

Advertisement

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:

sudo apt update
sudo apt install software-properties-common

Next, run the commands below to add the repository.

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

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

Advertisement
apt-cache showpkg php

Install a specific version using the command format below:

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:

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:

Advertisement
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!

Keeping track of active PHP versions is crucial for security and application compatibility.

  • 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.

Advertisement

📚 Related Tutorials

How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux
How to Downgrade PHP Version on Ubuntu 24.04
Ubuntu Linux How to Downgrade PHP Version on Ubuntu 24.04
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

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

Leave a Comment

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