I’m trying to update my server to use PHP8.1 and I ended up disabling http/2 and also can’t figure out how to re-enable it and actually get PHP8.1 to run.
The first steps I did were:
sudo a2dismod php7.4
sudo a2enmod php8.1
The second command had a conflict with mpm_event so I then ran:
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
After running "sudo a2enmod php8.1" again as well as "sudo systemctl restart apache2", it seemed okay.
However, whenever I run "php -v", it says that the CLI is "8.1" but using "phpinfo()" on the live site still returns "7.4.26".
I also ran these commands which all show that 8.1 is currently running:
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
sudo update-alternatives --config phpize
sudo update-alternatives --config php-config
After all of this, I noticed that my webpages stopped serving via http/2. Upon trying "sudo a2dismod mpm_prefork" so I can enable mpm_event again, it says that it can’t disable mpm_prefork because there’s a conflict with the PHP module. When I disable the PHP module, I can disable mpm_prefork and enable mpm_event but then I wouldn’t have PHP anymore (I think? It’s all so confusing…)
Edit: I tried disabling the PHP module and enabling mpm_event but it made the website not work anymore so I reverted those changes.
For clarity, when I try "sudo a2dismod mpm_prefork", I get this error:
ERROR: The following modules depend on mpm_prefork and need to be disabled first: php8.1
If it helps, phpinfo() says that I’m currently running:
PHP Version 7.4.26
Server API FPM/FastCGI
Configuration File (php.ini) Path /etc/php/7.4/fpm
Also, I now have PHP8.1 in my mods_enabled folder and I swear there were no PHP modules at all there before all this.
All in all, I’m very new to server management but I simply want to run PHP8.1 (fpm version?) while using http/2 but am running around in circles and I also took a step back with accidentally disabling http/2.
Edit: My question is basically three parts:
- Why did my site go offline after I disabled the PHP8.1 module? And,
how do I prevent that from happening again? - How do I safely re-enable mpm_event (so that http/2 will work again)? Keep in mind that it seems to
only be an option when both PHP8.1 and mpm_prefork modules are
disabled. - How do I upgrade to PHP 8.1-fpm?
If an answer can provide steps for digging myself out of the hole that I dug myself into while also enabling PHP8.1-fpm then that would be awesome.
Oh, and just so it’s clear; my current setup is:
- PHP8.1 and mpm_prefork modules are enabled (mpm_event is disabled)
- The live website is using PHP7.4-fpm without http/2
- The CLI version of PHP is PHP8.1
- I do not have PHP8.1-fpm installed
3
Answers
You need a package named
php8.1-fpm
to be able to use thempm_event
instead ofmpm_prefork
. For example this is mentioned in this tutorial:Of course you will want the php8.1-fpm package.
I think that your thrid question answers second, combined them into one list of commands
When you switch off apache php module, web server treats php code as plain text, which is a default behavior for unknown content type. Its kinda working, but your code is not interpreted at all.
In order to prevent that either use varnish, load balancer(apache/nginx), make snapshots of the system when its stable or containerize your application with docker. Whatever will be suitable for your needs.
In varnish case it will create cached versions of your web pages and will return them in response omitting your webserver until no such cached version of web page exist(no cache hits in other words). But before, you need to write script which will cache all pages. Then varnish will simply send html responses.
In load balancer case if one node fail then it will redirect traffic to another alive node. Each node is basically a copy of your website.
Snapshots are images of your OS which you can use in different VMs for example. So if you messed up then you can simply delete snapshot and install initial one again.
In docker you can simply split your app into 2 services, which you can configure however you want without being afraid of making everything bad )
1 service will apache2
2 service will be php-fpm
Then you can simply build each service as an image and rotate images like in VM(Virtual Machine).
Hope that something in this list will be helpful )
In my Apache config I had to change this line to use the right socket:
Infos about the socket: