Skip to content
Follow
Ubuntu Linux

Setting Up Apache with PHP-FPM on Ubuntu 24.04

Richard
Written by
Richard
Feb 24, 2025 Updated Mar 20, 2026 3 min read
Setting Up Apache with PHP-FPM on Ubuntu 24.04
Setting Up Apache with PHP-FPM on Ubuntu 24.04

Setting up Apache with PHP-FPM on Ubuntu 24.04 improves your web server’s PHP performance significantly.

PHP-FPM (FastCGI Process Manager) efficiently handles your PHP scripts by managing multiple PHP processes simultaneously. This manager optimizes resource usage, allowing your server to process requests much faster than traditional PHP handlers.

This setup is crucial for modern web applications that demand high concurrency and responsiveness. By integrating Apache with PHP-FPM on Ubuntu 24.04, you unlock superior resource management and application reliability for your website.

⚡ Quick Answer

Install PHP and PHP-FPM using `apt`. Enable the `proxy_fcgi` module and `php8.3-fpm` configuration with `a2enmod` and `a2enconf`. Restart Apache and PHP-FPM services.

Install PHP

Installing PHP on Ubuntu 24.04 is a key step for running web applications, especially when you want to speed up your site using PHP-FPM with Apache.

After PHP is installed, you can check its version with this command. You should see output similar to this.

🐧Bash / Shell
sudo apt update
sudo apt install php8.3 php-mbstring php-pear

Once PHP is installed, you can check its details by running the command below.

🐘PHP
php -i | head

That should output something similar to the lines below.

🐘PHP
phpinfo()
PHP Version => 8.3.6

System => Linux Ubuntu 6.11.0-17-generic #17~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jan 20 22:48:29 UTC 2 x86_64
Build Date => Dec 2 2024 12:36:18
Build System => Linux
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/8.3/cli
Loaded Configuration File => /etc/php/8.3/cli/php.ini

Install and enable PHP-FPM

With Apache and PHP installed, run the command below to install PHP-FPM.

🐧Bash / Shell
sudo  apt install php8.3-fpm

Next, enable the PHP-FPM module.

🐧Bash / Shell
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm

Restart Apache and PHP-FPM.

🐧Bash / Shell
sudo systemctl restart php8.3-fpm apache2

Use PHP-FPM with Apache

To make PHP-FPM work with Apache on Ubuntu 24.04, you need to adjust its configuration file to listen on the correct network address.

First, open the PHP-FPM config file.

🐧Bash / Shell
sudo nano /etc/php/8.3/fpm/pool.d/www.conf

Then, comment out one of the listen directives. Use the listen directive with [127.0.0.1:9000].

🐘PHP
; Note: This value is mandatory.

;listen = /run/php/php8.3-fpm.sock
listen = 127.0.0.1:9000

Save and exit the file. Restart Apache PHP-FPM after updating the file.

Add the highlighted portion to your virtual host to use PHP-FPM with Apache in your virtual host.

🐘PHP
<VirtualHost *:80>
ServerName example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/example.com

<Directory /var/www/example.com/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

<FilesMatch ".php$">
SetHandler "proxy:fcgi://127.0.0.1:9000/"
</FilesMatch>


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Validate PHP-FPM with Apache support.

Apache with PHP-FPM
Apache with PHP-FPM

That should do it!

Conclusion:

By integrating PHP-FPM with Apache on Ubuntu 24.04, you can enhance the performance and reliability of your PHP applications. Here are the key takeaways:

  • Improved Performance: PHP-FPM allows simultaneous handling of multiple requests, leading to faster response times.
  • Efficient Resource Management: It manages PHP worker pools, optimizing server resource utilization.
  • Enhanced Reliability: With the ability to manage multiple PHP processes, applications become more robust and less prone to failures.
  • Easy Installation: The installation and configuration process is straightforward, allowing for quick setup.
  • Future-Proofing: Keeping PHP and its components updated ensures your server remains secure and efficient.

Implementing PHP-FPM with Apache is a smart choice for anyone looking to boost the performance of their web applications.

Where is PHP-FPM in Ubuntu?

Where can you find PHP-FPM configuration files on Ubuntu? Usually, you’ll find the PHP-FPM pool settings in a path like /etc/php/7.x/fpm/pool.d/.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

Install Symfony 5 on Ubuntu with Apache
Ubuntu Linux Install Symfony 5 on Ubuntu with Apache
How to Install BoxBilling with Apache on Ubuntu Linux
Ubuntu Linux How to Install BoxBilling with Apache on Ubuntu Linux
How to Install Apache Solr on Ubuntu Linux
Ubuntu Linux How to Install Apache Solr on Ubuntu Linux
How to Set System Locale on Ubuntu 24.04
Ubuntu Linux How to Set System Locale on Ubuntu 24.04

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *