Apache was running slow in production. After searching for answers for some time, I finally went to #apache IRC channel and the pros had me check the apache mode with this command:
sudo apachectl -V
and were alarmed to find that Server MPM is prefork. They emphatically said DO NOT USE PREFORK ON A PRODUCTION SERVER. As it turns out, the Ubuntu packages (presumably inherited from Debian?) insist on running apache in prefork mode despite the fact that the recommended method for running PHP with Apache clearly recommends proxy_fcgi and php-fpm, then fcgid and ultimately says you should not use prefork:
Why you shouldn't use mod_php with the prefork mpm anymore
- mod_php is loaded into every httpd process all the time. Even when httpd is serving static/non php content, that memory is in use.
- mod_php is not thread safe and forces you to stick with the prefork mpm (multi process, no threads), which is the slowest possible configuration
That page also contains some detail on PHP-FPM but this seems a bit elaborate and unclear and seems to involve a lot of manual configuration. I'm disappointed and surprised Ubuntu 16 has no package option for fastCGI mode or something.
I tried switching apache to event mode using a2enmod and when I tried to fire apache back up, I got an error:
Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP
At any rate, I was wondering if anyone had some minimal, step-by-step instructions to get fastCGI mode running on Ubuntu 16 with PHP 7.0 by relying on the package installers as much as possible. I'm currently looking at a lot of poorly explained, vague instructions and I'm concerned about mucking up my production environment with poor decisions.
Also, someone should add mpm-event as a tag option. That's what the #apache IRC guys recommended.