Self-Hosting Guide: Nextcloud
· How to install and configure Nextcloud on Ubuntu.
Table of Contents
1. What is Nextcloud?
Nextcloud is a self-hosted solution for storage, communications, editing, calendar, contacts, and more.
This tutorial assumes that you have an Ubuntu server and a domain name configured to point toward the server.
2. Install Dependencies
To start, you will need to install the packages that Nextcloud requires:
3. Set Up MySQL
Next, you will need to log in to MySQL as the root user of the machine.
Once you've logged in, you must create a new user so that Nextcloud can manage the database. You will also create a nextcloud database and assign privileges:
@'localhost' IDENTIFIED BY 'password';
NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALL PRIVILEGES ON nextcloud.** TO 'username'@'localhost';
FLUSH PRIVILEGES;
quit;
4. Download & Install Nextcloud
To download Nextcloud, go the Nextcloud downloads page, click on Archive File and right-click the big blue button to copy the link.
Then, go to your server and enter the following commands to download, unzip, and move the files to your destination directory. This example uses example.com as the destination, but you can put it wherever you want to server your files from.
5. Configure the Apache Web Server
Now that the database is set up and Nextcloud is installed, you need to set up the Apache configuration files to tell the server how to handle requests for example.com/nextcloud.
First, open the following file in the editor:
Once the editor is open, paste the following information in. Then, save and close the file.
<VirtualHost *:80>
DocumentRoot /var/www/example.com
ServerName example.com
ServerAlias www.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example.com/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
Satisfy Any
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
</VirtualHost>
Once the file is saved, enable it with Apache:
Next, enable the Apache modules required by Nextcloud:
Finally, restart Apache. If any errors arise, you must solve those before continuing.
For the app to work, you must have the correct file permissions on your nextcloud directory. Set the owner to be www-data:
6. DNS
If you do not have a static internet protocol (IP) address, you will need to update your DNS (Domain Name System) settings (at your DNS provider) whenever your dynamic IP address changes.
For an example on how I do that with Cloudflare, see my other post: Dynamic DNS Record Updates via Cloudflare API.
7. Certbot
If you want to serve Nextcloud from HTTPS (Hypertext Transfer Protocol Secure) rather than plain HTTP (Hypertext Transfer Protocol), use the following commands to issue Let's Encrypt SSL (Secure Socket Layer) certificates:
8. Results
VoilĂ ! You're all done and should be able to access Nextcloud from your domain or IP address.