2

I followed directions from here to switch the server API entry will be FPM/FastCGI.from Server API Apache 2.0 Handler. When mpm_event is enabled and a2dismod php7.4 the phpinfo.php shows only:

<?php phpinfo(); ?>

Apache status:

Apache Server Status for localhost (via 127.0.0.1)

   Server Version: Apache/2.4.46 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1f

   Server MPM: event

   Server Built: 2020-11-13T01:36:38

     ----------------------------------------------------------------------

   Current Time: Saturday, 27-Feb-2021 13:08:50 EST

   Restart Time: Saturday, 27-Feb-2021 13:05:50 EST

   Parent Server Config. Generation: 1

   Parent Server MPM Generation: 0

   Server uptime: 3 minutes

   Server load: 0.80 0.95 1.07

   Total accesses: 14 - Total Traffic: 190 kB - Total Duration: 10069

   CPU Usage: u0 s.05 cu0 cs0 - .0278% CPU load

   .0778 requests/sec - 1080 B/second - 13.6 kB/request - 719.214 ms/request

   1 requests currently being processed, 49 idle workers

   +------------------------------------------------------------------------+
   |    |     |        |Connections    |Threads  |Async connections         |
   |Slot|PID  |Stopping|---------------+---------+--------------------------|
   |    |     |        |total|accepting|busy|idle|writing|keep-alive|closing|
   |----+-----+--------+-----+---------+----+----+-------+----------+-------|
   |0   |46738|no      |0    |yes      |1   |24  |0      |0         |0      |
   |----+-----+--------+-----+---------+----+----+-------+----------+-------|
   |1   |46739|no      |0    |yes      |0   |25  |0      |0         |0      |
   |----+-----+--------+-----+---------+----+----+-------+----------+-------|
   |Sum |2    |0       |0    |         |1   |49  |0      |0         |0      |
   +------------------------------------------------------------------------+

 _______________W__________________________________..............
 ................................................................
 ......................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of worker, "." Open slot with no current process

If I enable php7.4 and switch back on mpm_prefork, it will restore to Apache 2.0 Handler. Is something not right what I am doing?

Latest note: it partially works, but PHP pages still not shown correctly.

The PHP pages are shown correctly now and the MySQL connection test works. After I entered a2enmod php7.4 which should have switched to Server API Apache 2.0 Handler get the error below but switched to FPM/FastCGI.

Besides is capture here for future references it was 3 nights of work: enable/disable modules, dependencies conflicts, updates, configurations and logging. Copy&Paste from other posts always sucks. Thanks!

SOLVED

a2enmod php7.4
    Considering dependency mpm_prefork for php7.4:
    Considering conflict mpm_event for mpm_prefork:
    ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first!
    Considering conflict mpm_worker for mpm_prefork:
    ERROR: Could not enable dependency mpm_prefork for php7.4, aborting

enter image description here

Brad Thompson
  • 540
  • 1
  • 14
  • 35
  • I posted an answer for Ubuntu 20-22 [here](https://askubuntu.com/questions/1029564/php-7-2-fastcgi-doesnt-work-on-ubuntu-18-04-server/1458664#1458664). – centurian Mar 16 '23 at 19:09

1 Answers1

6

Setting up PHP-FPM with Apache is much more complicated than simply installing FPM and enabling a few things. It requires additiona modules (FastCGI) to be installed among other things enabled and disabled.

Funnily enough, the Digital Ocean guide for using MPM Event and PHP-FPM via FastCGI on Apache with Ubuntu 18.04 is still a relatively good jump-off point for configurations of this setup, we just have to tweak some things and adjust bits for some changes between 18.04 and 20.04. The below instructions are based off the DO guide but with the requisite tweaks to make FPM work in 20.04, adapting PHP versions, etc. and giving you just the commands.

Step 1: Changing the Multi-Processing Module

The php7.4 module in Apache is the inbuilt one - unfortunately it doesn't work for PHP-FPM. So we need to do some work to make this work.

First, stop Apache while we make tweaks to the configs

sudo systemctl stop apache2

Then, disable the in-built prefork driven PHP 7.4 module

sudo a2dismod php7.2

Disable the prefork module.

sudo a2dismod mpm_prefork

Enable the event mpm module

sudo a2enmod mpm_event

Now we configure the PHP components, which is fairly straightforward...

Step 2: Configure Apache's FastCGI manager with PHP

If you haven't done this already, install PHP FPM

sudo apt install php-fpm

If that command doesn't work, use this one:

sudp apt install php7.4-fpm

Install the FCGI module for Apache

sudo apt install libapache2-mod-fcgid

Enable requisite libraries and modules

a2enmod proxy_fcgi setenvif

Enable the PHP-FPM module's configuration (which will already be present)

sudo a2enconf php7.4-fpm

Now we need to make sure the syntax passes in your config.

Step 3: Make sure the configuration passes the tests.

Run this command:

sudo apachectl configtest

This command may spit out more information such as this, but as long as "Syntax OK" is the output you're good (run from a test container/environment, ignore the AH00558 error if it shows up and worry only about the 'Syntax OK' output):

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.73.252.124. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Now that config test has passed...

Step 4: Re-enable Apache service

sudo systemctl restart apache2

You should now get PHP working again, except with the FPM service. And PHP files should work again.

Nuke your browser cache before testing, though - web browsers are NOTORIOUS for caching error messages.


If you've done everything here, you should see PHP working as expected - this is phpinfo on my test env running 20.04:

enter image description here

Thomas Ward
  • 72,494
  • 30
  • 173
  • 237
  • Thank you for the guide! I had some problems following, but here is the fix that worked for me: in Step 2, `sudo apt install php-fpm` should be `sudo apt install php7.4-fpm`. Otherwise it will give an error that `php-fpm` doesn't exist. – Andy Jan 18 '23 at 12:47