• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » How to Install Apache MPM Event and PHP-FPM on Ubuntu Server

By Abhishek Ghosh April 20, 2023 7:22 pm Updated on May 14, 2023

How to Install Apache MPM Event and PHP-FPM on Ubuntu Server

Advertisement

If your production server is running Apache, mod_php and mpm prefork and you want to upgrade to MPM Event and PHP-FPM, then it is just a few steps. For this guide, we have tested the workflow on a server which is running PHP 7.2 (which is an old version). You can follow similar steps for any present version of PHP, only modify the version number. We have tested that restarting the server after the completion of the whole workflow is sufficient. So, even on a production server, the downtime will not be significant.

This guide is for operating a single site on a 16GB dedicated or cloud server.

 

Steps to Install Apache MPM Event and PHP-FPM

 

This command will install all the required components to run PHP-FPM:

Advertisement

---

Vim
1
apt-get -y install apache2-doc apache2-utils libapache2-mod-php php7.2 php7.2-common php7.2-gd php7.2-mysql php7.2-imap php7.2-cli php7.2-cgi libapache2-mod-fcgid apache2-suexec-pristine php-pear mcrypt imagemagick libruby libapache2-mod-python php7.2-curl php7.2-intl php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-xmlrpc php7.2-xsl php-imagick php7.2-gettext php7.2-zip php7.2-mbstring php-soap php7.2-soap php7.2-fpm

Please change the version number of PHP from 7.2 to your version (such as 8.2). You can search the repository for modules for your version of PHP:

Vim
1
apt search php8.2

First, disable the mod_php:

Vim
1
sudo a2dismod php7.2

Next, disable mod prefork:

Vim
1
sudo a2dismod mpm_prefork

Enable mpm_event:

Vim
1
sudo a2enmod mpm_event

Activate the required Apache2 modules:

Vim
1
2
3
4
5
sudo apt install php7.2-fpm
sudo apt install libapache2-mod-fcgid
sudo a2enconf php7.2-fpm
sudo a2enmod proxy
sudo a2enmod proxy_fcgi

Now check the below configuration file:

Vim
1
cat /etc/apache2/conf-enabled/php7.2-fpm.conf

This must not be empty. Run configuration test and restart Apache:

Vim
1
2
sudo apachectl configtest
sudo systemctl restart apache2

Now your site should be running on PHP-FPM.

Vim
1
sudo apachectl -M | grep 'mpm'

output will be as follows:

Vim
1
mpm_event_module (shared)

Check the proxy module and FastCGI:

Vim
1
2
3
4
sudo apachectl -M | grep 'proxy'
## output
# proxy_module (shared)
# proxy_fcgi_module (shared)

Create a PHP info webpage and check from browser:

Vim
1
sudo nano /var/www/html/info.php

Paste this content:

Do not forget to delete this file after checking.

To prevent the server from HTTPOXY attacks, we will create the httpoxy.conf file:

Vim
1
nano /etc/apache2/conf-available/httpoxy.conf

Paste this configuration:

Vim
1
   RequestHeader unset Proxy early

Save the file. Enable the HTTPOXY configuration file and restart Apache:

Vim
1
2
a2enconf httpoxy
sudo systemctl restart apache2

 

Optimizing Apache2 mpm_event and PHP-FPM

 

Open the mpm_event configuration file:

Vim
1
nano /etc/apache2/mods-enabled/mpm_event.conf

Add/modify to reflect the below content:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<IfModule mpm_event_module>
    KeepAlive On
    KeepAliveTimeout 5
    MaxKeepAliveRequests 128
 
    ServerLimit 10
    StartServers 4
    ThreadLimit 128
    ThreadsPerChild 128
    MinSpareThreads 256
    MaxSpareThreads 512
    MaxRequestWorkers 1280
    MaxConnectionsPerChild 2048
</IfModule>
 
Test it:
 
<pre>
cd ~
apt install python
wget https://raw.githubusercontent.com/pixelb/ps_mem/master/ps_mem.py
chmod a+x ps_mem.py
sudo python ps_mem.py

On my test 16GB dedicated server, it was sucking 2GB RAM:

Vim
1
2
3
4
5
6
7
8
9
Private  +   Shared  =  RAM used       Program
 
...
...
113.3 MiB +  11.3 MiB = 124.6 MiB       apache2 (5)
  1.3 GiB + 652.9 MiB =   2.0 GiB       php-fpm7.2 (31)
  3.0 GiB + 390.5 KiB =   3.0 GiB       mysqld
---------------------------------
                          5.3 GiB

Open the PHP-FPM configuration file:

Vim
1
nano /etc/php/7.2/fpm/pool.d/​www.conf

Adjust these parameters:

Vim
1
2
3
4
5
6
pm = dynamic
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.process_idle_timeout = 10s;

You can adjust the values to higher later after reading various documentation and guides available all over the internet. We have tried to deliver a balanced setting.

How to Install Apache MPM Event and PHP-FPM on Ubuntu Server

Restart Apache and PHP-FPM:

Vim
1
2
sudo systemctl restart php7.2-fpm
sudo systemctl restart apache2

Enable HTTP/2 from virtual host file and test it.

Normally, you’ll not need more optimization for running a single domain. To add multiple websites (separated from each other), you have to add a new Apache user, and add a new configuration file at /etc/php/7.2/fpm/pool.d.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Install Apache MPM Event and PHP-FPM on Ubuntu Server

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

    Here is Step by Step Guide on How to Install WordPress on Ubuntu 16.04, Nginx, PHP7-FPM, memcached & Percona MySQL 5.7 on Cloud Server or VPS.

  • How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS

    Here is Detailed Guide on How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS With Commands and Configurations For Most Secured Setup.

  • Fix HTTP/2 NOT Working on Apache 2.4 Running WordPress

    If you have followed older guides to configure the server to install WordPress, then you have followed the guides to install Mod PHP with MPM prefork. presently, the usual mod_php and prefork MPM module of Apache2 does not work with HTTP/2 module. The default prefork MPM is not fully compatible with HTTP/2. If you are […]

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy