Skip to content

Instantly share code, notes, and snippets.

@daun
Forked from mrl22/README.md
Created January 10, 2023 15:20
Show Gist options
  • Save daun/7d9b9f15bf47e96cda31e437ea17afab to your computer and use it in GitHub Desktop.
Save daun/7d9b9f15bf47e96cda31e437ea17afab to your computer and use it in GitHub Desktop.
PHP 8.1 Support for Apache and NGINX (OpenResty) on Moss.sh

Do not copy and paste this code, it requires changes

As of writing this, Moss.sh does not support PHP 8.1 via the control panel even though Ubuntu does.

Set up your website using Moss.sh and select Apache with PHP 7.4.

Once complete, we need to install PHP 8.1 with all the packages moss installs for 7.4.

apt install php8.1-bcmath php8.1-bz2 php8.1-cli php8.1-common php8.1-curl php8.1-dev php8.1-fpm php8.1-imap php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-pgsql php8.1-readline php8.1-soap php8.1-sqlite3 php8.1-xml php8.1-xmlrpc php8.1-zip php8.1-gd php8.1-igbinary php8.1-imagick php8.1-memcached php8.1-msgpack

Lets configure PHP 8.1 FPM for the sites user so that Apache or NGINX can process PHP scripts. Make sure to change myuser to your sites user.

cp /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/myuser.conf
sed -i 's/\[www\]/\[myuser\]/g' /etc/php/8.1/fpm/pool.d/myuser.conf
sed -i 's/www-data/myuser/g' /etc/php/8.1/fpm/pool.d/myuser.conf
sed -i 's/php8.1-fpm/php8.1-fpm-myuser/g' /etc/php/8.1/fpm/pool.d/myuser.conf

Restart php-fpm

service php8.1-fpm reload

Now we switch Apache/NGINX/OpenResty from PHP 7.4 to 8.1 by replacing some words. Again, make sure to replace myuser and mysite.com configuration file.

Apache Method

sed -i 's/php7.4-fpm-myuser/php8.1-fpm-myuser/g' /etc/apache2/sites-enabled/mysite.com.conf

Restart Apache

service apache2 restart

NGINX/OpenResty Method

Moss.sh uses OpenResty which is a fork of NGINX, but they label it as NGINX in their control panel.

sed -i 's/php7.4-fpm-myuser/php8.1-fpm-myuser/g' /usr/local/openresty/nginx/sites/mysite.com.conf

Restart OpenResty

service openresty restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment