Nextcloud
Nextcloud: Update PHP-FPM 8.2
By jplee ~ Published – 2023/11/29
By following this guide you will be able to setup Nextcloud 27 with the current PHP version 8.x to operate, we may go for a server installation according to this guide. Log in via SSH to the Server and change in the privileged user mode. However, backup your server first! Then, switch into the privileged user mode:
sudo -s In order to prevent access to the nextcloud during the conversion, we can move Nextcloud into the maintenance mode
and stop all the relevant server connected services:
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on service nginx stop && service redis-server stop && service php8.1-fpm stop && service mariadb stop
service postgresql stop Now that all services are stopped, we will update and clean up system:
apt update && apt full-upgrade -y && apt autoremove --purge && apt autoclean apt install -y lsb-release gnupg2 ca-certificates apt-transport-https software-properties-common add-apt-repository ppa:ondrej/php apt update && apt install -y php-common \
php8.2-{fpm,gd,curl,xml,zip,intl,mbstring,bz2,ldap,apcu,bcmath,gmp,imagick,igbinary,mysql,pgsql,redis,smbclient,cli,common,opcache,readline} \
imagemagick libmagickcore-6.q16-6-extra --allow-change-held-packages apt install -y ldap-utils nfs-common cifs-utils timedatectl set-timezone Asia/Taipei Before we start with the optimization of PHP, we ensure that by coping the configuration files:
cp /etc/php/8.2/fpm/pool.d/www.conf /etc/php/8.2/fpm/pool.d/www.conf.bak
cp /etc/php/8.2/fpm/php-fpm.conf /etc/php/8.2/fpm/php-fpm.conf.bak
cp /etc/php/8.2/cli/php.ini /etc/php/8.2/cli/php.ini.bak
cp /etc/php/8.2/fpm/php.ini /etc/php/8.2/fpm/php.ini.bak
cp /etc/php/8.2/mods-available/apcu.ini /etc/php/8.2/mods-available/apcu.ini.bak
cp /etc/php/8.2/mods-available/opcache.ini /etc/php/8.2/mods-available/opcache.ini.bak
cp /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak
systemctl restart php8.2-fpm.service Now, do all of the following optimizations to PHP files.
sed -i "s/;env\[HOSTNAME\] = /env[HOSTNAME] = /" /etc/php/8.2/fpm/pool.d/www.conf
sed -i "s/;env\[TMP\] = /env[TMP] = /" /etc/php/8.2/fpm/pool.d/www.conf
sed -i "s/;env\[TMPDIR\] = /env[TMPDIR] = /" /etc/php/8.2/fpm/pool.d/www.conf
sed -i "s/;env\[TEMP\] = /env[TEMP] = /" /etc/php/8.2/fpm/pool.d/www.conf
sed -i "s/;env\[PATH\] = /env[PATH] = /" /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm = dynamic/pm = static/' /etc/php/8.2/fpm/pool.d/www.conf sed -i 's/pm.max_children =.*/pm.max_children = 200/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm.start_servers =.*/pm.start_servers = 100/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm.min_spare_servers =.*/pm.min_spare_servers = 60/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm.max_spare_servers =.*/pm.max_spare_servers = 140/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i "s/;pm.max_requests =.*/pm.max_requests = 1000/" /etc/php/8.2/fpm/pool.d/www.conf
sed -i "s/allow_url_fopen =.*/allow_url_fopen = 1/" /etc/php/8.2/fpm/php.ini sed -i "s/output_buffering =.*/output_buffering = Off/" /etc/php/8.2/cli/php.ini
sed -i "s/max_execution_time =.*/max_execution_time = 3600/" /etc/php/8.2/cli/php.ini
sed -i "s/max_input_time =.*/max_input_time = 3600/" /etc/php/8.2/cli/php.ini
sed -i "s/post_max_size =.*/post_max_size = 10240M/" /etc/php/8.2/cli/php.ini
sed -i "s/upload_max_filesize =.*/upload_max_filesize = 10240M/" /etc/php/8.2/cli/php.ini
sed -i "s/;date.timezone.*/date.timezone = Asia\/\Taipei/" /etc/php/8.2/cli/php.ini
sed -i "s/;cgi.fix_pathinfo.*/cgi.fix_pathinfo=0/" /etc/php/8.2/cli/php.ini sed -i "s/memory_limit = 128M/memory_limit = 1G/" /etc/php/8.2/fpm/php.ini
sed -i "s/output_buffering =.*/output_buffering = Off/" /etc/php/8.2/fpm/php.ini
sed -i "s/max_execution_time =.*/max_execution_time = 3600/" /etc/php/8.2/fpm/php.ini
sed -i "s/max_input_time =.*/max_input_time = 3600/" /etc/php/8.2/fpm/php.ini
sed -i "s/post_max_size =.*/post_max_size = 10G/" /etc/php/8.2/fpm/php.ini
sed -i "s/upload_max_filesize =.*/upload_max_filesize = 10G/" /etc/php/8.2/fpm/php.ini
sed -i "s/;date.timezone.*/date.timezone = Asia\/\Taipei/" /etc/php/8.2/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo.*/cgi.fix_pathinfo=0/" /etc/php/8.2/fpm/php.ini
sed -i "s/;session.cookie_secure.*/session.cookie_secure = True/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.enable=.*/opcache.enable=1/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.validate_timestamps=.*/opcache.validate_timestamps=1/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.enable_cli=.*/opcache.enable_cli=1/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.memory_consumption=.*/opcache.memory_consumption=256/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.interned_strings_buffer=.*/opcache.interned_strings_buffer=64/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.max_accelerated_files=.*/opcache.max_accelerated_files=100000/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.revalidate_freq=.*/opcache.revalidate_freq=0/" /etc/php/8.2/fpm/php.ini
sed -i "s/;opcache.save_comments=.*/opcache.save_comments=1/" /etc/php/8.2/fpm/php.ini sed -i "s|;emergency_restart_threshold.*|emergency_restart_threshold = 10|g" /etc/php/8.2/fpm/php-fpm.conf
sed -i "s|;emergency_restart_interval.*|emergency_restart_interval = 1m|g" /etc/php/8.2/fpm/php-fpm.conf
sed -i "s|;process_control_timeout.*|process_control_timeout = 10|g" /etc/php/8.2/fpm/php-fpm.conf sed -i '$aapc.enable_cli=1' /etc/php/8.2/mods-available/apcu.ini sed -i 's/opcache.jit=off/; opcache.jit=off/' /etc/php/8.2/mods-available/opcache.ini
sed -i '$aopcache.jit=1255' /etc/php/8.2/mods-available/opcache.ini
sed -i '$aopcache.jit_buffer_size=256M' /etc/php/8.2/mods-available/opcache.ini
sed -i "s/rights=\"none\" pattern=\"PS\"/rights=\"read|write\" pattern=\"PS\"/" /etc/ImageMagick-6/policy.xml
sed -i "s/rights=\"none\" pattern=\"EPS\"/rights=\"read|write\" pattern=\"EPS\"/" /etc/ImageMagick-6/policy.xml
sed -i "s/rights=\"none\" pattern=\"PDF\"/rights=\"read|write\" pattern=\"PDF\"/" /etc/ImageMagick-6/policy.xml
sed -i "s/rights=\"none\" pattern=\"XPS\"/rights=\"read|write\" pattern=\"XPS\"/" /etc/ImageMagick-6/policy.xml sed -i '$a[mysql]' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.allow_local_infile=On' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.allow_persistent=On' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.cache_size=2000' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.max_persistent=-1' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.max_links=-1' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.default_port=3306' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.connect_timeout=60' /etc/php/8.2/mods-available/mysqli.ini
sed -i '$amysql.trace_mode=Off' /etc/php/8.2/mods-available/mysqli.ini We optimize PHP PostgreSQL.
sed -i '$a[pgsql]' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.allow_local_infile=On' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.allow_persistent=On' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.cache_size=2000' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.max_persistent=-1' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.max_links=-1' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.default_port=3306' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.connect_timeout=60' /etc/php/8.2/mods-available/pgsql.ini
sed -i '$apgsql.trace_mode=Off' /etc/php/8.2/mods-available/pgsql.ini PHP 8.x is now installed and optimized, so that we can restart the service.
systemctl restart php8.2-fpm.service nginx.service Within the nginx web server, we need to change to the updated PHP 8.2. Inorder to do this, we open the following file.
vim /etc/nginx/nginx.conf And replace the socket entry 8.1 with 8.2:
[...]
upstream php-handler {
server unix:/run/php/php8.2-fpm.sock;
}
[...]
Test that nginx web server is properly functioning correctly.
nginx -t Now restart with all of the relevant server services
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off service redis-server restart && service mariadb restart && service nginx restart && service postgresql restart FYI: We may need to set system default PHP to version 8.2. There are two ways to do this:
sudo update-alternatives --set php /usr/bin/php8.2
sudo update-alternatives --config php
service php8.2-fpm restart
FYI: If you have PHP 8.0 or PHP 8.1 on your Server and want to remove. Do the following to remove the service from the Server:
apt remove --purge php8.0-*
apt remove --purge php8.1-*
rm -rf /etc/php/8.0/*
rm -rf /etc/php/8.1/* Congratulations, you now have your own personal data on your own secured Nextcloud 27 system with PHP 8.2, enjoy!
We at Ahuitech create clouds systems that allow you to have complete control of your Data.
Ahuitech – Cloud Creations are always in your Control

