2023-11-22

[Technology] Nextcloud on a Raspberry Pi: setting up a web server, a database, PHP and Nextcloud itself

Installing Nextcloud on a Raspberry Pi can be fun, or "fun".  Run your own suite of open source web services for greater control, customization, independence, and whatever.  I'll share my process for installing it from a tarball on a Raspberry Pi (4) running Raspberry Pi OS (bookworm).  Let's hope I don't skip any steps.

My Pi, luxuriating on the soft bedding it deserves
 
Nextcloud's website offers a lot of options, and you can run Nextcloud in containers, install it from snaps, from Fedora's RPM repositories, etc. One benefit of installing it from a simple tarball, from its source, is that you can better understand a lot of its dependencies and the configuration needs.  I used their extensive directions found here:

Honestly, they're comprehensive enough that you can follow that instead of the below, but hopefully in the end I'll have a streamlined guide, at least for myself.

Regarding storage, going through this on my Raspberry Pi (already in use for other things) used 3.5GB of disk space. Going through it on the docker.io/library/debian:latest container image, I used 4.8GB of disk space (starting from a minimal 172MB!). And this is before user data gets accumulated. So if you want to store a lot, you will likely want to get a larger microSD card for your Pi or use some external USB storage.

Regarding performance, I've had some mixed results. During a demo to a group of friends on a local network using the nextcloudpi docker container, many features were quite slow. However, testing at home recently, using either the container or the source installation described below, those same features were now fast with very low latency!

Environment

My environment:

  • Hardware:
    • Raspberry Pi 4 Model B Rev 1.4
    • Storage: 29GB
  • OS:
    • Raspberry Pi OS (Debian GNU/Linux 12 (bookworm))
    • image: 2023-10-10-raspios-bookworm-arm64-lite.img
  • Nextcloud
    • version: 27.1.3
    • build: 2023-10-26T17:25:16+00:00 565dc36226d08d071c30d8ad4fd54126dfa4be79

Nextcloud can work with a variety of databases and web servers, and the choices can be overwhelming.  For this process, I'm going with their recommendations in their install guide and making some boring, conventional choices. 

Software choices:

  • web server: Apache
    • apache2-2.4.57-2
  • database: MariaDB (mysql)
    • mariadb-server-1:10.11.4-1~deb12u1

If you would like to follow along but don't have a Raspberry Pi to play with, you can get a very similar set-up experience using a standard Debian GNU/Linux 12 (bookworm) installation.  If you like containers, docker.io/library/debian:latest is currently bookworm.  I used that with podman to do testing along the way.

Another note is that I generally use systemd but feel free to use your favourite service manager/init system.

1. Set-up Environment

# # update the base system
# apt update
# apt upgrade
# # install some useful tools
# apt install vim
# apt install less
# apt install wget 
# # install some tools that Nextcloud requires
# apt install bzip2
  

2. Database

As noted above, I'm using MariaDB, a MySQL-compatible derivative. You'll create an empty database, as well as a username and a password, for Nextcloud. Nextcloud will handle table creation on its own. Don't forget to replace username and password with your own unique values below.

# apt install mariadb-server       # 18.3MB download, 197MB installed
# systemctl enable --now mariadb
# mysql -u root
> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
> CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
> GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'localhost';
> FLUSH PRIVILEGES;
  

Next, we need to add some configuration to MariaDB/MySQL in /etc/mysql/my.cnf (which maps to /etc/mysql/mariadb.cnf for me). The installation guide suggests the following settings. I'll note that my default config already has a similar [client-server] section, so I excluded I only added the other ones that weren't present. The transaction_isolation and binlog_format settings are particularly important.

[server]
skip_name_resolve = 1
innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1

[client-server]
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

[client]
default-character-set = utf8mb4

[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1    
  

Later on, when configuring Nextcloud itself, you'll provide it with the database name, username, password and host (in this case, localhost). You can manually configure it or use the web installation wizard (which I'll do for in post.)

3. PHP

Nextcloud requires a bunch of PHP modules, some of which were already installed on my system, and some not. Below I only show install commands for those that I were not already there. You can view Nextcloud's documentation to see all the modules they require and recommend, including some optional ones that I am skipping.

# apt install php
#
# # install required modules
# apt install php-curl
# apt install php-gd
# apt install php-json
# apt install php-mbstring
# apt install php-xml                  # SimpleXML, XMLReader, XMLWriter
# apt install php-zip
# apt install php-mysql                # for DB since I use MariaDB
#
# # install recommended modules
# apt install php-bz2                  # for installing packages
# apt install php-intl                 # faster language translation performance (I run it in German)
# apt install php-redis                # cache for faster performance; alt: php-acpu, php-memcached
# apt install redis-server             # see notes
# systemctl enable --now redis-server  # or redis-server
#
# # file preview generation
# apt install php-imagick              # image preview generation (22.4MB down, 84.0MB installed)
# apt install ffmpeg                   # video preview generation; alt: avconv;  (127MB down, 415MB installed)
# apt install libreoffice              # (318MB down, 1,235MB installed)
  

You may want to review suggested configuration changes to see which ones you need.

4. Web server

As noted above, I'm using Apache 2. We will enable some modules; several that Nextcloud want were enabled by default but I'm listing them anyway.

It's 2023, so of course we will encrypt our connections and traffic. In this case, we are going to use a default self-signed certificate, but if you are actually going to deploy it, at least use Let's Encrypt to get a certificate for your actual domain.

# apt install apache2
# systemctl enable --now apache2
#
# # required modules, for at least pretty urls :)
# a2enmod rewrite
# # recommended modules
# a2enmod headers
# a2enmod env            # already enabled for me
# a2enmod dir            # already enabled for me
# a2enmod mime           # already enabled for me
#
# # SSL
# a2enmod ssl
# a2ensite default-ssl
#
# # use php-fpm, Nextcloud recommends it over mod_php
# apt install php-fpm
# a2enmod proxy_fcgi
# a2enmod setenvif       # already enabled for me
# a2enconf php8.2-fpm
# systemctl enable --now php8.2-fpm
#
# systemctl restart apache2
# systemctl reload apache2
  

Next, we'll configure our Nextcloud site in Apache. You can set it up as either a sub-directory or a subdomain on your host. I picked sub-directory. More details here. Note that it disables mod_dav, as Nextcloud uses SabreDAV.

Nextcloud Apache Configuration

Create this file /etc/apache2/sites-available/nextcloud.conf with the following content:

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off
  </IfModule>
</Directory>
  

Afterwards, run this:

    a2ensite nextcloud.conf
    systemctl reload apache2
  

We will actually create and populate the /var/www/nextcloud directory when we finally get to installing Nextcloud itself from its tarball.

5. Nextcloud

Now that we have our web server, database, and PHP configured, we can finally install Nextcloud itself. As noted above, I am installing it from their latest source tarball. You can find it by going to their Install page > Community Projects > Archive, or just follow this direct link: https://download.nextcloud.com/server/releases/latest.tar.bz2.

# cd /var/www
# wget https://download.nextcloud.com/server/releases/latest.tar.bz2  # 172MB download, 607MB unpacked
# tar -xf latest.tar.bz2                                              # this unpacks 'nextcloud/' here at '/var/www/nextcloud'
# chown -R www-data:www-data /var/www/nextcloud/
#
# # verify that necessary services are running
# systemctl status mariadb
# systemctl status php8.2-fpm
# systemctl status apache2
  

Now, if everything went smoothly, you should be able to pop open https://yourpihostname:443/ and be greeted with the initial configuration page!

  • create an admin account
  • configure database settings (back from step #2 up above)
  • install recommended apps

Now you can have some fun playing around. Some features require extra configuration, like using Nextcloud Office with Collabora Online (Development Edition, CODE), and I may update this in the future with some more nuance.

Admin user and DB set-up screen


User dashboard with some test data added

Next steps

In a future post, I may discuss setting up a Google Docs-like experience with Nextcloud Office using Collabora Online office, as well as explore more of the options and configuration settings. I will also discuss the much-simpler ways of installing and running Nextcloud (e.g. from VM or container images!)

Update: just wrote up the very quick-to-start-but-deprecated nextcloudpi container image.

Keine Kommentare:

Kommentar veröffentlichen

Dieses Blog durchsuchen

Labels

#Technology #GNOME gnome gxml fedora bugs linux vala google #General firefox security gsoc GUADEC android bug xml fedora 18 javascript libxml2 programming web blogger encryption fedora 17 gdom git emacs libgdata memory mozilla open source serialisation upgrade web development API Spain containers design evolution fedora 16 fedora 20 fedora 22 fedup file systems friends future glib gnome shell internet luks music performance phone photos php podman preupgrade tablet testing typescript yum #Microblog Network Manager adb apache art automation bash brno catastrophe css data loss debian debugging deja-dup disaster docker emusic errors ext4 facebook fedora 19 gee gir gitlab gitorious gmail gobject google talk google+ gtk html libxml mail microsoft mtp mysql namespaces nautilus nextcloud owncloud picasaweb pitivi ptp python raspberry pi resizing rpm school selinux signal sms speech dispatcher systemd technology texting time management uoguelph usability video web design youtube #Tech Air Canada C Electron Element Empathy Europe GError GNOME 3 GNOME Files Go Google Play Music Grimes IRC Mac OS X Mario Kart Memento Nintendo Nintendo Switch PEAP Selenium Splatoon UI VPN Xiki accessibility advertising ai albums anaconda anonymity apple ask asus eee top automake autonomous automobiles b43 backup battery berlin bit rot broadcom browsers browsing canada canadian english cars chrome clarity comments communication compiler complaints computer computers configuration console constructive criticism cron cropping customisation dataloss dconf debug symbols design patterns desktop summit development discoverability distribution diy dnf documentation drm duplicity e-mail efficiency email english environment estate experimenting ext3 fedora 11 festival file formats firejail flac flatpak forgottotagit freedom friendship fuse galaxy nexus galton gay rights gdb german germany gimp gio gjs gnome software gnome-control-center google assistant google calendar google chrome google hangouts google reader gqe graphviz growth gtest gtg gvfs gvfs metadata hard drive hard drives hardware help hp humour ide identity instagram installation instant messaging integration intel interactivity introspection jabber java java 13 jobs kernel keyboard language language servers languages law learning lenovo letsencrypt libreoffice librpm life livecd liveusb login lsp macbook maintainership mariadb mario matrix memory leaks messaging mounting mouse netflix new zealand node nodelist numix obama oci ogg oggenc oh the humanity open open standards openoffice optimisation org-mode organisation package management packagekit paint shedding parallelism pdo perl pipelight privacy productivity progress progressive web apps pumpkin pwa pyright quality recursion redhat refactoring repairs report rhythmbox rust sandboxes scheduling screenshots self-navigating car shell sleep smartphones software software engineering speed sql ssd synergy tabs test tests themes thesis tracker travel triumf turtles tv tweak twist typing university update usb user experience valadoc video editing volunteering vpnc waf warm wayland weather web apps website wifi wiki wireless wishes work xinput xmpp xorg xpath
Powered by Blogger.