Setting Up Apache with PHP-FPM on Ubuntu 24.04
Setting up Apache with PHP-FPM on Ubuntu 24.04 makes your website run much faster.
PHP-FPM, which stands for FastCGI Process Manager, is a special tool that helps your web server handle PHP code more efficiently. It manages multiple PHP jobs at once, using your computer’s resources better.
This setup is key for websites that get a lot of visitors or run complex applications. It means your server can deal with requests quicker, giving your visitors a smoother experience.
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
To start, install PHP on your Ubuntu 24.04 server. A quick command does the trick. Then, confirm PHP is set up correctly by checking its version with `php -v`.
After installing PHP, you can check the PHP version using the `php -v` command. You should see output similar to this example: PHP 8.3.6 (cli) (built: May 23 2024 11:34:18) (NTS). This confirms PHP is active and shows its exact version number.
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 now installed, the next step is to install PHP-FPM. Run the command below for this.
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
Now that PHP is installed, the next step is to configure PHP-FPM to work with Apache on Ubuntu 24.04. This involves editing a specific configuration file to tell Apache how to communicate with PHP-FPM. Following these steps will help get Apache with PHP-FPM running properly on Ubuntu 24.04.
First, open the PHP-FPM config file.
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
; 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.
<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 boosts web application performance by allowing Apache to handle more requests simultaneously. This setup separates PHP processing from Apache’s main threads, leading to faster page loads for you.
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!