Apache/PHP Update

Back when I setup my webserver to run wordpress and dokuwiki, all the guides that I found and the guides that I followed had apache get setup with mod_php. However, after seeing this ArsTechnica WordPress Writeup, I realized that this might not have been the best way to get things going. I decided that this would be a good time to upgrade some of my webserver, so I started working on it, while my server was already setup, and the guide was on setting up a new server, the process is nearly identical, the only differences is that I had to disable/enable modules in a certain order for everything to work.

Packages Needed

There was only one package needed to get php-fpm setup on my webserver. Since I already had mod_php running, and they share many packages, php-fpm was able to use those packages.

root@apache:~# apt install php-fpm

After installing php-fpm, I got this message which provides some details on how to enable php-fpm in apache. We will be using the configuration listed in it later.

Processing triggers for php7.2-fpm (7.2.24-0ubuntu0.18.04.6) ...
NOTICE: Not enabling PHP 7.2 FPM by default.
NOTICE: To enable PHP 7.2 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php7.2-fpm
NOTICE: You are seeing this message because you have apache2 package installed.

Apache Module Changes

You can find the right config file by looking in /etc/apache2/conf-available, or from the terminal output after installing php-fpm. Just enable the config with a2enconf.

root@apache:~# a2enmod proxy_fcgi
root@apache:~# a2enconf php7.2-fpm.conf

I started with disabling the php module, since I wasn’t sure the full name of it, I just let a2dismod list out all of them for me to pick from.

root@webserv:/etc/apache2/sites-enabled# a2dismod
Your choices are: access_compat alias auth_basic authn_core authn_file authz_core authz_host authz_user autoindex deflate dir env filter mime mpm_prefork negotiation php7.2 proxy proxy_fcgi proxy_http proxy_wstunnel reqtimeout rewrite setenvif socache_shmcb ssl status
Which module(s) do you want to disable (wildcards ok)?
php7.2
Module php7.2 disabled.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@webserv:/etc/apache2/sites-enabled# service apache2 restart

The next step was to disable the mpm_prefork mod. I did this in the same way as the PHP module.

root@webserv:/etc/php/7.2/fpm# a2dismod
Your choices are: access_compat alias auth_basic authn_core authn_file authz_core authz_host authz_user autoindex deflate dir env filter mime mpm_prefork negotiation proxy proxy_fcgi proxy_http proxy_wstunnel reqtimeout rewrite setenvif socache_shmcb ssl status
Which module(s) do you want to disable (wildcards ok)?
mpm_prefork
Module mpm_prefork disabled.
To activate the new configuration, you need to run:
  systemctl restart apache2

Finally, we can start enabling the new modules and restart the apache process. I didn’t restart apache until now as I wanted everything configured first so I would have minimal downtime.

root@webserv:/etc/php/7.2/fpm# a2enmod mpm_event
Considering conflict mpm_worker for mpm_event:
Considering conflict mpm_prefork for mpm_event:
Enabling module mpm_event.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@webserv:/etc/php/7.2/fpm# service apache2 restart

This finishes up the primary portion of the PHP shift. I had a few more things to do on my webserver to bring everything back to my baseilne. I had some changes off of the baseline php.ini file in mod_php, and the mod_php configuration files are separate from php-fpm. So I have to go move these changes into the php-fpm configuration files. The new file is located in /etc/php/<version>/fpm.

root@webserv:/etc/php/7.2/fpm# nano php.ini

The main components that I had updated on my webserver were related to uploading files (mainly pictures for WordPress), so I have those properties listed below with my new values.

post_max_size = 10M
upload_max_filesize = 10M

After updating the configuration file, I restarted apache one last time.

Final Checking of Loaded Modules

Now we want to double check that all the correct modules are loaded in apache. To do so, we will be using apachectl to list out the modules, the command is below with the output as well.

root@webserv:/etc/php/7.2/fpm# apachectl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)
 proxy_module (shared)
 proxy_fcgi_module (shared)
 proxy_http_module (shared)
 proxy_wstunnel_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)
root@webserv:/etc/php/7.2/fpm#

In this list, we want to verify that the proxy_fcgi_module and the mpm_event_module are enabled, and the mpm_prefork module is disabled along with any PHP modules.

Conclusion

This was a straight forward process to update my apache webserver to no longer use mod_php. The mod_php might be one of the more common ways to find online for setting up wordpress or other php applications, however its also the least efficient when it comes to resources. While my blog may not get that much traffic, and my other services are not too intensive, it was still a good exercise to get apache/PHP running in better form.