Nextcloud 17 on FreeBSD 12


Now you have a basic FAMP stack, but we need some extra requirements for Nextcloud. The official instructions have a list of prerequisites, mainly PHP extensions. Here’s the command to run to install the required and recommended extensions from the FreeBSD ports collection:

pkg install -y php73-extensions php73-curl php73-gd php73-mbstring \
    php73-openssl php73-zip php73-zlib php73-pdo_mysql \
    php73-fileinfo php73-bz2 php73-intl

Other useful (but optional) prerequisites:

pkg install -y ffmpeg php73-exif php73-pecl-imagick-im7 php73-pcntl

Once everything is installed, run service php-fpm restart to load the new PHP modules.

Installing files

Download, verify, and extract the Nextcloud files. Note: curl, gpg, and shasum aren’t available in the base install of FreeBSD, but they can easily be installed with pkg install curl gnupg p5-Digest-SHA. Alternatively, you can use fetch -qo- instead of curl.


shasum -a 256 -c nextcloud-17.0.0.tar.bz2.sha256

curl | gpg --import
gpg --verify nextcloud-17.0.0.tar.bz2.asc

tar -xf nextcloud-17.0.0.tar.bz2 \
    -C /usr/local/www/apache24/data/
chown -R www:www /usr/local/www/apache24/data/nextcloud/

Installation wizard

Since we haven’t yet set up SSL encryption, running the install wizard in a browser is not recommended, unless you’re working on a local network, as any passwords you submit will be sent unencrypted. Luckily, there’s a command-line tool that can be used instead. (If you’re running locally and decide you’d rather try the web version, just go to and follow the given instructions using the same details as below.)

First, gather all the necessary information. You’ll need an admin user with a strong password, the data directory, and the database name, database user, and database user’s password.

You can keep the default data directory (/usr/local/www/apache24/data/nextcloud/data), but Nextcloud recommends putting it outside the web root for security. This isn’t strictly necessary for Apache, however, as Nextcloud includes an .htaccess file to deny requests to the data directory. There’s no standard location for the data directory, so it can be anywhere you want, so long as it already exists and is owned by the web server user. According to the Filesystem Hierarchy Standard, /srv is a good location for site-specific data, so let’s go with that:

mkdir -p /srv/nextcloud-data
chown www:www /srv/nextcloud-data

Now it’s time to run the installation command. This must be run in the Nextcloud directory as the web server user:

cd /usr/local/www/apache24/data/nextcloud
su -m www -c 'php occ maintenance:install \\
    --database="mysql"                    \\
    --database-name="nextcloud"           \\
    --database-user="nc_admin"            \\
    --database-pass="<password>"          \\
    --admin-user="admin"                  \\
    --admin-pass="<password>"             \\

(The double backslashes are there so the command can extend to multiple lines.)

If all went well, you’ll see the message “Nextcloud was successfully installed”. This would be a good time to set up SSL encryption before doing anything in the web interface, which is available at

Since we used the command-line tool to install, you’ll probably see a message saying you’re accessing the site through an untrusted domain. This is fixed by editing the file /usr/local/www/apache24/data/nextcloud/config/config.php and adding your server IP and/or domain name to the trusted_domains array:

'trusted_domains' =>
array (
  0 => 'localhost',
  1 => '<server_ip>',
  2 => '',

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.