{"id":104596,"date":"2022-09-22T11:00:27","date_gmt":"2022-09-22T04:00:27","guid":{"rendered":"https:\/\/harianaceh.co.id\/?p=104596"},"modified":"2023-09-09T12:10:20","modified_gmt":"2023-09-09T05:10:20","slug":"steps-to-set-up-apache-with-mpm-event-and-php-fpm-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.harianaceh.co.id\/2022\/09\/22\/steps-to-set-up-apache-with-mpm-event-and-php-fpm-on-ubuntu-20-04\/","title":{"rendered":"Steps to Set Up Apache with MPM Event and PHP-FPM on Ubuntu 20.04"},"content":{"rendered":"<p><span class=\"dropcap shadow\" style=\"color: #000000; border-color: #ffffff;\"><span class=\"dropcap\">A<\/span><\/span>PACHE is free, open-source, and the most widely used web server, largely because it is capable of working in different environments. <a title=\"Apache\" href=\"https:\/\/www.harianaceh.co.id\/tag\/apache\/\">Apache<\/a> has the ability to manage different processes to serve an HTTP protocol request including processing the request, opening a socket, and handling new events.<\/p>\n<p>These tasks are performed by the Apache Multi-Processing Module (MPM).<\/p>\n<p>Apache MPM (Multi-Processing Modules) are Apache modules used for creating child processes in Apache. They allow more requests to be served simultaneously by passing off some processing work to listener threads, freeing up worker threads to serve new requests. Using PHP-FPM with MPM Event in an Apache webserver decreases the website page loading time and allows the webserver to handle more concurrent connections.<\/p>\n<p>In this tutorial, we will learn how to configure Apache with MPM Event and PHP-FPM on Ubuntu 20.04.<\/p>\n<h4 id=\"h-prerequisites\">Prerequisites<\/h4>\n<ul>\n<li>A fresh Ubuntu 20.04\u00a0VPS\u00a0on the Atlantic.Net Cloud Platform<\/li>\n<li>A root password configured on your server<\/li>\n<\/ul>\n<h3 id=\"h-step-1-create-atlantic-net-cloud-server\">Step 1 \u2013 Create a Cloud Server<\/h3>\n<p>First, log in to your Cloud Server.\u00a0 Create a new\u00a0server, choosing Ubuntu 20.04 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.<\/p>\n<p>Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.<\/p>\n<pre>apt-get update -y<\/pre>\n<h3 id=\"h-step-2-install-lamp-server\">Step 2 \u2013 Install LAMP Server<\/h3>\n<p>First, install the Apache web server, MariaDB, and PHP with the following command:<\/p>\n<pre class=\"wp-block-preformatted\">apt-get install apache2 mariadb-server php7.4 libapache2-mod-php7.4 -y<\/pre>\n<p>Once the LAMP server is installed, you can proceed to the next step.<\/p>\n<h3 id=\"h-step-3-change-the-multi-processing-module\">Step 3 \u2013 Change the Multi-Processing Module<\/h3>\n<p>Before starting, you will need to switch the MPM from pre-fork to event and remove the php7.4 module connection between PHP and Apache.<\/p>\n<p>First, stop the Apache service and disable the php7.4 module with the following command:<\/p>\n<pre>systemctl stop apache2\r\na2dismod php7.4<\/pre>\n<p>Next, disable the Pre-fork MPM module with the following command:<\/p>\n<pre>a2dismod mpm_prefork<\/pre>\n<p>Next, enable the Event MPM module with the following command:<\/p>\n<pre>a2enmod mpm_event<\/pre>\n<p>Once you are finished, you can proceed to the next step.<\/p>\n<h3 id=\"h-step-4-configure-apache-to-use-the-fastcgi-process-manager\">Step 4 \u2013 Configure Apache to Use the FastCGI Process Manager<\/h3>\n<p>In this section, we will install the PHP-FPM processor and proxy modules so Apache can communicate with PHP.<\/p>\n<p>First, install the PHP-FPM with the following command:<\/p>\n<pre>apt-get install php7.4-fpm -y<\/pre>\n<p>Once installed, you will need to install libapache2-mod-fcgid library in order to communicate Apache and PHP.<\/p>\n<p>You can install it with the following command:<\/p>\n<pre>apt-get install libapache2-mod-fcgid -y<\/pre>\n<p>Once installed, you will need to enable the PHP-FPM, Proxy and FastCGI Proxy module in Apache webserver.<\/p>\n<p>You can enable them with the following command:<\/p>\n<pre>a2enconf php7.4-fpm\r\na2enmod proxy\r\na2enmod proxy_fcgi<\/pre>\n<p>Next, restart the Apache service to apply the changes:<\/p>\n<pre>systemctl restart apache2<\/pre>\n<p>Now, verify the MPM module with the following command:<\/p>\n<pre class=\"wp-block-preformatted\">apachectl -M | grep 'mpm'<\/pre>\n<p>You should get the following output:<\/p>\n<pre>mpm_event_module (shared)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-104603 alignnone\" src=\"https:\/\/www.harianaceh.co.id\/media\/2022\/09\/Apache-MPM-Event.png\" alt=\"Apache MPM Event\" width=\"282\" height=\"29\" \/><\/p>\n<p>Next, verify the Proxy and FastCGI Proxy module with the following command:<\/p>\n<pre>apachectl -M | grep 'proxy'<\/pre>\n<p>You should get the following output:<\/p>\n<pre>\u00a0proxy_module (shared)\r\n\u00a0proxy_fcgi_module (shared)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-104602\" src=\"https:\/\/www.harianaceh.co.id\/media\/2022\/09\/Apache-MPM-FCGI.jpg\" alt=\"Apache MPM FCGI\" width=\"291\" height=\"41\" \/><\/p>\n<h3 id=\"h-step-5-verify-fastcgi-process-manager\">Step 5 \u2013 Verify FastCGI Process Manager<\/h3>\n<p>At this point, Apache web server is configured to use the FastCGI Process Manager. It\u2019s time to verify if PHP is using the FastCGI Process Manager.<\/p>\n<p>First, create an info.php file inside the Apache document root directory:<\/p>\n<pre>nano \/var\/www\/html\/info.php<\/pre>\n<p>Add the following lines:<\/p>\n<pre><\/pre>\n<p>Save and close the file when you are finished.<\/p>\n<p>Next, open your web browser and type the URL\u00a0<a target=\"_blank\" rel=\"noopener noreferrer\" class=\"vglnk\" href=\"http:\/\/your-server-ip\/info.php\" rel=\"nofollow\">http:\/\/your-server-ip\/info.php<\/a>. You should see the following screen:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-104604\" src=\"https:\/\/www.harianaceh.co.id\/media\/2022\/09\/PHP-Info.png\" alt=\"apache\" width=\"943\" height=\"520\" \/><\/p>\n<p>In the above page, you should see that Apache web server is using FPM\/FastCGI.<\/p>\n<h3 id=\"h-conclusion\">Conclusion<\/h3>\n<p>In the above guide, we learned how to configure Apache with MPM Event and PHP-FPM on Ubuntu 20.04. Now, PHP-FPM will handle the PHP code and improve overall resource utilization.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache is free, open-source, and the most widely used web server, largely because it is capable of working in different environments. Apache has the ability to manage different processes to serve an HTTP protocol request including processing the request, opening a socket, and handling new events<\/p>\n","protected":false},"author":1,"featured_media":104605,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_disable_autopaging":false},"categories":[61,98452],"tags":[58638,71190,71192,92187,92188,92189,92190],"series":[],"class_list":["post-104596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-teknologi","category-tutorial","tag-ubuntu","tag-how-to","tag-ubuntu-20-04","tag-mpm-event","tag-php-fpm","tag-tips","tag-apache"],"_links":{"self":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/posts\/104596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/comments?post=104596"}],"version-history":[{"count":0,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/posts\/104596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/media\/104605"}],"wp:attachment":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/media?parent=104596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/categories?post=104596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/tags?post=104596"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/series?post=104596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}