How to Install Nextcloud on Ubuntu Server

In this tutorial, we will be going through the steps to install Nextcloud on Ubuntu Server. Nextcloud is a free and open-source software designed for secure cloud collaboration, file sharing, and storage. It allows you to access your data from various devices and locations.

Prerequisites

Step 1 – Update System

Before installing Nextcloud, we need to update our system packages. Connect to your Ubuntu Server via SSH and run the following command:

sudo apt update && sudo apt upgrade

Step 2 – Install LAMP Stack

Nextcloud requires a web server, database server, and PHP to function. We will install these components using the LAMP stack.

sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql php-gd php-mbstring php-curl php-mcrypt php-xml php-imagick unzip wget

During the installation, you will be prompted to set a root password for the MySQL server. Be sure to select a strong, secure password.

Once the installation is complete, start the Apache and MySQL services using the following commands:

sudo systemctl start apache2
sudo systemctl start mariadb

MySQL Configuration

Next, we will configure MySQL for use with Nextcloud. Run the following command and follow the prompt:

sudo mysql_secure_installation

Choose "y" or "yes" for all prompts, except for the "VALIDATE PASSWORD PLUGIN" prompt. If you choose to use the password plugin, be sure to select a strong password.

Step 3 – Download Nextcloud

Download the latest version of Nextcloud from their official website.

cd ~
wget https://download.nextcloud.com/server/releases/nextcloud-21.0.1.zip

Extract the downloaded file:

unzip nextcloud-21.0.1.zip

Move the Nextcloud directory to the Apache web root directory.

sudo mv nextcloud /var/www/html/
sudo chown -R www-data:www-data /var/www/html/nextcloud/
sudo chmod -R 755 /var/www/html/nextcloud/

Step 4 – Apache Configuration

Next, we need to configure Apache to serve the Nextcloud site. Create a new Apache configuration file for the Nextcloud domain:

sudo vim /etc/apache2/sites-available/nextcloud.conf

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/nextcloud/
    ServerName example.com
    ServerAlias www.example.com

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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Be sure to replace "example.com" and "admin@example.com" with your domain name and email address.

Activate the configuration:

sudo a2ensite nextcloud.conf

Restart Apache to apply changes:

sudo systemctl restart apache2

Step 5 – Configure Nextcloud

Nextcloud configuration can be done via the web interface. Open your web browser and go to "http://example.com" (replace "example.com" with your domain name).

Follow the setup wizard to complete the installation. When prompted for a database type, select "MySQL/MariaDB". Enter the database name, user name, and password you created earlier.

Nextcloud will prompt you to create an administrator account. Create the account with a strong password.

Once you have completed the setup wizard, you will be redirected to the Nextcloud dashboard.

Conclusion

In this tutorial, you have learned how to install Nextcloud on Ubuntu Server using the LAMP stack. We also configured Apache to serve the Nextcloud site and completed the Nextcloud setup wizard. Now you can use your own cloud storage without relying on third-party services.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!