In case someone, like me, needs PHP 8.0 in their servers before official support in WordOps, I'm offering the script I wrote to install PHP 8 and adapt current WO configuration to it.
Before the script, please note:
- This script works for my needs; I don't know if it fits yours.
- You are responsible for what you run in your server. If you can't understand the code below, perhaps it's better not even try it.
- I can't provide you with any support.
- I don't know how WO or the server will behave when official support for PHP 8 finally comes.
That said, here goes the script. I named it install-php8.sh
. It must be run as root
(I didn't even try it with sudo
). PHP 7.4 must be installed beforehand (wo stack install --php74
).
#!/bin/bash
e_error(){
echo "ERROR: $1"
}
e_success(){
echo "SUCCESS: $1"
}
function replace {
echo "${3/$1/$2}"
}
newSection='}
#-------------------------------
# PHP 8.0
#-------------------------------
# PHP 8.0 upstream with load-balancing on two unix sockets
upstream php80 {
least_conn;
server unix:/var/run/php/php80-fpm.sock;
server unix:/var/run/php/php80-two-fpm.sock;
keepalive 5;
}
# PHP 8.0 debug
upstream debug80 {
# Debug Pool
server 127.0.0.1:9175;'
apt install php8.0-bcmath php8.0-cli php8.0-common php8.0-curl php8.0-fpm \
php8.0-gd php8.0-igbinary php8.0-imagick php8.0-imap php8.0-intl \
php8.0-mbstring php8.0-memcached php8.0-msgpack php8.0-mysql \
php8.0-opcache php8.0-readline php8.0-redis php8.0-soap php8.0-xdebug \
php8.0-xml php8.0-zip -y
if [[ -d /etc/php/8.0/fpm/pool.d/ ]] ; then
cd /etc/php/8.0/fpm/pool.d/
cp /etc/php/7.4/fpm/pool.d/*.conf .
sed -i -e "s/php74/php80/g" *.conf
sed -i -e "s/9174/9175/g" debug.conf
cd /etc/php/8.0/fpm/
sed -i -e "s/^upload_max_filesize = .*$/upload_max_filesize = 64M/g" php.ini
sed -i -e "s/^post_max_size = .*$/post_max_size = 64M/g" php.ini
sed -i -e "s/^memory_limit = .*$/memory_limit = 256M/g" php.ini
service php8.0-fpm restart
cd /etc/nginx/conf.d
cp upstream.conf upstream.orig
sed '/server 127.0.0.1:9174;/r'<( echo "$newSection" ) -i -- upstream.conf
cd /etc/nginx/common
for F in *74.conf ; do
G=$( replace "74" "80" "$F" )
cp "$F" "$G"
sed -i -e "s/php74/php80/g" "$G"
done
update-alternatives --set php /usr/bin/php7.4
update-alternatives --set phar /usr/bin/phar7.4
update-alternatives --set phar.phar /usr/bin/phar.phar7.4
update-alternatives --set phpize /usr/bin/phpize7.4
update-alternatives --set php-config /usr/bin/php-config7.4
e_success "PHP 8 is installed"
else
e_error "Something went wrong!"
fi
Since wp-cli
was showing a lot of warning related to my old plugins (compatible with PHP8 but not 100% written in PHP8) I found better to set PHP in command line to PHP 7.4 rather than 8.0.
After you install PHP8, in order to adapt your sites to the newest version you should wo site edit domain.com
and replace all occurrences of "74" with "80", and you should be good to go.