Nextcloud and PHP8

 



PHP8 broke my Nextcloud instance !!!

I run a Nextcloud instance on a self hosted Arch linux server. Arch linux because I like the challenge 😁. Nextcloud due to privacy reasons. Recently Arch upgraded all php packages to php8. Nextcloud 20.x, the version I'm using currently can't work on php8 thus my instance went offline. In this article I'm gonna describe how I managed to fix this issue.

I run timeshift in my server via the cli. So I could have downgraded the php version. That would mean I would have to refrain from updating php and risk zero day vulnerabilities. That would nullify the whole purpose of running a self hosted Nextcloud instance for my sensitive data. Instead I went with dual php versions. I run php-fpm with Apache in my server so now I have to figure out how to run Fast CGI process manager with 2 php versions in the same Apache server. If you are thinking "well you are a SDE and you should know it", let me start by saying I neither use PHP nor Apache in my day job. As a matter of fact none of the tech stacks mentioned here are used in my day job. The exception is linux of course. 

Arch announced that PHP 7 legacy packages will be maintained with a limited support timeline. So I started by installing the required packages. 

`sudo pacman -S php7 php7-fpm php7-gd php7-imagick php7-intl php7-apcu`

Confirmed php7 is working by running `php7 -v`

Now I need to enable the needed extensions. Edit the ini `sudo vim /etc/php7/php.ini` and uncomment/changed the following,

extension=gd
extension=iconv
extension=pdo_mysql
extension=bz2
extension=bcmath
extension=gmp
extension=intl
opcache.enable=1
zend_extension=opcache
pocache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumpion=128
opcache.save_comments=1
opcache.revalidate_freq=1
memory_limit = 2048
output _buffering = off

Enable imagick in systemd service. `sudo vim /etc/php7/conf.d/imagick.ini` and uncomment,

extension=imagick

Edit the php-fpm systemd service `sudo vim /etc/php/php-fpm.d/www.conf` and uncomment/change the following,

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
request_terminate_timeout = 3600
pm=dynamic
pm.max_children=120
pm.start_servers=12
pm.min_spare-servers=6
pm.max_spare_servers=18

Add the apcu settings to the php systemd service. `sudo vim /etc/php7/conf.d/apcu.ini` and add

extension=apcu
apc.enable_cli=1
apc.tl=7200

Now I need to tell my nextcloud virtual host to use the correct php version. Edit `/etc/httpd/conf/vhosts/[my vhost].conf` and add the following,

<FilesMatch \.php$>
      SetHandler "proxy:unix:/run/php-fpm7/php-fpm.sock|fcgi://localhost"
</FilesMatch>

Restart/Start the systemd services

`systemctl enable --now php-fpm7.service`
`systemctl restart httpd`

That's it. My Nextcloud instance is up and running again. Most of the above settings/configs are Nextcloud related optimizations I have done to my instance. I have a plan to write an article on setting up Nextcloud from scratch. Stay tuned...




Comments

Popular posts from this blog

Setting up KDiff3 to work with TortoiseGIT

Nextcloud on Arch Linux (Encrypted System) [Part 01 - Preparation]