PHP runs the backend of my website, and keeping anything that is running on your server up to date is one of the most important steps in security.
First install the php8.4 packages from apt.
Add the Ondřej Surý’s PHP Repository
sudo apt update
sudo apt install -y apt-transport-https lsb-release ca-certificates wget
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo “deb https://packages.sury.org/php $(lsb_release -sc) main” | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt install php8.4 php8.4-bz2 php8.4-cgi php8.4-cli php8.4-common php8.4-curl php8.4-fpm php8.4-gd php8.4-mbstring php8.4-mcrypt php8.4-mysql php8.4-opcache php8.4-readline php8.4-xml php8.4-zip php8.4-dom php8.4-bcmath php8.4-imagick
sudo a2enconf php8.4-fpm
sudo a2disconf php8.3-fpm
systemctl start php8.4-fpm
systemctl enable php8.4-fpm
systemctl stop php8.3-fpm
systemctl disable php8.3-fpm
sudo apachectl configtest
systemctl reload apache2
sudo apt remove php8.3 php8.3-bz2 php8.3-cgi php8.3-cli php8.3-common php8.3-curl php8.3-fpm php8.3-gd php8.3-mbstring php8.3-mcrypt php8.3-mysql php8.3-opcache php8.3-readline php8.3-xml php8.3-zip
This Guide assumed all you needed to do is upgrade your php version.
Below are instructions that you can use to switch from the prefork to the fastcgi module, these have a little more explanation if you are not familiar with apache2 web server.
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 php8.3
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 php8.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 php8.4-fpm
Test your configuration is good before restarting apache2
sudo apachectl configtest
Now you should be running the most efficient php processing module for apache2 and the most up to date php version 🙂
Leave a Reply