
PHP (Hypertext Preprocessor) is a popular general-purpose server-side scripting language for developing dynamic and interactive web applications. PHP-FPM (FastCGI Process Manager) enhances PHP performance to handle heavy loads through advanced process management, worker pools, and more. On Debian 12, a stable and secure Linux distribution, installing PHP and PHP-FPM ensures efficient handling of complex web applications while maximizing server performance.
This article explains how to install PHP and PHP-FPM on Debian 12, helping you create an environment for dynamic and interactive web development. If you're working on different systems, you may also explore our articles on Install PHP and PHP-FPM on Ubuntu 24.04 and Install PHP and PHP-FPM on FreeBSD 14.0.
Before you begin:
PHP is available in the default package repositories on Debian 12, but the available version might be out-of-date. Follow the steps below to download the SURY PHP PPA repository, which includes the latest PHP package information and install PHP 8.3 on Debian 12. While this guide focuses on PHP 8.3, the repository also supports other versions like PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, and the latest PHP 8.4 on Debian 12.
Update the server's package information index.
Upgrade all existing packages.
Install the necessary dependency packages for HTTPS transport and certificate management.
Download the SURY GPG key.
Add the SURY PPA repository information to your APT sources.
Update the server's package information index to apply the repository changes.
View all the available PHP versions in the APT repository sources.
Output:
From the above output, PHP 8.3 is the latest version you can install from the SURY PPA repository.
Install the latest PHP version.
Verify the PHP version.
Output:
PHP extensions add functionalities for running most dynamic web applications. Follow the steps below to install common PHP extensions.
Install PHP extensions.
The above command installs the following PHP extensions:
php-mysql: Connects PHP with MySQL databases.php-curl: Allows PHP to create HTTP requests.php-json: Enables PHP to handle JSON data.php-xml: Enables support for XML data.php-mbstring: Manages multi-byte strings.View the available extensions on your server.
Output:
PHP-FPM (FastCGI Process Manager) manages the connection between PHP and other applications, such as web servers, to process dynamic content. Follow the steps below to install and configure PHP-FPM based on the PHP version on your server.
Install PHP-FPM.
Enable PHP-FPM to automatically start at boot.
Start the PHP-FPM service.
Verify the PHP-FPM service status and verify that it's running.
Output:
Follow the steps below to create a sample application to display the available PHP version information.
Install Apache web server package.
Start the Apache web server.
Create a new info.php PHP application file in the default /var/www/html web root directory.
Add the following contents to the file.
Save and close the file.
Enable the PHP-FPM configuration for Apache.
Output:
Allow network connections to the Apache HTTP port 80 through the firewall.
Reload UFW to apply the new changes.
Open a web browser such as Chrome and access your server's public IP address. Then, load the /info.php file to access the PHP application.
Multiple web development projects may require specific PHP versions to run on your server. Follow the steps below to install multiple PHP versions and use separate PHP-FPM pools to manage each PHP version.
Install PHP 8.0 and common extensions.
Enable PHP-FPM for PHP 8.0 to automatically start at boot.
Start the PHP-FPM service for PHP 8.0.
Install PHP 7.4 and common extensions.
Enable PHP-FPM for PHP 7.4 to start at boot.
Start the PHP-FPM service for PHP 7.4.
Enable the PHP 8.0 FPM configuration for Apache.
Enable the PHP 7.4 FPM configuration.
Restart Apache to apply the configuration changes.
Create a new Apache virtual host configuration file.
Add the following configurations to the file.
Save and close the file.
The above Apache virtual host configuration listens for connection requests on all server interfaces and forwards specific requests to the appropriate PHP-FPM version for processing.
Disable the default Apache virtual host.
Enable the new virtual host.
Enable the necessary Apache proxying and rewrite modules.
Create new directories to store PHP 8.3, PHP 8.0, and PHP 7.4 files.
Create a sample info.php file under the /var/www/html/php83 directory.
Add the following contents to the file.
Save and close the file.
Repeat the above steps and create additional info.php files in the /var/www/html/php80 and /var/www/html/php74 directories.
Open a web browser and access the following paths. Each web page should display the respective PHP version.
PHP Version 8.3:
PHP Version 8.0:
PHP Version 7.4:
You have installed PHP and PHP-FPM on Debian 12. You can integrate PHP with multiple applications to deliver and process dynamic web applications using PHP-FPM pools. For more information, visit the PHP documentation.
0 Comments
Be the first to comment and share your perspective with the community.