NextCloud on Arch Linux arm

15 Jan 2021

update: Fixed weird indentation issues and added more details

The easiest way to install NextCloud would be to use the NextCloudPi image which is based on Raspbian. I am quite fond of Arch Linux arm and use it on the Pi exposed to the internet so there was no question what to install on the older Pi 3B for using NextCloud. Only problem was the lack of a step by step guide for Arch. The Arch wiki on NextCloud is a great reference but it involved a lot of back and forth and searching the internet to set up NextCloud the way I wanted.

Here is a drill down if anybody else wanted to go down this path:

  1. Install Arch on Pi.

  2. Install prerequisites. I chose to go with postgresql as database:
    sudo pacman -S nextcloud nginx postgresql php-intl php-pgsql php-fpm smbclient ffmpeg libreoffice
    
  3. Uncomment certain extensions in /etc/php/php.ini:
    extension=pdo_pgsql
    extension=pgsql
    extension=gd
    extension=intl
    
  4. Configure OPcache as per the documentation in /etc/php/php.ini.
    opcache.enable=1
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=10000
    opcache.memory_consumption=128
    opcache.save_comments=1
    opcache.revalidate_freq=1
    
  5. Open the file /etc/php/php-fpm.d/www.conf and uncomment the following:
    env[PATH] = /usr/local/bin:/usr/bin:/bin
    env[TMP] = /tmp
    
  6. NextCloud needs certain PHP modules to function. Set it up by referring this guide. Most of the modules are already installed. Check for the modules by php -m. If anything is missing or you need anything extra install it from Arch repository by searching for php-<modulename>. I couldn’t find exif, bz2 and iconv modules in the repository.

  7. Uncomment the line session.save_path = "/tmp" in /etc/php/php.ini.

  8. Set up postgresql database. Make sure you note down the password for the database generated here:
    $ sudo -iu postgres
    [postgres]$ initdb -D /var/lib/postgres/data
    [postgres]$ exit
    $ sudo systemctl start postgresql
    $ sudo -iu postgres
    [postgres]$ createuser -h localhost -P nextcloud
    [postgres]$ createdb -O nextcloud nextcloud
    [postgres]$ exit
    
  9. Write to /etc/nginx/nginx.conf according to this documentation. I chose the first configuration for NextCloud in the webroot of nginx. Since its a local installation, I went with the static IP of my pi for the server address and generated self-signed SSL certificates to use locally.

  10. Verify the nginx config with sudo nginx -t.

  11. Create data storage directory
    $ mkdir /var/nextcloud
    $ chown http:http /var/nextcloud
    $ chmod 750 /var/nextcloud
    
  12. Fix apps directory permissions
    $ mkdir -p /usr/share/webapps/nextcloud/data
    $ chown -R http:http /usr/share/webapps/nextcloud/{apps,data}
    $ chmod 750 /usr/share/webapps/nextcloud/{apps,data}
    
  13. Create an override file for php-fpm service as per the wiki
    $ systemctl edit php-fpm.service
    

    This automatically creates an override.conf file. Add the following at the top:

    [Service]
    ReadWritePaths = /usr/share/webapps/nextcloud/apps
    ReadWritePaths = /usr/share/webapps/nextcloud/data
    ReadWritePaths = /etc/webapps/nextcloud/config
    
    # Replace the following path with the Nextcloud data directory
    ReadWritePaths = /var/nextcloud
    
  14. Enable nginx, postgresql and php-fpm service and start them. We have already started the postgresql service in Step 8.
    sudo systemctl enable php-fpm
    sudo systemctl enable postgresql
    sudo systemctl enable nginx
    sudo systemctl start php-fpm
    sudo systemctl start nginx
    
  15. Create a Pacman hook to upgrade NextCloud automatically on updates.
    [Trigger]
    Operation = Install
    Operation = Upgrade
    Type = Package
    Target = nextcloud
    Target = nextcloud-app-*
    	
    [Action]
    Description = Update Nextcloud installation
    When = PostTransaction
    Exec = /usr/bin/runuser -u http -- /usr/bin/php /usr/share/webapps/nextcloud/occ upgrade
    

Navigating to the static IP opened NextCloud with an error for locale. I had to set my locale to en_US.UTF-8 by following this guide on Arch wiki and reboot before the locale could take effect. Once that was fixed, NextCloud was up and running with the set up screen asking to create admin user and to enter the database details created earlier.

Day 71 - Join Me in #100DaysToOffload

tag: 100daystooffload nginx nextcloud