How to Install PHP 8.4 on Ubuntu 24.04
How to Install PHP 8.4 on Ubuntu 24.04: Complete Step-by-Step Guide

Introduction
PHP 8.4 brings exciting new features and performance improvements to the PHP ecosystem. In this comprehensive tutorial, we’ll walk you through installing PHP 8.4 on Ubuntu 24.04 LTS, covering multiple installation methods and essential configurations for optimal performance.
What’s New in PHP 8.4?
PHP 8.4 introduces several groundbreaking features including property hooks, asymmetric visibility, lazy objects, and significant performance enhancements. This latest version offers improved memory usage, better JIT compilation, and enhanced security features that make it essential for modern web development.
Prerequisites
Before installing PHP 8.4 on Ubuntu 24.04, ensure you have:
- Ubuntu 24.04 LTS server or desktop
- Root or sudo privileges
- Basic command-line knowledge
- Stable internet connection
Enable the PHP PPA Repository
Ubuntu’s default repositories may not always provide the latest or specific PHP 8.x versions. To get access to PHP 8.4 and its associated extensions, add the trusted third-party source maintained by Ondřej Surý. Use the Personal Package Archive: ppa:ondrej/php. This PPA is widely used and actively maintained by the PHP community.
Step 1: Update Your Ubuntu System
sudo apt update && sudo apt upgrade -yStep 2: Install Required Dependencies
sudo apt install software-properties-common apt-transport-https ca-certificates -yStep 3: Add PHP PPA Repository
sudo add-apt-repository ppa:ondrej/phpEnter to confirm adding the PPA when prompted. Then, refresh your package list to load the latest information from the newly added repository.sudo apt updateStep 4: Install PHP 8.4
sudo apt install php8.4 -yStep 5: Verify PHP Installation
php -vThe output will look something like:
OutputPHP 8.4.8 (cli) (built: Jun 9 2025 13:49:53) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.8, Copyright (c) Zend Technologies
with Zend OPcache v8.4.8, Copyright (c), by Zend TechnologiesStep 6: Install PHP 8.4 Common Extensions
The following PHP 8.4 extensions are commonly used across modern web applications, including content management systems, frameworks, and RESTful APIs:
php8.4-common: Includes core PHP files required by other modules
php8.4-cli: Enables PHP to run from the command line
php8.4-opcache: Improves performance by caching precompiled script bytecode
php8.4-mysql: Provides integration with MySQL and MariaDB databases
php8.4-xml: Supports XML parsing and DOM manipulation
php8.4-curl: Enables communication with external APIs and services using cURL
php8.4-zip: Allows reading and writing of ZIP-compressed files
php8.4-mbstring: Handles multibyte character encodings such as UTF-8
php8.4-gd: Provides image processing capabilities
php8.4-intl: Adds support for internationalization and localization
php8.4-bcmath: Enables arbitrary precision mathematics operations
php8.4-json: Provides JSON encoding and decoding support, commonly used in APIs and web applications
php8.4-fpm: FastCGI Process Manager for PHP, optimized for high-performance web servers like Nginx
sudo apt install php8.4 php8.4-cli php8.4-common php8.4-mysql php8.4-zip php8.4-gd php8.4-mbstring php8.4-curl php8.4-xml php8.4-bcmath php8.4-intl php8.4-fpm -yAfter installation, you can verify all installed modules with:
php -mInstall PHP 8 FPM
PHP-FPM (FastCGI Process Manager) runs PHP as an independent background service, allowing it to handle dynamic content more efficiently than standard CGI methods. It offers better performance, enhanced resource management, and is well-suited for handling high-concurrency web applications.
Step 1: Install PHP 8.4 FPM
sudo apt install php8.4-fpm -yStep 2: Start the PHP-FPM service to begin handling requests:
sudo systemctl start php8.4-fpmStep 3: Enable it to launch automatically at system startup:
sudo systemctl enable php8.4-fpmStep 4: Verify that the service is active and running properly:
sudo systemctl status php8.4-fpmEssential PHP 8.4 Configuration
Configure PHP.ini Settings; Edit the PHP configuration file:
sudo nano /etc/php/8.4/cli/php.iniRecommended settings for optimal performance:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_vars = 3000Configure PHP-FPM Socket for Apache Integration
To integrate PHP-FPM with Apache efficiently, it’s best to use a Unix socket instead of a TCP connection. Unix sockets offer lower latency and enhanced security for inter-process communication.
1. Open the PHP-FPM pool configuration file for the default user pool
sudo nano /etc/php/8.4/fpm/pool.d/www.conf2. Modify or ensure the following directives are set:
listen = /run/php/php8.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660www-data user, has permission to communicate with PHP-FPM via the socket.Why this matters?
PHP-FPM enables Apache to offload PHP processing to a dedicated service, enhancing performance and scalability. With the help of modules like proxy_fcgi and configurations enabled via a2enconf, the integration is seamless and production-ready.
Testing PHP 8.4 Installation
Before proceeding, ensure that Apache is installed and running on your server.
If you haven’t set up Apache yet, follow the installation guide available at the link below:
For a step-by-step Apache installation guide, please click here
Create a test PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.phphttp://your-server-ip/info.php to verify the installation.Installing Composer with PHP 8.4
Composer is the dependency manager for PHP, widely used in modern PHP development to manage packages and libraries. This guide explains how to install Composer globally on Ubuntu with PHP 8.4, ensuring a secure and clean setup for your development environment.
1. Install required dependencies
sudo apt install curl unzip -y2. Download Composer Installer
curl -sS https://getcomposer.org/installer -o composer-setup.phpcomposer-setup.php that installs Composer securely.3. Verify Installer Signature (Recommended)
To protect against corrupted or tampered downloads, validate the installer’s signature.
To ensure the integrity of the downloaded installer, we’ll compare its SHA-384 hash against the official value published on Composer’s Public Keys / Signatures page.
You can use the following command to automatically fetch the latest hash and store it in a shell variable for verification:
HASH=`curl -sS https://composer.github.io/installer.sig`
4. Next, run the following PHP code—directly sourced from the official Composer download page—to verify that the installer script is authentic and secure before executing it:
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"You should see:
OutputInstaller verified5. Install Composer Globally
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composercomposer binary in /usr/local/bin/.OutputAll settings correct for using Composer
Downloading...
Composer (version 2.8.9) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer6. Verify Composer Installation
composer --versionOutputComposer version 2.8.9 2025-05-13 14:01:37
PHP version 8.4.8 (/usr/bin/php8.4)
Run the "diagnose" command to get more detailed diagnostics output.Managing Multiple PHP Versions
Ubuntu allows running multiple PHP versions simultaneously. Use update-alternatives to switch between versions:
1. Set PHP 8.4 as Default
sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.4 842. Run a command to Configure PHP Alternative
sudo update-alternatives --config phpPerformance Optimization Tips
These OPcache settings optimize PHP performance by caching compiled script bytecode in memory, reducing the need for repeated parsing and compilation:
1. Enable OPcache; OPcache significantly improves PHP performance:
sudo nano /etc/php/8.4/cli/conf.d/10-opcache.ini2.Add these optimizations:
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.revalidate_freq=0opcache.enable=1 Enables the OPcache extension. When set to 1, OPcache actively caches PHP scripts to improve performance.opcache.memory_consumption=256 Allocates 256 MB of memory for storing precompiled PHP code in shared memory. This value can be increased for large applications.
opcache.max_accelerated_files=20000 Specifies the maximum number of PHP files that OPcache can store. A higher number allows for larger codebases to be fully cached.
opcache.revalidate_freq=0 Forces OPcache to check for script updates on every request. This ensures changes are picked up immediately, ideal for development environments (set higher for production).
Configure PHP-FPM for High Performance
These PHP-FPM directives control how child processes are managed to handle incoming PHP requests. Tuning these values is important for performance, especially under high traffic:
1. Open the PHP-FPM pool configuration file for the default user pool
sudo nano /etc/php/8.4/fpm/pool.d/www.conf2. Add / Modify these configurations
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35pm = dynamic Sets the process manager mode to dynamic, which allows PHP-FPM to automatically adjust the number of child processes based on demand.pm.max_children = 50 Defines the maximum number of child processes that can be alive at the same time. This limits concurrency and memory usage.
pm.start_servers = 10 Sets how many child processes are created when PHP-FPM starts. Adjust based on expected load at startup.
pm.min_spare_servers = 5 Minimum number of idle (waiting) child processes to keep available. Helps handle sudden traffic spikes without delay.
pm.max_spare_servers = 35 Maximum number of idle child processes. Prevents resource waste by limiting how many idle processes can remain active.
/etc/php/8.4/fpm/pool.d/www.conf, restart PHP-FPM:sudo systemctl restart php8.4-fpmSecurity Best Practices
Disable Dangerous Functions
1. In php.ini, disable potentially harmful functions:
disable_functions = exec,passthru,shell_exec,system,proc_open,popen2. Hide PHP Version
expose_php = Off3. Enable Error Logging
log_errors = On
error_log = /var/log/php_errors.logConclusion
Installing PHP 8.4 on Ubuntu 24.04 brings significant performance improvements and new features to your web development environment. Whether you’re running WordPress, Laravel, Symfony, or custom PHP applications, PHP 8.4 offers enhanced security, better memory management, and improved execution speed.
At HostingHome, we provide optimized hosting solutions with the latest PHP versions, ensuring your websites run at peak performance. Our Ubuntu 24.04 hosting plans come with PHP 8.4 pre-configured and ready for your applications.
For production environments, always test thoroughly before upgrading, maintain proper backups, and monitor your applications post-upgrade to ensure optimal performance.