
PHP 7.4 is a popular PHP release and the last mirror version for PHP 7. It is supported and required by most applications due to its extensible features and compatibility with multiple services such as database backends. You can use PHP 7.4 with all supported extensions on Ubuntu 24.04 and integrate applications such as web servers to deliver dynamic web applications.
This article explains how to install PHP 7.4 on Ubuntu 24.04. You will use PHP, PHP 7.4 FPM, and common extensions to deliver dynamic web applications while integrating supported services such as web servers with PHP.
Before you begin, you need to:
PHP 7.4 is discontinued and not available in the APT package sources on Ubuntu 24.04. Adding a Personal Package Archive (PPA) repository source allows you to install PHP 7.4 with all supported PECL (PHP Extension Community Library) extensions required in most applications. Follow the steps below to add the ondrej/ppa source to the APT package sources on Ubuntu 24.04.
Update the APT package information index.
Add the ondrej/ppa source 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.
You can install PHP 7.4 on Ubuntu 24.04 after adding the main PPA source on your server. Follow the steps below to install PHP 7.4 and all required extensions on Ubuntu 24.04.
Update the APT package index.
Install PHP 7.4
Check the installed PHP version and verify that it's 7.4.
Use the php7.4 -v command if you have another installed PHP version on your server.
Output:
Install common PHP 7.4 extensions.
The command installs the following common PHP extensions on the server.
php-mysql: Connects PHP to MySQL database sources.php-gd: Used for image manipulation.php-xml: Enables XML file support in PHP applications.php-zip: Enables ZIP compression support in PHP applications.php-mbstring: Handles multistring data in PHP applications.php-curl: Allows PHP applications to create connections to external APIsphp-json: Enables JSON encoding and decoding in PHP applications.PHP-FPM (FastCGI Process Manager) is a high-performance process manager for PHP that efficiently handles connections between PHP and other applications or services. PHP-FPM enables efficient and scalable connections between PHP and other applications using a UNIX socket or port. It's available as a separate module and is not installed with PHP directly. Follow the steps below to install PHP 7.4 FPM on Ubuntu 24.04 to optimize and handle PHP connections.
Update the APT package information index.
Install PHP 7.4 FPM.
Enable the PHP 7.4 FPM service to start at boot.
Start the PHP 7.4 FPM service.
Check the PHP 7.4 FPM status and verify that it's active and running.
Output:
PHP 7.4 FPM uses pools to configure the PHP process information, enable and optimize PHP connections with other applications. Follow the steps below to configure PHP 7.4 pools and test the connection to PHP on Ubuntu 24.04.
List the files in the /etc/php/7.4/fpm/ directory and verify that the php-fpm.conf file is available.
Output:
The /etc/php/7.4/fpm directory is the main configuration directory for PHP 7.4 FPM that includes the pool and configuration information. The php-fpm.conf file includes the main configuration information and links to the pool.d directory which includes pool configurations.
Open the www.conf default configuration using a text editor such as vim.
Verify the [www] pool configuration name.
Verify the user and group configuration the pool runs as.
PHP-FPM uses the www-data user and group to run on the server by default. Specifying a different user allows PHP-FPM to run and interact with other applications.
Locate and verify the default listen configuration.
The default configuration specifies the UNIX socket used to handle PHP connections on the server. Specifying an IP address like 127.0.0.1:9000 enables PHP FPM to listen for connections using a TCP port and address.
Find additional configurations, including pm to modify how PHP FPM handles connections on the server.
Save the www.conf file and close the text editor to save the pool configuration changes.
Create new configurations in the pool.d directory to set up additional custom pool configurations with the .conf extension to handle PHP connections on the server.
Restart PHP 7.4 FPM to apply the pool configuration changes.
Follow the steps below to create a sample PHP application and test PHP 7.4 on your Ubuntu 24.04 server.
Test the active PHP version and verify that it's 7.4.
Or, run php7.4 -v if multiple versions are installed.
Output:
Create an app.php test application file.
Enter the following PHP code into the file.
Save the app.php file and close the text editor.
The PHP code in the above file displays a Greetings from Vultr message when it runs.
Run the app.php application using PHP.
Verify that the PHP application runs without any errors in your output.
You have installed PHP 7.4 on Ubuntu 24.04 and configured it to run using PHP FPM pools. You can use PHP 7.4 with most dynamic applications and install additional modules enables you to integrate PHP with other services, including Nginx, and MySQL, to process requests depending on your project needs.
0 Comments
Be the first to comment and share your perspective with the community.