✓ Solved

Set-up apache vhosts with php-fpm

What I'd actually like to do is modify some existing vhost configuration to have some sites use php-fpm7.4 and some use php-fpm8.1. I've read a lot of posts in this regard, what I've done so far is simply add

<FilesMatch \.php$>
  Sethandler None
  SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://php74.localhost"
</FilesMatch>

to the <VirtualHost *:80> block for 7.4, and similarly

<FilesMatch \.php$>
  Sethandler None
  SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://php74.localhost"
</FilesMatch>

for 8.1, with

<FilesMatch ".+\.ph(ar|p|tml)$">
  SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://php74.localhost"
</FilesMatch>

in my php7.4-fpm.conf and

<FilesMatch ".+\.ph(?:ar|p|tml)$">                                                                                                                            
    SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://php81.localhost"        
</FilesMatch>        

in my php8.1-fpm.conf. As soon as I enable php8.1-fpm.conf, all sites will use php-fpm8.1. I know there are lots of variables affecting this, but I wanted to start a thread here to solicit suggestions about where I should look next to determine the problem with this set-up. I'm using Ubuntu 20.04.6 and Apache/2.4.41.

4 Replies

✓ Best Answer

Two things were important in my case to get this working:

  1. I needed to a2dismod mpm_prefork and a2enmod mpm_event.
  2. I needed to add the handler to my *ssl.conf, since requests are automatically upgraded to https.

I also found that I did not need to have php8.1-fpm.conf enabled at all, the changes to the vhost files is enough.

I did some research and worked through this a bit and tried to figure out what parts of the process are most likely to be responsible for this behavior and I have some guesses that I hope help. Most of this is coming from these two sources:


  • You can check to make sure that php7.4-fpm is still running by checking the status with systemctl.
  • Make sure you restart Apache after any configuration changes to ensure they take effect.
  • Make sure both of your sites/both virtual host files are active, which may look a bit different depending on your configuration. This is addressed in those sources, but there are also options for creating [symbolic links](are active) to ensure the files exist in /etc/apache2/sites-enabled.

I see a note that says "For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server" in the configuration examples, and I can see you're using a version above that. Based on that, I'd recommend making sure you enabled the modules that relate to that process:

sudo a2enmod actions fcgid alias proxy_fcgi

Finally, the syntax of the SetHandler directive looks different in your output than in the examples I've seen. It may be worth looking into that as well.

I'm probably relying on the same sources you used to see how to do this, so my apologies if this is all stuff you've considered. But I hope it helps.

Did you get anywhere with this?

I’ve just set up a new Linode with Apache (having been away from Linode for a couple years and using Nginx) and when PHP 8.4 or 9 is released next, this is something I’ll need to do.

Thanks!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct