One place for hosting & domains

      Comment configurer Apache HTTP avec MPM Event et PHP-FPM sur Ubuntu 18.04


      L’auteur a choisi le COVID-19 Relief Fund pour recevoir un don dans le cadre du programme Write for DOnations.

      Introduction

      Au fil des années, le serveur Web Apache HTTP a évolué. Il fonctionne aujourd’hui dans différents environnements et répond à différents besoins. Comme tout serveur Web, un des problèmes importants qu’Apache HTTP doit résoudre est de savoir de quelle manière gérer différents processus pour servir une requête de protocole http. Cela implique d’ouvrir une socket, de traiter la requête, de maintenir la connexion ouverte pendant une certaine période, de gérer les nouveaux événements se produisant via cette connexion et de renvoyer le contenu produit par un programme créé dans un langage particulier (comme PHP, Perl ou Python). Ces tâches sont effectuées et contrôlées par un Multi-Processing Module (MPM).

      Apache HTTP est livré avec trois MPM différents :

      • Pre-fork : un nouveau processus est créé pour chaque connexion entrante atteignant le serveur. Chaque processus est isolé des autres. Donc, même s’ils effectuent des appels identiques à un certain moment, ils ne partagent aucune mémoire. Il s’agit d’un moyen sûr d’exécuter des applications liées à des bibliothèques qui ne prennent pas en charge le threading, généralement des applications ou des bibliothèques plus anciennes.
      • Worker : un processus parent a pour responsabilité de lancer un pool de processus enfants, certains écoutant les nouvelles connexions entrantes et d’autres servant le contenu demandé. Chaque processus est threadé (un seul thread pour gérer une connexion), donc un processus peut gérer plusieurs requêtes simultanément. Cette méthode de traitement des connexions permet une meilleure utilisation des ressources, tout en maintenant la stabilité. Cela est permis grâce au pool de processus disponibles, qui dispose souvent de threads gratuits prêts à servir de nouvelles connexions immédiatement.
      • Event : en fonction du travailleur, ce MPM va plus loin en optimisant la façon dont le processus parent planifie les tâches pour les processus enfants et les threads qui y sont associés. Par défaut, une connexion reste ouverte pendant 5 secondes. Si aucun nouvel événement ne se produit, elle se ferme. Il s’agit de la valeur par défaut de la directive keep-alive, qui conserve le thread qui lui est associé. Le MPM Event permet au processus de gérer les threads afin que certains soient libres de gérer les nouvelles connexions entrantes tandis que d’autres sont liés aux connexions actives. En autorisant ainsi la redistribution des tâches affectées aux threads, l’utilisation des ressources et les performances sera optimisée.

      Le module MPM Event est un module de multi-traitement rapide disponible sur le serveur Web Apache HTTP.

      PHP-FPM est le Gestionnaire de processus FastCGI pour PHP. Le protocole FastCGI est basé sur la Common Gateway Interface (CGI), un protocole qui se situe entre les applications et les serveurs Web comme Apache HTTP. Cela permet aux développeurs d’écrire des applications indépendamment du comportement des serveurs Web. Les programmes exécutent leurs processus de manière indépendante et transmettent leur produit au serveur Web via ce protocole. Chaque nouvelle connexion qui devra être traitée par une application qui créera un nouveau processus.

      En combinant MPM Event dans Apache HTTP et le Gestionnaire de processus PHP FastCGI (PHP-FPM), le chargement d’un site Web se fait plus rapidement et il pourra gérer un plus grand nombre de connexions simultanées tout en utilisant moins de ressources.

      Dans ce tutoriel, vous améliorerez les performances de la pile LAMP en remplaçant le module de multi-traitement par défaut de pré-fork par un événement et en utilisant le gestionnaire de processus PHP-FPM pour gérer le code PHP au lieu du mod_php traditionnel d’Apache HTTP.

      Conditions préalables

      Avant de commencer ce guide, vous aurez besoin des éléments suivants :

      Étape 1 – Changement du module multi-traitement

      Ubuntu hérite de scripts pour activer ou désactiver les modules HTTP Apache de sa distribution parente, Debian. Vous utiliserez cet ensemble d’outils dans cette étape pour désactiver le module Pre-fork et activer le module Event.

      Au cours cette étape, vous allez arrêter Apache HTTP, désactiver le module PHP 7.2 lié au module Pre-fork, puis désactiver Pre-fork pour activer immédiatement le module Event.

      Vous allez tout d’abord arrêter le service HTTP Apache :

      • sudo systemctl stop apache2

      Vous pouvez maintenant désactiver le module PHP 7.2, qui est lié au module Pre-fork :

      Ensuite, désactivez le module Pre-fork MPM :

      • sudo a2dismod mpm_prefork

      Maintenant, activez le module Event MPM :

      Vous avez changé le MPM de pre-fork en event et supprimé la connexion du module PHP 7.2 entre PHP et Apache HTTP. À l’étape suivante, vous installerez le module php-fpm, ainsi que les bibliothèques et modules proxy associés. Vous allez configurer Apache HTTP pour qu’il puisse également communiquer avec PHP.

      Étape 2 – Configuration d’Apache HTTP pour utiliser le Gestionnaire de processus FastCGI

      À ce stade, vous avez changé la méthode de traitement des connexions d’Apache HTTP en déplaçant de Pre-fork MPM à Event. Cependant, au cours du processus, vous avez désactivé le module PHP qui connectait Apache HTTP à tout programme fonctionnant sur PHP.

      Au cours de cette étape, vous allez installer le processeur PHP-FPM pour permettre à Apache HTTP de traiter à nouveau les programmes PHP. Vous installerez également les bibliothèques de dépendances et activerez les modules afin que les deux puissent coopérer avec fluidité et plus rapidement qu’auparavant.

      Tout d’abord, installez php-fpm. La commande suivante installera le package PHP-FPM et activera automatiquement le service php7.2-fpm intégré à systemd, de sorte que le service se lance au démarrage :

      Pour communiquer, Apache HTTP et PHP ont besoin d’une bibliothèque permettant cette capacité. Vous allez maintenant installer libapache2-mod-fcgid. Il peut servir d’interface entre des programmes avec des serveurs Web et il est spécifique à Apache HTTP. Cette communication se produira via une socket UNIX.

      Installez cette bibliothèque :

      • sudo apt install libapache2-mod-fcgid

      Vous avez installé php-fpm et la libapache2-mod-fcgid, mais aucune des deux n’est encore activée.

      Tout d’abord, activez le module php-fpm avec la commande suivante :

      Ensuite, activez le module proxy d’Apache HTTP :

      Pour finir, activez le module proxy FastCGI dans Apache HTTP :

      Note : vous pouvez lire la configuration de cette interaction entre les programmes PHP et Apache HTTP via une socket UNIX avec ce qui suit :

      • cat /etc/apache2/conf-enabled/php7.2-fpm.conf

      Tout est maintenant en place pour démarrer Apache HTTP. Vous allez tout d’abord procéder à un contrôle de configuration :

      • sudo apachectl configtest

      Output

      Syntax OK

      Après cela, vous pouvez redémarrer Apache HTTP, puisqu’il a été démarré automatiquement lors de l’installation de la bibliothèque FastCGI libapache2-mod-fcgid :

      • sudo systemctl restart apache2

      Vous avez installé le module php-fpm, configuré Apache HTTP pour fonctionner avec lui, activé les modules nécessaires pour que le protocole FastCGI fonctionne et démarre les services correspondants.

      Maintenant qu’Apache a activé le module Event MPM et que PHP-FPM est présent et en cours d’exécution, il est temps de vérifier si tout fonctionne comme prévu.

      Étape 3 – Vérification de votre configuration

      Vous allez exécuter ces tests afin de vérifier que les modifications de configuration ont bien été appliquées. Le premier test consiste à vérifier quel module multi-traitement Apache HTTP utilise. Le second à vérifier que PHP utilise le gestionnaire FPM.

      Vérifiez le serveur Apache HTTP en exécutant la commande suivante :

      • sudo apachectl -M | grep 'mpm'

      Votre sortie sera la suivante :

      Output

      mpm_event_module (shared)

      Vous pouvez refaire la même chose pour le module proxy et FastCGI :

      • sudo apachectl -M | grep 'proxy'

      Le résultat sera :

      Output

      proxy_module (shared) proxy_fcgi_module (shared)

      Pour voir la liste complète des modules, vous pouvez supprimer la deuxième partie de la commande après -M.

      Il est maintenant temps de vérifier si PHP utilise le Gestionnaire de processus FastCGI. Pour cela, vous allez écrire un petit script PHP qui vous donnera toutes les informations liées à PHP.

      Exécutez la commande suivante pour écrire un fichier nommé de la manière suivante :

      • sudo nano /var/www/your_domain/info.php

      Ajoutez le contenu suivant dans le fichier info.php :

      info.php

      <?php phpinfo(); ?>
      

      Maintenant, naviguez vers l’URL de votre serveur et ajoutez info.php à la fin comme ceci : http://your_domain/info.php.

      L’entrée API du serveur sera FPM/FastCGI.

      PHP balaye l'entrée de l'API du serveur FPM/FastCGI

      Supprimez le fichier info.php après cette vérification afin qu’aucune information ne puisse être divulguée publiquement sur le serveur :

      • sudo rm /var/www/yourdomain.com/info.php

      Vous avez vérifié l’état de fonctionnement du module MPM, les modules gérant le FastCGI et le traitement du code PHP.

      Conclusion

      Vous avez optimisé votre pile LAMP d’origine,en augmentant ainsi le nombre de connexions pour créer de nouveaux processus HTTP Apache. PHP-FPM permettra de traiter le code PHP plus efficacement et l’utilisation globale des ressources est meilleure.

      Pour plus d’informations sur les différents modules et les projets associés, consultez la documentation sur le projet de serveur Apache HTTP.



      Source link

      How To Configure Apache HTTP with MPM Event and PHP-FPM on Ubuntu 18.04


      The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      The Apache HTTP web server has evolved through the years to work in different environments and solve different needs. One important problem Apache HTTP has to solve, like any web server, is how to handle different processes to serve an http protocol request. This involves opening a socket, processing the request, keeping the connection open for a certain period, handling new events occurring through that connection, and returning the content produced by a program made in a particular language (such as PHP, Perl, or Python). These tasks are performed and controlled by a Multi-Processing Module (MPM).

      Apache HTTP comes with three different MPM:

      • Pre-fork: A new process is created for each incoming connection reaching the server. Each process is isolated from the others, so no memory is shared between them, even if they are performing identical calls at some point in their execution. This is a safe way to run applications linked to libraries that do not support threading—typically older applications or libraries.
      • Worker: A parent process is responsible for launching a pool of child processes, some of which are listening for new incoming connections, and others are serving the requested content. Each process is threaded (a single thread can handle one connection) so one process can handle several requests concurrently. This method of treating connections encourages better resource utilization, while still maintaining stability. This is a result of the pool of available processes, which often has free available threads ready to immediately serve new connections.
      • Event: Based on worker, this MPM goes one step further by optimizing how the parent process schedules tasks to the child processes and the threads associated to those. A connection stays open for 5 seconds by default and closes if no new event happens; this is the keep-alive directive default value, which retains the thread associated to it. The Event MPM enables the process to manage threads so that some threads are free to handle new incoming connections while others are kept bound to the live connections. Allowing re-distribution of assigned tasks to threads will make for better resource utilization and performance.

      The MPM Event module is a fast multi-processing module available on the Apache HTTP web server.

      PHP-FPM is the FastCGI Process Manager for PHP. The FastCGI protocol is based on the Common Gateway Interface (CGI), a protocol that sits between applications and web servers like Apache HTTP. This allows developers to write applications separately from the behavior of web servers. Programs run their processes independently and pass their product to the web server through this protocol. Each new connection in need of processing by an application will create a new process.

      By combining the MPM Event in Apache HTTP with the PHP FastCGI Process Manager (PHP-FPM) a website can load faster and handle more concurrent connections while using fewer resources.

      In this tutorial you will improve the performance of the LAMP stack by changing the default multi-processing module from pre-fork to event and by using the PHP-FPM process manager to handle PHP code instead of the classic mod_php in Apache HTTP.

      Prerequisites

      Before you begin this guide you’ll need the following:

      Step 1 — Changing the Multi-Processing Module

      Ubuntu inherits scripts to enable or disable Apache HTTP modules from its parent distribution, Debian. You’ll use this toolset in this step to disable the Pre-fork module and enable the Event module.

      In this step you will stop Apache HTTP, disable the PHP 7.2 module linked to the Pre-fork module, and then disable Pre-fork to immediately enable the Event module.

      First you’ll stop the Apache HTTP service:

      • sudo systemctl stop apache2

      Now you can disable the PHP 7.2 module, which is related to the Pre-fork module:

      Then disable the Pre-fork MPM module:

      • sudo a2dismod mpm_prefork

      Now enable the Event MPM module:

      You’ve switched the MPM from pre-fork to event and removed the PHP 7.2 module connection between PHP and Apache HTTP. In the next step you’ll install the php-fpm module, as well as the related libraries and proxy modules. You’ll configure Apache HTTP so that it can communicate with PHP too.

      Step 2 — Configuring Apache HTTP to Use the FastCGI Process Manager

      At this stage you’ve switched the way Apache HTTP processes connections by moving from the Pre-fork MPM to Event. However along the way you’ve disabled the PHP module that connected Apache HTTP with any program running on PHP.

      In this step you’ll install the PHP-FPM processor so Apache HTTP is again able to process PHP programs. And you’ll also install the dependency libraries and enable the modules so both can cooperate smoothly and quicker than before.

      First install php-fpm. The following command will install the PHP-FPM package and it will automatically enable the php7.2-fpm service integrated with systemd, so the service is started at boot time:

      In order to communicate, Apache HTTP and PHP need a library enabling that capacity. You’ll now install libapache2-mod-fcgid, which is able to serve as an interface between programs with web servers, and it’s specific to Apache HTTP. This communication will happen through a UNIX socket.

      Install this library:

      • sudo apt install libapache2-mod-fcgid

      You’ve installed php-fpm and the libapache2-mod-fcgid, but neither are enabled yet.

      First enable the php-fpm module with the following command:

      Second enable Apache HTTP proxy module:

      Third enable the FastCGI proxy module in Apache HTTP:

      Note: You can read the configuration of this interaction between PHP programs and Apache HTTP through a UNIX socket with the following:

      • cat /etc/apache2/conf-enabled/php7.2-fpm.conf

      Everything is now in place so you can start Apache HTTP. You’ll make a configuration check first:

      • sudo apachectl configtest

      Output

      Syntax OK

      After that you can proceed to restart Apache HTTP, since it was automatically started when installing the FastCGI library libapache2-mod-fcgid:

      • sudo systemctl restart apache2

      You’ve installed the php-fpm module, configured Apache HTTP to work with it, enabled the necessary modules for the FastCGI protocol to work, and started the corresponding services.

      Now that Apache has the Event MPM module enabled and PHP-FPM is present and running, it is time to check everything is working as intended.

      Step 3 — Checking Your Configuration

      In order to check that the configuration changes have been applied you’ll run some tests. The first one will check what multi-processing module Apache HTTP is using. The second will verify that PHP is using the FPM manager.

      Check the Apache HTTP server by running the following command:

      • sudo apachectl -M | grep 'mpm'

      Your output will be as follows:

      Output

      mpm_event_module (shared)

      You can repeat the same for the proxy module and FastCGI:

      • sudo apachectl -M | grep 'proxy'

      The output will show:

      Output

      proxy_module (shared) proxy_fcgi_module (shared)

      If you would like to see the entire list of the modules, you can remove the the second part of the command after -M.

      It is now time to check if PHP is using the FastCGI Process Manager. To do so you’ll write a small PHP script that will show you all the information related to PHP.

      Run the following command to write a file named as follows:

      • sudo nano /var/www/your_domain/info.php

      Add the following content into the info.php file:

      info.php

      <?php phpinfo(); ?>
      

      Now visit your server’s URL and append info.php at the end like so: http://your_domain/info.php.

      The server API entry will be FPM/FastCGI.

      PHP Screen the Server API entry FPM/FastCGI

      Delete the info.php file after this check so no information about the server is publicly disclosed:

      • sudo rm /var/www/yourdomain.com/info.php

      You’ve checked the working status of the MPM module, the modules handling the FastCGI and the handling of PHP code.

      Conclusion

      You’ve optimized your original LAMP stack, so the number of connections to create new Apache HTTP processes has increased, PHP-FPM will handle PHP code more efficiently, and overall resource utilization has improved.

      See the Apache HTTP server project documentation for more information on the different modules and related projects.



      Source link

      How To Configure Apache HTTP with MPM Event and PHP-FPM on FreeBSD 12.0


      The author selected the Open Internet/Free Speech Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      The Apache HTTP web server has evolved through the years to work in different environments and solve different needs. One important problem Apache HTTP has to solve, like any web server, is how to handle different processes to serve an http protocol request. This involves opening a socket, processing the request, keeping the connection open for a certain period, handling new events occurring through that connection, and returning the content produced by a program made in a particular language (such as PHP, Perl, or Python). These tasks are performed and controlled by a Multi-Processing Module (MPM).

      Apache HTTP comes with three different MPM:

      • Pre-fork: A new process is created for each incoming connection reaching the server. Each process is isolated from the others, so no memory is shared between them, even if they are performing identical calls at some point in their execution. This is a safe way to run applications linked to libraries that do not support threading—typically older applications or libraries.
      • Worker: A parent process is responsible for launching a pool of child processes, some of which are listening for new incoming connections, and others are serving the requested content. Each process is threaded (a single thread can handle one connection) so one process can handle several requests concurrently. This method of treating connections encourages better resource utilization, while still maintaining stability. This is a result of the pool of available processes, which often has free available threads ready to immediately serve new connections.
      • Event: Based on worker, this MPM goes one step further by optimizing how the parent process schedules tasks to the child processes and the threads associated to those. A connection stays open for 5 seconds by default and closes if no new event happens; this is the keep-alive directive default value, which retains the thread associated to it. The Event MPM enables the process to manage threads so that some threads are free to handle new incoming connections while others are kept bound to the live connections. Allowing re-distribution of assigned tasks to threads will make for better resource utilization and performance.

      The MPM Event module is a fast multi-processing module available on the Apache HTTP web server.

      PHP-FPM is the FastCGI Process Manager for PHP. The FastCGI protocol is based on the Common Gateway Interface (CGI), a protocol that sits between applications and web servers like Apache HTTP. This allows developers to write applications separately from the behavior of web servers. Programs run their processes independently and pass their product to the web server through this protocol. Each new connection in need of processing by an application will create a new process.

      By combining the MPM Event in Apache HTTP with the PHP FastCGI Process Manager (PHP-FPM) a website can load faster and handle more concurrent connections while using fewer resources.

      In this tutorial you will improve the performance of the FAMP stack by changing the default multi-processing module from pre-fork to event and by using the PHP-FPM process manager to handle PHP code instead of the classic mod_php in Apache HTTP.

      Prerequisites

      Before you begin this guide you’ll need the following:

      • A FreeBSD 12.0 server set up following this guide.
      • The FAMP stack installed on your server following this tutorial.
      • Access to a user with root privileges (or allowed by using sudo) in order to make configuration changes.

      Step 1 — Changing the Multi-Processing Module

      You’ll begin by looking for the pre-fork directive in the httpd.conf file. This is the main configuration file for Apache HTTP in which you can enable and disable modules. You can edit and set directives such as the listening port where Apache HTTP will serve content or the location of the content to display in this file.

      To make these changes, you’ll use the nl, number line, program, with the -ba flag to count and number lines so that nothing is mismatched at a later stage. Combined with grep this command will first count all the lines in the file specified in the path, and once finished, it will search for the string of characters you’re looking for.

      Run the following command so that the nl program will process and number the lines in httpd.conf. Then, grep will process the output by searching for the given string of characters 'mod_mpm_prefork':

      • nl -ba /usr/local/etc/apache24/httpd.conf | grep 'mod_mpm_prefork'

      As output you’ll see something similar to:

      Output

      67 LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so

      Let’s edit line 67 with your text editor. In this tutorial, you’ll use vi, which is the default editor on FreeBSD:

      • sudo vi +67 /usr/local/etc/apache24/httpd.conf

      Append a # symbol at the beginning of the line so this line is commented out, like so:

      /usr/local/etc/apache24/httpd.conf

      ...
      # LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so
      ...
      

      By appending the # symbol you’ve disabled the pre-fork MPM module.

      Now you’ll find the event directive in the same httpd.conf file.

      • nl -ba /usr/local/etc/apache24/httpd.conf | grep mpm_event

      You’ll see output similar to the following:

      Output

      ... 66 #LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so ...

      Now you’ll remove the # symbol in line 66 to enable the Event MPM:

      • sudo vi +66 /usr/local/etc/apache24/httpd.conf

      The directive will now read as follows:

      /usr/local/etc/apache24/httpd.conf

      ...
      LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so
      ...
      

      Now that you’ve switched the configuration from the MPM pre-fork to event, you can remove the mod_php73 package connecting the PHP processor to Apache HTTP, since it is no longer necessary and will interfere if it remains on the system:

      • sudo pkg remove -y mod_php73

      Make sure the configuration is correct by running the following command to test:

      • sudo apachectl configtest

      If you see Syntax OK in your output, you can restart the Apache HTTP server:

      Note: If there are other running HTTP connections on your server a graceful restart is recommended instead of a regular restart. This will ensure that users are not pushed out, losing their connection:

      You've switched the MPM from pre-fork to event and removed the mod_php73 module connection PHP to Apache HTTP. In the next step you'll install the PHP-FPM module and configure Apache HTTP so that it can communicate with PHP more quickly.

      Step 2 — Configuring Apache HTTP to Use the FastCGI Process Manager

      FreeBSD has several supported versions of PHP that you can install via the package manager. On FreeBSD different binaries of the various available versions are compiled instead of using just one like most GNU/Linux distributions offer in their default repositories. To follow best practice you'll use the supported version, which you can check on at PHP's supported versions page.

      In this step you'll add PHP-FPM as a running service to start at boot. You'll also configure Apache HTTP to work with PHP by adding a dedicated configuration for the module as well as enabling some further modules in httpd.conf.

      First you'll append 'php_fpm_enable=YES' to the /etc/rc.conf file so the PHP-FPM service can start. You'll do that by using the sysrc command:

      • sudo sysrc php_fpm_enable="YES"

      Now you'll add the php-fpm module into the Apache module's directory, so it is configured to be used by Apache HTTP. Create the following file to do so:

      • sudo vi /usr/local/etc/apache24/modules.d/030_php-fpm.conf

      Add the following into 030_php-fpm.conf:

      /usr/local/etc/apache24/modules.d/030_php-fpm.conf

      <IfModule proxy_fcgi_module>
          <IfModule dir_module>
              DirectoryIndex index.php
          </IfModule>
          <FilesMatch ".(php|phtml|inc)$">
              SetHandler "proxy:fcgi://127.0.0.1:9000"
          </FilesMatch>
      </IfModule>
      

      This states that if the module 'proxy_fcgi' is enabled as well as the 'dir_module' then any processed files matching the extensions in parentheses should be handled by the FastCGI process manager running on the local machine through port 9000—as if the local machine were a proxy server. This is where the PHP-FPM module and Apache HTTP interconnect. To achieve this, you'll activate further modules during this step.

      To enable the proxy module, you'll first search for it in the httpd.conf file:

      • nl -ba /usr/local/etc/apache24/httpd.conf | grep mod_proxy.so

      You'll see output similar to the following:

      Output

      ... 129 #LoadModule proxy_module libexec/apache24/mod_proxy.so ...

      You'll uncomment the line by removing the # symbol:

      • sudo vi +129 /usr/local/etc/apache24/httpd.conf

      The line will look as follows once edited:

      /usr/local/etc/apache24/httpd.conf

      ...
      LoadModule proxy_module libexec/apache24/mod_proxy.so
      ...
      

      Now you can activate the FastCGI module. Find the module with the following command:

      • nl -ba /usr/local/etc/apache24/httpd.conf | grep mod_proxy_fcgi.so

      You'll see something similar to the following:

      Output

      ... 133 #LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so ...

      Now uncomment the line 133 as you've already done with the other modules:

      • sudo vi +133 /usr/local/etc/apache24/httpd.conf

      You'll leave the line as follows:

      /usr/local/etc/apache24/httpd.conf

      ...
      LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so
      ...
      

      Once this is done you'll start the PHP-FPM service:

      • sudo service php-fpm start

      And you'll restart Apache so it loads the latest configuration changes incorporating the PHP module:

      You've installed the PHP-FPM module, configured Apache HTTP to work with it, enabled the necessary modules for the FastCGI protocol to work, and started the corresponding services.

      Now that Apache has the Event MPM module enabled and PHP-FPM is present and running, it is time to check everything is working as intended.

      Step 3 — Checking Your Configuration

      In order to check that the configuration changes have been applied you'll run some tests. The first one will check what multi-processing module Apache HTTP is using. The second will verify that PHP is using the FPM manager.

      Check the Apache HTTP server by running the following command:

      • sudo apachectl -M | grep 'mpm'

      Your output will be as follows:

      Output

      mpm_event_module (shared)

      You can repeat the same for the proxy module and FastCGI:

      • sudo apachectl -M | grep 'proxy'

      The output will show:

      Output

      proxy_module (shared) proxy_fcgi_module (shared)

      If you would like to see the entire list of the modules, you can remove the the second part of the command after -M.

      It is now time to check if PHP is using the FastCGI Process Manager. To do so you'll write a very small PHP script that will show you all the information related to PHP.

      Run the following command to write a file named as follows:

      • sudo vi /usr/local/www/apache24/data/info.php

      Add the following content into the info.php file:

      info.php

      <?php phpinfo(); ?>
      

      Now visit your server's URL and append info.php at the end like so: http://your_server_IP_address/info.php.

      The Server API entry will be FPM/FastCGI.

      PHP Screen the Server API entry FPM/FastCGI

      Remember to delete the info.php file after this check so no information about the server is publicly disclosed.

      • sudo rm /usr/local/www/apache24/data/info.php

      You've checked the working status of the MPM module, the modules handling the FastCGI, and the handling of PHP code.

      Conclusion

      You've optimized your original FAMP stack, so the number of connections to create new Apache HTTP processes has increased, PHP-FPM will handle PHP code more efficiently, and overall resource utilization has improved.

      See the Apache HTTP server project documentation for more information on the different modules and related projects.



      Source link