One place for hosting & domains

      So konfigurieren Sie Apache HTTP mit MPM Event und PHP-FPM unter Ubuntu 18.04


      Der Autor hat den COVID-19 Relief Fund dazu ausgewählt, eine Spende im Rahmen des Programms Write for DOnations zu erhalten.

      Einführung

      Der Apache-HTTP-Webserver wurde im Laufe der Jahre weiterentwickelt, damit er in verschiedenen Umgebungen arbeitet und verschiedene Anforderungen erfüllt. Ein wichtiges Problem, das Apache HTTP wie jeder andere Webserver auch lösen muss, ist die Handhabung verschiedener Prozesse bei der Bearbeitung von http-basierten Anfragen. Dazu zählt das Öffnen eines Sockets, das die Anforderung verarbeitet, das Offenhalten der Verbindung für eine bestimmte Zeit, die Handhabung neuer Ereignisse, die während dieser Verbindung eintreten und die Rückgabe des produzierten Contents durch ein Programm, dass in einer bestimmten Sprache geschrieben wurde (wie PHP, Perl oder Python). Diese Aufgaben werden von einem Multi-Processing-Module (MPM) ausgeführt und gesteuert.

      Apache HTTP ist mit drei verschiedenen MPM ausgestattet:

      • Prefork: Für jede eingehende Verbindung, die den Server erreicht, wird ein neuer Vorgang erstellt. Jeder Vorgang ist isoliert von den anderen und es wird kein Speicher zwischen ihnen geteilt, selbst dann, wenn sie in der Ausführung identische Anrufe an einem bestimmten Punkt ausführen. Auf diese Weise können Sie mit Bibliotheken verknüpfte Anwendungen, die Thread-Ausführungen nicht unterstützen, sicher ausführen – meist ältere Anwendungen oder Bibliotheken.
      • Worker: Ein Elternprozess ist für das Starten eines Bündels von Kindprozessen verantwortlich, von denen einige neu eingehende Verbindungen erfassen und andere den angeforderten Content bereitstellen. Für jeden Prozess gibt es einen dazugehörigen Thread (ein einzelner Thread kann jeweils eine Verbindung verwalten), sodass ein Prozess mit mehreren Anfragen gleichzeitig umgehen kann. Diese Methode für die Handhabung von Verbindungen fördert eine bessere Ressourcennutzung und gewährleistet die Aufrechterhaltung der Stabilität. Das ist auf das Bündel von verfügbaren Prozessen zurückzuführen, bei denen oft frei verfügbare Threads bereitstehen, die neue Verbindungen sofort bedienen können.
      • Event: Basierend auf Worker geht dieses MPM noch einen Schritt weiter, indem es die Art und Weise optimiert, wie der Elternprozess Aufgaben für die Kindprozesse und für die Threads, die damit verknüpft sind, vorgibt. Eine Verbindung bleibt für 5 Sekunden standardmäßig geöffnet und schließt sich bei jedem neuen Ereignis, das eintritt; das ist der Standardwert für die Keep-Alive-Anweisung, der den mit ihm verknüpften Thread beibehält. Das Event MPM ermöglicht dem Prozess das Verwalten von Threads, damit einige Threads für die Verwaltung neuer eingehender Verbindungen bereitstehen, während andere weiterhin mit den Live-Verbindungen verknüpft sind. Die Ressourcennutzung und Leistungsfähigkeit wird dadurch verbessert, dass die den Threads zugewiesenen Aufgaben neu verteilt werden können.

      Mit dem MPM Event-Modul ist ein schnelles Multi-Processing-Modul auf dem Apache-HTTP-Webserver verfügbar.

      PHP-FPM ist der FastCGI-Prozessmanager für PHP. Das FastCGI-Protokoll basiert auf dem Common Gateway Interface (CGI), einem Protokoll, das zwischen Anwendungen und Webservern wie Apache HTTP steht. Dadurch können Entwickler Anwendungen schreiben, ohne das Verhalten der Webserver berücksichtigen zu müssen. Die Programme führen ihre Prozesse unabhängig aus und übergeben ihr Produkt über dieses Protokoll an den Webserver. Jede neue Verbindung, die von einer Anwendung verarbeitet werden muss, erstellt einen neuen Prozess.

      Durch die Kombination von MPM Event in Apache HTTP mit dem PHP FastCGI-Prozessmanager (PHP-FPM) kann eine Website schneller laden und mehr gleichzeitige Verbindungen mit weniger Ressourcen verarbeiten.

      In diesem Tutorial verbessern Sie die Leistung des LAMP-Stacks, indem Sie das standardmäßige Multi-Processing-Module von Prefork auf Event umstellen und den PHP-FPM-Prozessmanager für die Handhabung des PHP-Codes nutzen anstelle des klassischen mod_php in Apache HTTP.

      Voraussetzungen

      Bevor Sie diese Anleitung beginnen, benötigen Sie Folgendes:

      Schritt 1 — Umstellen des Multi-Processing-Module

      Ubuntu übernimmt Skripte, um Apache-HTTP-Module über die eigene übergeordnete Distribution Debian zu aktivieren oder zu deaktivieren. Sie werden dieses Toolset in diesem Schritt verwenden, um das Prefork-Modul zu deaktivieren und das Event-Modul zu aktivieren.

      In diesem Schritt halten Sie Apache HTTP an, deaktivieren das Modul PHP 7.2, das mit dem Prefork-Modul verknüpft ist, und deaktivieren anschließend Prefork, um das Event-Modul unmittelbar aktivieren zu können.

      Zuerst halten Sie den Apache-HTTP-Dienst an:

      • sudo systemctl stop apache2

      Nun können Sie das Modul PHP 7.2 deaktivieren, das mit dem Prefork-Modul in Verbindung steht:

      Deaktivieren Sie dann das Prefork MPM-Modul:

      • sudo a2dismod mpm_prefork

      Nun Aktivieren Sie das Event MPM-Modul:

      Sie haben das MPM von Prefork auf Event umgestellt und die Modulverbindung PHP 7.2 zwischen PHP und Apache HTTP entfernt. Im nächsten Schritt installieren Sie das php-fpm-Modul sowie die verwandten Bibliotheken und Proxy-Module. Sie konfigurieren Apache HTTP so, dass es auch mit PHP kommunizieren kann.

      Schritt 2 — Konfigurieren von Apache HTTP für die Nutzung des FastCGI-Prozesses

      In dieser Phase haben Sie die Verarbeitung von Verbindungen durch Apache HTTP umgestellt, indem Sie sie von dem Prefork-MPM auf Event verlagert haben. Im Zuge dessen haben Sie jedoch das PHP-Modul deaktiviert, das Apache HTTP mit jedem Programm verbunden hatte, das mit PHP ausgeführt wird.

      In diesem Schritt installieren Sie den PHP-FPM-Prozessor, damit Apache HTTP wieder PHP-Programme verarbeiten kann. Außerdem installieren Sie die Abhängigkeitsbibliotheken und aktivieren die Module, damit beide reibungslos und schneller zusammenarbeiten können als zuvor.

      Installieren Sie zuerst php-fpm. Der folgende Befehl installiert das PHP-FPM und aktiviert automatisch den Dienst php7.2-fpm, der in systemd integriert ist, sodass der Dienst beim Booten gestartet wird:

      Apache HTTP und PHP benötigen für die Kommunikation eine Bibliothek, die diese Funktion ermöglicht. Nun installieren Sie libapache2-mod-fcgid, das als Schnittstelle zwischen Programmen mit Webservern dient und Apache-HTTP-spezifisch ist. Diese Kommunikation erfolgt über ein UNIX-Socket.

      Installieren Sie diese Bibliothek:

      • sudo apt install libapache2-mod-fcgid

      Sie haben php-fpm und das libapache2-mod-fcgid installiert, aber noch keines davon aktiviert.

      Aktivieren Sie zuerst das php-fpm-Modul mit folgendem Befehl:

      Aktivieren Sie in einem zweiten Schritt das Apache HTTP-Proxy-Modul:

      Aktivieren Sie in einem dritten Schritt das FastCGI-Proxy-Modul auf Apache HTTP:

      Hinweis: Sie können die Konfiguration dieser Interaktion zwischen PHP-Programmen und Apache HTTP über einen UNIX-Socket mit Folgendem lesen:

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

      Nun wurden alle Vorkehrungen getroffen, damit Sie Apache HTTP starten können. Führen Sie eine Konfigurationsüberprüfung durch:

      • sudo apachectl configtest

      Output

      Syntax OK

      Danach können Sie mit dem Neustart von Apache HTTP fortfahren, da es beim Installieren der FastCGI-Bibliothek libapache2-mod-fcgid automatisch gestartet wurde:

      • sudo systemctl restart apache2

      Sie haben das php-fpm-Modul installiert und Apache HTTP so konfiguriert, dass es damit funktioniert. Zudem haben Sie ermöglicht, dass die erforderlichen Module für das FastCGI-Protokoll funktionieren, und die entsprechenden Dienste gestartet.

      Nachdem Apache das Event MPM-Modul aktiviert hat und PHP-FPM verfügbar ist und ausgeführt wird, ist es an der Zeit sicherzustellen, das alles wie geplant funktioniert.

      Schritt 3 — Testen Ihrer Konfiguration

      Führen Sie einige Tests aus, um zu prüfen, ob die Konfigurationsänderungen angewendet wurden. Beim ersten Test wird geprüft, welches Multi-Processing-Modul Apache HTTP verwendet. Beim zweiten Test wird sichergestellt, dass PHP den FPM-Manager verwendet.

      Überprüfen Sie den Apache-HTTP-Server, indem Sie den folgenden Befehl ausführen:

      • sudo apachectl -M | grep 'mpm'

      Sie erhalten folgende Ausgabe:

      Output

      mpm_event_module (shared)

      Für das Proxy-Modul und FastCGI können Sie diese Prozedur wiederholen:

      • sudo apachectl -M | grep 'proxy'

      Die Ausgabe zeigt Folgendes:

      Output

      proxy_module (shared) proxy_fcgi_module (shared)

      Wenn Sie die gesamte Liste der Module sehen möchten, können Sie den zweiten Teil des Befehls nach -M entfernen.

      Nun ist es Zeit zu prüfen, ob PHP den FastCGI-Prozessmanager verwendet. Dazu schreiben Sie ein kleines PHP-Skript, das Ihnen alle Informationen zeigt, die mit PHP in Verbindung stehen.

      Führen Sie den folgenden Befehl aus, um eine Datei zu schreiben, deren Name wie folgt lautet:

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

      Fügen Sie den folgenden Inhalt in die Datei info.php ein:

      info.php

      <?php phpinfo(); ?>
      

      Rufen Sie nun die URL Ihres Servers auf und fügen Sie info.php am Ende hinzu: http://your_domain/info.php.

      Der Server-API-Eintrag lautet FPM/FastCGI.

      PHP Screen the Server API entry FPM/FastCGI

      Löschen Sie die Datei info.php nach diesem Test, damit keine Informationen über den Server veröffentlicht werden:

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

      Sie haben den Betriebszustand des MPM-Moduls und der Module, die für die Handhabung von FastCGI zuständig sind, sowie die Handhabung des PHP-Codes überprüft.

      Zusammenfassung

      Sie haben Ihren ursprünglichen LAMP-Stack optimiert, sodass sich die Anzahl der Verbindungen zur Erstellung neuer Apache HTTP-Prozesse erhöht hat, PHP-FPM den PHP-Code effizienter verwaltet und sich die Ressourcennutzung insgesamt verbessert.

      Weitere Informationen zu den verschiedenen Modulen und verwandten Projekten finden Sie in der Projekt-Dokumentation zum Apache HTTP-Server.



      Source link

      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