
PHP (Hypertext Preprocessor) is a widely used, open-source scripting language for building dynamic and interactive web applications. To take advantage of its latest capabilities, install PHP 8 on Ubuntu 24.04, which includes PHP 8.4’s performance enhancements such as JIT compilation, improved type safety, and expanded syntax features.
This article shows you how to install PHP 8.4 on Ubuntu 24.04 using the ppa:ondrej/php repository. You'll configure PHP-FPM, verify the installation using two test methods (Apache and PHP's built-in server), and ensure common extensions are working properly.
Before you begin:
sudo privileges.Ubuntu’s default package sources may not include older PHP 8.x versions. To install PHP 8.4, you’ll use the widely trusted ppa:ondrej/php Personal Package Archive (PPA), which offers maintained versions and related extensions.
Update the APT package index.
Add the ppa:ondrej/php repository to your APT sources.
Press Enter when prompted to add the PPA to your APT sources.
Update the APT package index to apply the PPA repository information.
PHP 8.4 is currently available through the ppa:ondrej/php repository. You can verify the available version in your APT sources by running:
Output.
This confirms that PHP 8.4 is available from the ppa:ondrej/php repository.
For the latest official release details, refer to the PHP Releases page.
Now that you've added the PPA, install PHP 8.4 and the essential extensions required by most modern web applications.
Install PHP 8.4.
Install commonly used PHP extensions.
These extensions are frequently used in content management systems, frameworks, and APIs:
php8.4-common: Core PHP files php8.4-cli: Command-line interface php8.4-opcache: Bytecode caching for performance php8.4-mysql: MySQL/MariaDB database support php8.4-xml: XML parsing php8.4-curl: cURL library support php8.4-zip: ZIP archive handling php8.4-mbstring: Multibyte string encoding (UTF-8, etc.) php8.4-gd: Image manipulation php8.4-intl: Internationalization support php8.4-bcmath: Arbitrary precision mathVerify the PHP installation.
Output.
List installed PHP versions and optionally make PHP 8.4 the default.
If only PHP 8.4 is installed, set it as the default system version:
Then confirm:
Verify active modules to ensure extensions are loaded:
This lists all active PHP modules.
PHP-FPM (FastCGI Process Manager) runs PHP as a separate background service and handles dynamic requests more efficiently than traditional CGI. It improves performance, resource control, and is ideal for high-traffic applications. Follow the steps below to set up PHP-FPM for optimal performance and efficiency.
Install PHP 8.4 FPM.
Start the PHP-FPM service.
Enable PHP-FPM to start automatically on boot.
Check the status of PHP-FPM service.
Output.
Press Q to exit the status output.
When using PHP-FPM with Apache, it's recommended to connect via a secure Unix socket instead of TCP for better performance and security. This section shows how to configure PHP-FPM to use a socket that Apache can access.
Open the PHP-FPM pool configuration file.
Update the following lines (if not already present).
These settings allow Apache (running as www-data) to send PHP requests through the socket used by PHP-FPM.
PHP-FPM allows Apache to delegate PHP processing to a separate process manager, improving performance and resource handling under heavy traffic. The integration is seamless with modules like proxy_fcgi and configuration snippets enabled through a2enconf.
For advanced tuning options (e.g., process limits, slow logs), see the official PHP-FPM documentation.
This section guides you through integrating Apache with PHP-FPM and verifying the setup with a sample PHP script. Using proxy_fcgi, Apache delegates PHP processing to PHP-FPM, improving performance and scalability.
If Apache is not already installed, install it:
Verify the Apache service is running.
Output.
Press Q to exit the status output.
Enable required Apache modules for PHP-FPM:
Enable the PHP-FPM configuration for Apache:
Restart Apache to apply changes:
Allow HTTP traffic through the firewall.
Reload the firewall configuration.
Create a test info.php file in the Apache web root directory.
Add the following code to the file.
Save and exit the editor.
Access your server's IP address in a web browser and load the /info.php URL path to view the PHP information page. Replace SERVER-IP with your server's actual IP address.
After verifying PHP info, delete info.php to avoid exposing server configuration.
In this article, you installed PHP 8.4 on Ubuntu 24.04, added the required PPA repository, installed core PHP extensions, and configured PHP-FPM. You also verified the installation by creating a test script served through Apache. With PHP 8.4 now running on your system, you’re ready to start building and deploying modern web applications using the latest features and improvements. For more information, visit the official PHP documentation.
0 Comments
Be the first to comment and share your perspective with the community.