How to Install PHP 8.4 on Ubuntu 24.04 LTS
PHP is one of the most widely used server-side programming languages for web development. Popular platforms such as Magento, WordPress, Laravel, and many custom PHP applications depend on a properly configured PHP environment.
In this guide, you'll learn how to install PHP 8.4 on Ubuntu 24.04 LTS, install commonly used PHP extensions, configure PHP for better performance, verify the installation, and troubleshoot common issues.
What You'll Learn
By the end of this tutorial you'll know how to:
- Install PHP 8.4
- Install commonly required PHP extensions
- Verify your PHP installation
- Configure PHP settings
- Restart PHP-FPM
- Troubleshoot common PHP issues
Prerequisites
Before starting, ensure you have:
- Ubuntu 24.04 LTS
- A user with sudo privileges
- Internet connectivity
- Terminal access
Step 1 — Update Your Ubuntu System
Before installing new software, update your package list and installed packages.
bashsudo apt update sudo apt upgrade -y
Keeping your system updated ensures you're installing the latest available packages and security fixes.
You can also verify your Ubuntu version.
bashlsb_release -a
Example:
textDistributor ID: Ubuntu Description: Ubuntu 24.04 LTS Release: 24.04 Codename: noble
Step 2 — Install Required Packages
Install the package required to manage repositories.
bashsudo apt install software-properties-common -y
Step 3 — Add the PHP Repository
Ubuntu's default repositories may not always provide the latest PHP release. A commonly used repository for newer PHP versions is maintained by Ondřej Surý.
Add the repository:
bashsudo add-apt-repository ppa:ondrej/php
Update package information:
bashsudo apt update
Step 4 — Install PHP 8.4
Install PHP.
bashsudo apt install php8.4 -y
After installation, verify the installed version.
bashphp -v
Example output:
textPHP 8.4.x (cli) Copyright (c) The PHP Group Zend Engine v4.x
Step 5 — Install Common PHP Extensions
Most PHP applications require additional extensions.
Install the commonly used extensions:
bashsudo apt install \ php8.4-cli \ php8.4-common \ php8.4-fpm \ php8.4-bcmath \ php8.4-curl \ php8.4-gd \ php8.4-intl \ php8.4-mbstring \ php8.4-mysql \ php8.4-opcache \ php8.4-readline \ php8.4-soap \ php8.4-xml \ php8.4-xsl \ php8.4-zip \ php8.4-sockets -y
PHP Extension Overview
| Extension | Purpose |
|---|---|
| bcmath | Mathematical calculations |
| curl | HTTP requests |
| gd | Image processing |
| intl | Internationalization |
| mbstring | UTF-8 string handling |
| mysql | MySQL database connectivity |
| soap | SOAP web services |
| xml | XML parsing |
| xsl | XML transformations |
| zip | Archive extraction |
| sockets | Network communication |
| opcache | Improves PHP performance |
Step 6 — Verify Installed Extensions
Run:
bashphp -m
Verify that important modules such as the following are available:
- curl
- intl
- mbstring
- mysql
- soap
- xml
- xsl
- zip
- gd
- opcache
Step 7 — Find the Active PHP Configuration File
Display the active configuration.
bashphp --ini
Example output:
textLoaded Configuration File: /etc/php/8.4/cli/php.ini
For PHP-FPM you'll typically edit:
text/etc/php/8.4/fpm/php.ini
Open the file:
bashsudo nano /etc/php/8.4/fpm/php.ini
Step 8 — Recommended PHP Configuration
The following settings are suitable for many PHP applications and provide a good starting point.
inimemory_limit = 2G max_execution_time = 1800 max_input_time = 1800 upload_max_filesize = 64M post_max_size = 64M date.timezone = Asia/Kolkata
Recommended Values
| Setting | Value |
|---|---|
| memory_limit | 2G |
| max_execution_time | 1800 |
| upload_max_filesize | 64M |
| post_max_size | 64M |
| timezone | Asia/Kolkata |
Adjust these values based on your application's requirements.
Step 9 — Restart PHP-FPM
After making configuration changes, restart PHP-FPM.
bashsudo systemctl restart php8.4-fpm
Check its status.
bashsudo systemctl status php8.4-fpm
You should see:
textActive: active (running)
Step 10 — Verify the Default PHP Version
If multiple PHP versions are installed, verify which version is active.
bashphp -v
If needed, switch the CLI version.
bashsudo update-alternatives --config php
Troubleshooting
PHP Command Not Found
textphp: command not found
Possible solutions:
- Verify PHP is installed.
- Restart your terminal.
- Check your PATH configuration.
Incorrect PHP Version
Verify the installed version.
bashphp -v
If multiple versions exist, update the active version.
bashsudo update-alternatives --config php
Missing Extensions
List installed extensions.
bashphp -m
Install any missing extension.
Example:
bashsudo apt install php8.4-intl
PHP-FPM Service Won't Start
Check its status.
bashsudo systemctl status php8.4-fpm
Review logs.
bashsudo journalctl -u php8.4-fpm
Frequently Asked Questions
How do I check my PHP version?
Run:
bashphp -v
Where is php.ini located?
Find the active configuration file.
bashphp --ini
Can I install multiple PHP versions?
Yes.
Ubuntu allows multiple PHP versions to coexist. You can switch the active CLI version using:
bashsudo update-alternatives --config php
How do I list installed PHP extensions?
Run:
bashphp -m
Do I need PHP-FPM?
If you're using Nginx, PHP-FPM is the standard way to process PHP requests and is recommended for production deployments.
Conclusion
Congratulations! 🎉
You've successfully installed PHP 8.4 on Ubuntu 24.04 LTS, installed commonly used extensions, configured PHP, and verified that your installation is working correctly.
Your server is now ready for PHP-based applications and is well prepared for the next steps in setting up a complete development environment.
What's Next?
Continue with the next guide in our series:
➡️ How to Install Composer on Ubuntu 24.04 LTS
Composer is the dependency manager used by modern PHP applications such as Magento, Laravel, and many other frameworks.



