Installing Nextcloud on a FreeBSD VPS
Introduction
Nextcloud is an exciting new fork of OwnCloud. I have been meaning to try it out lately and I finally got around to doing it. I picked Vultr{.add-link} for this instance since they have really affordable "Spinny Disk" instances starting at just \$5/mo for 125GB. The performance is noticeably slower than SSD, but if you are looking for a low cost place to store all of your files then this deal cannot be beat. Vultr also comes with full support for FreeBSD out of the box, which is a great choice for a system like this. The official Nextcloud documentation is wonderful, however it seems like it geared toward large multi-user installs. The purpose of this guide is to make it easy to install Nextcloud for a single (or just a few) user system. If you follow this guide you will have the latest stable version of Nextcloud with PHP7, Apache 2.4, MySQL 5.7 and Redis secured with LetsEncrypt on the latest stable version of FreeBSD.Pre Requisites
In order to complete this guide successfully with a TLS enabled Nextcloud site you must have a domain name with DNS that successfully resolves to the IP address of your VPS Server.Configuration Steps
- Launch a new Storage Instance in the DC of your choice. In my specific case I am running a 512MB RAM/125GB HD instance in the Los Angeles Data Center.
- SSH into the new VPS.
- Update and Upgrade BSD
- Add some swap By default, the storage instance does not come with a swap partition, since I chose the smallest instance with 512MB of RAM, it is probably a good idea to add some swap because if the system ever runs out of memory the whole entire thing will come crashing down. You can read more about how to add swap in FreeBSD, but the gist of it is: If everything was successful, running htop you should now see some swap space.
- Install and Configure BAMP Stack (BSD, Apache, MySQL, PHP) and Redis
- Install all packages and dependencies
pkg install apache24 mysql57-server redis php70 mod_php70 php70-pdo_mysql \ php70-redis php70-gd php70-curl php70-json php70-zip php70-dom \ php70-xmlwriter php70-xmlreader php70-xml php70-mbstring php70-ctype \ php70-zlib php70-simplexml php70-hash php70-fileinfo php70-posix \ php70-iconv php70-filter php70-openssl
- Add Services to
/etc/rc.conf
# /etc/rc.conf
… apache24_enable=“yes” mysql_enable=“yes” redis_enable=“yes”
- Configure Apache Ensure that the rewrite and ssl modules are enabled (uncommented) in
/usr/local/etc/apache24/httpd.conf
.# /usr/local/etc/apache24/httpd.conf
…
LoadModule ssl_module libexec/apache24/mod_ssl.so LoadModule rewrite_module libexec/apache24/mod_rewrite.so
…
/usr/local/etc/apache24/modules.d
# /usr/local/etc/apache24/modules.d/001_mod_php.conf
<FilesMatch ".php$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch ".phps$"> SetHandler application/x-httpd-php-source </FilesMatch>
- Configure MySQL Once MySQL has been added to
/etc/rc.conf
you can start it up by executing the following command in your shell:/usr/local/etc/rc.d/mysql-server start
$HOME/.mysql_secret
, use this password to log into MySQL, change the root password, and then create a new admin user for Nextcloud.# Grab the Root Password cat ~/.mysql-secret
Log into MySQL
mysql -u root -p $PASSWORD # Password from previous step
Change the Root Password
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘$NEW_PASSWORD’;
Create New Schema for Nextcloud
CREATE DATABASE nextcloud;
Create New Admin User for Nextcloud
CREATE USER ’nextcloud_admin’@’localhost’ IDENTIFIED BY ‘$OTHER_NEW_PASSWORD’;
Grant Permissions to the new Admin user to the Nextcloud Schema
GRANT ALL ON nextcloud.* TO ’nextcloud_admin’@’localhost’;
Refresh all Privileges
FLUSH PRIVILEGES;
- Configure Redis There are many different memory caching strategies for Nextcloud. I like using Redis for this sort of thing, you can chose whichever strategy you prefer. The following (optional) configuration will make redis run on a local socket instead of over TCP. This is better from a security perspective. Update
/usr/local/etc/redis.conf
to run on local socket# /usr/local/etc/redis.conf
…
port 0 …
unixsocket /tmp/redis.sock unixsocketperm 750
www
user to thewheel
group so that it has permission to access this socket.pw groupmod wheel -m www
/usr/local/etc/rc.d/redis start
/tmp
# ls -al /tmp total 48 drwxrwxrwt 7 root wheel 512 Sep 1 23:02 . drwxr-xr-x 18 root wheel 512 Sep 1 22:03 ..
…
srwxr-x— 1 redis wheel 0 Sep 1 23:02 redis.sock
…
- Install all packages and dependencies
- Download Nextcloud We are almost there! The last few steps are to actually download and configure Nextcloud. You can get the latest version of Nextcloud from here.
# Go to the default apache data directory cd /usr/local/www/apache24/data
Download Nextcloud
wget https://download.nextcloud.com/server/releases/nextcloud-10.0.0.zip
Unzip Nextcloud
unzip nextcloud-10.0.0.zip
Make sure the www user owns this directory
chown -R www:www nextcloud
- Install and run certbot by LetsEncrypt The full instructions are available here but the gist is:
Go through the certbot UI and fill out your site specific details. If all goes well you should see a message that says:
Congratulations! Your certificate and chain have been saved at
/usr/local/etc/letsencrypt/live/$YOUR_SITE/fullchain.pem
- Create a VirtualHost Configuration for Nextcloud Create a new file called
$YOUR_SITE.conf
in/usr/local/etc/apache24/Includes
, the contents of this file should have a VirtualHost specification for your new Nextcloud site. The first VirtualHost will listen on port 80 and redirect all requests to HTTPS. The second VirtualHost will listen on port 443 and serve your actual Nextcloud site.<VirtualHost *:80> ServerAdmin $YOUR_EMAIL ServerName $YOUR_SITE
RewriteEngine on RewriteCond %{SERVER_NAME} =$YOUR_SITE RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] </VirtualHost>
Listen 443
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin $YOUR_EMAIL ServerName $YOUR_SITE
DirectoryIndex index.php DocumentRoot /usr/local/www/apache24/data/nextcloud SSLCertificateFile /usr/local/etc/letsencrypt/live/$YOUR_SITE/fullchain.pem SSLCertificateKeyFile /usr/local/etc/letsencrypt/live/$YOUR_SITE/privkey.pem SSLEngine on # Intermediate configuration, tweak to your needs SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA SSLHonorCipherOrder on SSLCompression off SSLOptions +StrictRequire <span class="nt"><Directory</span> <span class="err">/usr/local/www/apache24/data/nextcloud</span><span class="nt">></span> AllowOverride all <span class="nt"></Directory></span> <span class="nt"><IfModule</span> <span class="err">mod_headers.c</span><span class="nt">></span> Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" <span class="nt"></IfModule></span>
</VirtualHost> </IfModule>
/usr/local/etc/rc.d/apache24 start
- Configure Nextcloud
- Verify Installation Go to https://\$YOUR_SITE.com, verify that you get redirected to HTTPS and that the certificate shows up as valid.
- Create Admin Account If this page loads properly, you should create an admin user, set the data directory location, and fill in the database credentials from step 5.
- Tweak Config File We need to tweak the config file in order to enable Redis memory caching. Open up
/usr/local/www/apache24/data/nextcloud/config/config.php
and add:# /usr/local/www/apache24/data/nextcloud/config/config.php
…
‘memcache.locking’ => ‘\OC\Memcache\Redis’, ‘memcache.local’ => ‘\OC\Memcache\Redis’, ‘redis’ => array ( ‘host’ => ‘/tmp/redis.sock’, ‘port’ => 0, ),
- Use System Cron Job By default NextCloud uses an AJAX cron, the performance is a bit better if you let the system cron handle this. Add the following to the crontab:
# crontab -u www-data -e PATH=/usr/local/bin */15 * * * * php -f /usr/local/www/apache24/data/nextcloud/cron.php
- Enjoy Nextcloud That was a lot of steps, but now we have a private, self hosted, secure, and affordable Nextcloud instance. If you ran into any issues during installation please let me know in the comments below!
Next Steps
- Download the Nextcloud client for your Desktop or Mobile Device.
- Explore the Apps, my favorites are:
- News
- Tasks
- Join the Nextcloud Community
- Hack on Nextcloud
Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.
Check out some more stuff to read down below.
Most popular posts this month
- 2024
- Reinstalling Windows at 1am
- SQLite DB Migrations with PRAGMA user_version
- My Custom Miniflux CSS Theme
- How to Disable Wayland in Debian Testing
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- The AGI economy is coming faster than you think from Freethink
- Rolling the ladder up behind us from Xe Iaso's blog
- In Praise of “Normal” Engineers from charity.wtf
- Reports of Bluesky's death have been greatly exaggerated from The Torment Nexus
- What Would a Kubernetes 2.0 Look Like from matduggan.com
- We Can Just Measure Things from Armin Ronacher's Thoughts and Writings
- The Gentle Singularity from Sam Altman
- Whale Watching from https://popagandhi.com/
Articles from blogs I follow around the net
Pluralistic: Daniel de Visé's 'The Blues Brothers' (21 Jun 2025)
Today's links Daniel de Visé's 'The Blues Brothers': Far more than production gossip – an unmissable portrait of a turning point in American comedy and music. Hey look at this: Delights to delectate. Object permanence: 2005, 2010, 2015, 20…
via Pluralistic: Daily links from Cory Doctorow June 21, 2025Hiding metrics from the web
In 2012, artist Ben Grosser released a browser extension called Facebook Demetricator. Once installed, it hid all metrics from Facebook’s interface: likes, comments, notifications, unread messages, and so on. “What’s going on here is that these quantifica…
via Manual do Usuário June 21, 2025It's like surfing
The weird thing about engineering management is that you feel kinda useless. Yet if you stop, projects stop.
via swizec.com RSS Feed June 21, 2025Generated by openring