Check PHP Version and Install on Ubuntu 24.04
You can check your current PHP version on Ubuntu 24.04 using the `php -v` command in your terminal.
PHP is a server-side scripting language vital for dynamic websites and web applications like WordPress, and knowing its version is key for compatibility. For instance, some applications specifically require PHP 8.2 to function correctly.
Running software designed for an older PHP version on a newer one can lead to errors, so verifying your version and knowing how to install a specific one, like PHP 8.2 or 8.3, on Ubuntu 24.04 is essential for smooth development and deployment.
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
You can easily check the PHP version installed on your Ubuntu 24.04 system by opening your terminal and running a simple command.
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 7.4.3 (cli) (built: Nov 25 2021 23:16:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Version 7.4.3 is available in the Ubuntu repository, but this doesn’t mean the absolute latest PHP version can be installed.
You can also find more information on the installed PHP version 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
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:
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:

Find out what PHP modules are installed
After checking your PHP version, you might want to see which PHP modules are currently installed and active on your Ubuntu system.
dpkg --get-selections | grep -i php
After executing the commands above, you should see output that resembles the lines shown below.
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:
php -m
Install a specific version of PHP
Ubuntu 24.04 usually installs the latest stable PHP version from its default software sources, but you can install a specific version if needed.
You might need to add a third-party repository to your system if you want to install a specific version that isn’t available in Ubuntu Linux.
Use the commands below to add a repository in Ubuntu Linux. This will let you install specific software versions.
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.
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 and <complete version number> with the 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:
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?
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.
No comments yet — be the first to share your thoughts!