Guy Fawkes Posted August 18 Posted August 18 Many people use Apache2 as a web server. However, few people think about optimizing its performance, which directly affects the speed of loading site pages, the speed of processing scripts (in particular, PHP), as well as the growth of the load on the CPU and the increase in the amount of RAM used. Thus, the following manual should help beginners (and not only) users. All examples below were used on Raspberry PI 3, Debian 9, Apache 2.4.38, PHP 7.3. So, let's get started. 1. Disabling unused modules The first method is to simply disable modules that you do not use: You can view the list of currently used modules using the command: apache2ctl -M To disable the module, use the command: a2dismod *module name* Accordingly, to enable the module, use the command: a2enmod *module name* Please note that when using a2dismod, the module name must be written without the word module itself. For example, if you see proxy_module in the output of the apache2ctl -M command, then to disable it, you need to use the command — a2dismod proxy The modules that load the system the most (from personal experience) are: PHP, Ruby, Perl and other modules for various scripting languages SSL Rewrite CGI So in cases where you do not need these modules, I recommend disabling these modules. Also, after disabling any module, I recommend using the command - apache2ctl configtest, which will check the configuration of the sites used and if any of the disabled modules were necessary for them, it will return an error. 2. Changing MPM (Multi-Processing Module) and using php-fpm By default, after installation, apache2 uses MPM Prefork (1 thread per 1 connection), which significantly reduces performance, but at the same time improves stability and security. But to optimize performance, I recommend using MPM Worker, which allows you to use several threads at once per connection. To enable it, use the following commands: a2dismod mpm_prefork //Disable prefork a2dismod php7.3 //Disable the php module that depends on prefork a2enmod mpm_worker //Enable worker However, when using Worker, you may encounter a problem, because the php7.3 module depends on the Prefork module. To solve this problem, install the php7.3-fpm module, which will be used to process php scripts: apt-get update && apt-get install php7.3-fpm //Install systemctl enable php7.3-fpm && systemctl start php7.3-fpm //Add to startup and run a2enmod php7.3-fpm && a2enconf php7.3-fpm.conf //Enable the module and config for it It is worth noting that using php-fpm will also reduce the amount of RAM used by the apache2 process and speed up the processing of php scripts a little. 3. Conclusion Thus, with such simple actions we were able to optimize performance and reduce the load on the machine (RPI3 in this case). Of course, there are hundreds of other optimization options, such as enabling compression (which is really useful, but most of them are already enabled by default), changing MPM parameters (configuration files), disabling HostnameLookups, etc., but in this article I tried to reflect exactly those points that helped me the most, and I hope that they will help others. Quote Donate Vi Veri Veniversum Vivus Vici I am not a tech support or a script consultant! I am a network engineer and system administrator! In my free time I crack software and publish it on this site! If you need help installing any software from this site or any other - write to @Guy Fawkes - we will agree for a modest reward! If you want the same site - the price is 100 euros, including hosting for 1 year! (you will publish the content yourself), I will only install and configure everything. I will also help with payment systems for Europe!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.