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.
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.
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 -i | head
That should output something similar to the lines below.
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.
sudo apt install php8.3-fpm
Next, enable the PHP-FPM module.
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
Restart Apache and PHP-FPM.
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.
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].
; 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.
<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.

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?
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.
No comments yet — be the first to share your thoughts!