Last Updated on September 21, 2023 EDT by Jordan
Table of Contents
- Introduction
- Why?
- Step 1 – Install the required packages
- Step 2 – Copy FPM config and modify
- Step 3 – Modify Nginx
- Step 4 – Change MySQL/Percona Server Charset
- Step 5 – Jeff Cleverly’s Additions
- No server page caching w/out ModSec
- FastCGI Page Caching w/out Modsec
- Redis Page Caching w/Modsec and HTTPS
- Redis Page Caching w/Modsec and no HTTPS
- No server page caching w/Modsec and HTTPS
- No server page caching w/Modsec and no HTTPS
- FastCGI Caching w/Modsec and HTTPS
- FastCGI Caching w/Modsec and no HTTPS
Content Error or Suggest an Edit
Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!
DISCLAIMER
The following commands change how your GridPane server functions. This may void any support provide by GridPane, use at your own discretion. If you contact GridPane support, inform them that you made these changes.
Introduction
This article will cover how to set up PHP 5.6 on a GridPane server.
Why?
You might be asking why would you want to install PHP 5.6? It’s slow, slowly being phased out of WordPress as a minimum supported version. My main reasoning is migrations and upgrades. I’ve had to upgrade sites on WordPress 3.5.1 to 5.3.2 and I needed to do this within a staging environment. I could simply install a custom LAMP stack with PHP5.6, and do everything manually. But why when I pay for GridPane?
Step 1 – Install the required packages
onYou will need to install the required PHP 5.6 packages for Ubuntu 18, which unfortunately aren’t shipped or available on the Ubuntu mirrors. But let’s just add a PPA (personal package archive). There is a rather popular one by ondrej and is rather easy to use. Let’s go!
sudo add-apt-repository ppa:ondrej/ppa sudo apt-get install php5.6-fpm php5.6-bcmath php5.6-cli php5.6-common php5.6-curl php5.6-xml php5.6-gd php5.6-imagick php5.6-json php5.6-mbstring php5.6-mysql php5.6-opcache php5.6-readline php5.6-soap php5.6-zip
Step 2 – Copy FPM config and modify
Now that we have all the PHP 5.6 bits, we just need to configure the PHP 5.6 php-fpm daemon with an appropriate pool.
We’ll take the configuration from an already active website that is configured, in this instance, managingwp.io is the site and it’s has PHP 7.2 enabled. So just copy the configuration to the php-fpm 5.6 directory pool.
cp /etc/php/7.2/fpm/pool.d/staging.managingwp.io.conf /etc/php/5.6/fpm/pool.d/staging.managingwp.io.conf
Now we should modify the configuration otherwise if we try and restart php-5.6-fpm service it will error stating that the socket for this new configuration is already in use. Which is true because we just copied the configuration.
sed -i 's/managingwp.io72/staging.managingwp.io56/g' /etc/php/5.6/fpm/pool.d/staging.managingwp.io.conf sed -i 's/php72-fpm-staging.managingwp.io.sock/php56-fpm-managingwp.io.sock /g' /etc/php/5.6/fpm/pool.d/managingwp.io.conf
Restart the php5.6-fpm service to take the new configuration.
systemctl restart php5.6-fpm
You shouldn’t receive an error if everything was done correctly after running the above command. However, double-check php5.6-fpm process is running correctly by using the following commands.
ps -auxwwf | grep php-fpm tail -f /var/log/php5.6-fpm.log
Step 3 – Modify Nginx
Now we need to modify the Nginx configuration to use the new socket for PHP5.6
sed -i 's/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g' /etc/nginx/common/staging.managingwp.io-wpcommon.conf /etc/nginx/common/staging.managingwp.io-wp-redis.conf
Then test NGiNX
nginx -t
If all is good then do a configuration reload on NGiNX.
systemctl reload nginx
You should then be able to go to the site in question and see that it’s running PHP 5.6. To confirm, run the following command in the document root to create a PHP information page.
echo "<?php phpinfo();?>" > phpinfo.php
Step 4 – Change MySQL/Percona Server Charset
Unfortunately, MySQL/Maria/Percona 8.x change the default charset used. This breaks PHP 5.6 code. https://severalnines.com/database-blog/how-run-php-5-applications-mysql-80-centos-7
So we need to change the default charset. Add the following to /etc/mysql/mysql.conf.d/mysqld.cnf below [mysqld]
[mysqld] collation-server = utf8_unicode_ci character-set-server = utf8
Then restart mysqld
systemctl restart mysqld
Step 5 – Jeff Cleverly’s Additions
Jeff the CTO at GridPane kindly provided some additional configuration files you’ll need if you enable specific options after the initial site deploy.
Everything here is perfect if you follow things immediately after site build, which is of course the most common use case for anything like this, but for anyone who is wanting to perhaps do something like this after some settings have been adjusted here are the updated commands as per state.
(This will be more useful in an upcoming update when users will be able to specify various initial builds or even a preferred default. I also mention them, because during internal switching of functions I can’t guarantee the system won’t freak when it doesn’t find 7.x and lead to incomplete configurations changeovers.)
The /etc/nginx/common/{site.url}-wpcommon.conf will be common to all caching/firewall settings but the other files and adjusted commands are as follows.
No server page caching w/out ModSec
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-php.conf
FastCGI Page Caching w/out Modsec
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-wpfc.conf
Redis Page Caching w/Modsec and HTTPS
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-proxy-https-rediscache.conf
Redis Page Caching w/Modsec and no HTTPS
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-proxy-http-rediscache.conf
No server page caching w/Modsec and HTTPS
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-proxy-https.conf
No server page caching w/Modsec and no HTTPS
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-proxy-http.conf
FastCGI Caching w/Modsec and HTTPS
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-proxy-https-proxycache.conf
FastCGI Caching w/Modsec and no HTTPS
sed -i ‘s/php72-fpm-staging.managingwp.io.sock/php56-fpm-staging.managingwp.io.sock/g’ /etc/nginx/common/{site.url}-wpcommon.conf /etc/nginx/common/{site.url}-proxy-http-proxycache.conf
Last Updated on September 21, 2023 EDT by Jordan