NextCloud is a self-hosted, free, open-source cloud storage solution for those unaware. It is similar to Dropbox, Google Drive, iCloud, and other cloud storage services. NextCloud returns ownership and security of your critical data to you, removing the need for a third-party cloud hosting service. This guide will demonstrate how to install Nextcloud on Ubuntu 22.04 LTS.
I will demonstrate the installation of Nextcloud on Ubuntu 22.04 step by step. This tutorial assumes you have at least a fundamental understanding of Linux, are familiar with the shell, and, most importantly, host your website on a VPS. If you are not using the root account, you may need to append “sudo” to the instructions to obtain root access.
Prerequisites
- A server running Ubuntu 22.04, 20.04.
- You should install the operating system from scratch to avoid any potential complications.
- SSH access to the server, or if you’re on a desktop, launch Terminal.
- A non-root user with Sudo or root access. However, we recommend using a non-root sudo user, as carelessness when working as root can destroy your system.
Install Nextcloud on Ubuntu 22.04 LTS
Step 1. First, run the following apt commands in the terminal to ensure that all your system packages are up to current.
sudo apt update
sudo apt upgrade
Step 2. Installing Apache HTTP Server on Ubuntu 22.04.
Apache is available by default in the Ubuntu 22.04 basic repository. Now use the command below to install the most recent version of Apache on your Ubuntu system::
sudo apt install apache2 apache2-utils
Enable Apache (so that it starts automatically at system boot), start it, and verify its status with the commands below:
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2
You can verify the Apache2 version with the command listed below.:
apache2 -v
Step 3. Installing MariaDB on Ubuntu 22.04.
Enable MariaDB (so that it starts automatically at system boot), run it, and test its status using the procedures listed below.:
sudo apt install mariadb-server
After successfully installation, enable MariaDB (to start automatically upon system boot), start, and verify the status using the commands below:
sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo systemctl status mariadb
Verify the installation and check the version of MariaDB’s installed:
mariadb --version
Step 4. Installing Nextcloud on Ubuntu 22.04.
Nextcloud is not available by default in the Ubuntu 22.04 basic repository. Now use the following command to install the latest stable version of Nextcloud on your Ubuntu system:
wget https://download.nextcloud.com/server/releases/nextcloud-24.0.4.zip
Now, extract the Nextcloud zip file to the webroot directory using the command listed below:
unzip nextcloud-24.0.4.zip mv nextcloud /var/www/html/
You will need to change some folders permissions:
chown -R www-data:www-data /var/www/html/nextcloud chmod -R 775 /var/www/html/nextcloud
Step 5. Configuring MariaDB for Nextcloud.
By default, MariaDB is not a secure database. The MySQL secure installation script allows you to secure MariaDB. Set a root password, remove anonymous users, block remote root login, and delete the test database and access to secure MariaDB:
mysql_secure_installation
Configure it like this:
Set root password? [Y/n] y Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
Now, we must log in to the MariaDB console and create a Nextcloud database. Execute the specified command:
mysql -u root -p
This will prompt you for a password; enter the root password for MariaDB and press Enter. After logging into your database server, you must create a database for the installation of Nextcloud:
MariaDB [(none)]> CREATE DATABASE next_db; MariaDB [(none)]> CREATE USER 'next_user'@'localhost' IDENTIFIED BY 'your-strong-password'; MariaDB [(none)]> GRANT ALL ON next_db.* TO 'next_user'@'localhost'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
Step 6. Configure Apache Virtual Host.
Now create Apache virtual host config file for Nextcloud:
sudo nano /etc/apache2/sites-available/www.your-domain.com.conf
Add the following file:
<VirtualHost *:80> ServerName your-domain.com ServerAlias www.your-domain.com ServerAdmin admin@your-domain.com DocumentRoot /var/www/html/nextcloud ErrorLog ${APACHE_LOG_DIR}/www.your-domain.com_error.log CustomLog ${APACHE_LOG_DIR}/www.your-domain.com_access.log combined <Directory /var/www/html/nextcloud> Options FollowSymlinks AllowOverride All Require all granted </Directory> </VirtualHost>
Save and close the file, then restart Apache in order for the changes to take effect:
sudo a2ensite www.your-domain.com.conf sudo a2enmod rewrite dir mime env headers sudo a2enmod ssl rewrite sudo systemctl restart apache2
Step 7. Secure Nextcloud with Let’s Encrypt.
If you want to have an SSL, you need to install Certbot to get an SSL cert with Let’s Encrypt:
sudo apt install certbot python3-certbot-apache
Now, get your SSL with Let’s Encrypt by following these steps:
sudo certbot --apache -d your-domain.com
You will need to install the certificate by following the interactive prompt. I will install SSL certificates for both of my domains, as I have two:
Step 8. Setup Auto-Renewal SSL.
Let’s Encrypt certificates are valid for 90 days, and it is highly recommended to renew them before they expire. You can test automatic certificate renewal by executing this command:
sudo certbot renew --dry-run
Output:
Step 9. Configure Firewall.
Now we configure a Simple Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS.:
sudo ufw allow OpenSSH sudo ufw allow 'Apache Full' sudo ufw enable
Step 9. Accessing WordPress Web Interface.
Once Nextcloud has been successfully installed, launch a web browser and navigate to https://your-domain.com to access the Nextcloud web UI wizard. The following page will be redirected to you: