Written by: Robert R. Russell on Saturday, August 29, 2020.
If you followed the WordPress Install Guide you are leaving performance on the table for your website. The WordPress Install Guide defaults to Apache’s mod_PHP which is definitely leaving performance on the table.
Here is how to fix that in Ubuntu 20.04:
sudo apt install php-fpm
sudo a2dismod php mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo a2enconf php7.4-fpm
sudo apt-mark manual apache2
sudo apt purge libapache2-mod-php*
That takes care of the general Apache configuration. The next configuration adjustments need to be done at the vhost level. Substitute the correct information for YOUREMAIL, YOURDOMAIN, and WPDIR, and you are good to go.
<VirtualHost *:443>
Protocols h2 http/1.1
ServerName YOURDOMAIN
ServerAdmin [email protected]
DocumentRoot "WPDIR"
<Directory "WPDIR">
<FilesMatch "\.php$">
#Proxy php files to php-fpm
SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
Options All
AllowOverride All
DirectoryIndex index.php
Require all granted
</Directory>
#Protect the uploads directory.
<Directory "WPDIR/wp-content/uploads/">
<FilesMatch "\.php$">
SetHandler none
Require all denied
</FilesMatch>
</Directory>
#snip extraneous stuff
</VirtualHost>
©2020 Robert R. Russell — All rights reserved