Install NextCloud Server by Manual Method On Ubuntu 16.04 | 18.04 With Apache2, MariaDB And PHP 7.3

Install MariaDB Server

After installation, we can now verify that the installation is successful and our MariaDB server is up and running by using the below command.

sudo apt install mariadb-server


[email protected]:~# service mariadb status
 ● mariadb.service - MariaDB 10.4.11 database server
    Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Drop-In: /etc/systemd/system/mariadb.service.d
    Active: active (running) since Tue 2020-01-07 04:43:41 UTC; 59s ago

After that, run the below command for setting up a root password for our Database and prevent remote access.


As a result, you will see the below choices.

  • Enter current password for root (enter for none): Just press the Enter
  • Switch to unix_socket authentication [Y/n]: n
  • Change the root password? [Y/n]: y
  • New password: Enter the new password
  • Re-enter new password: Repeat the new password
  • 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

After that restart the MariaDB Server by using the below command.

service mariadb restart

Now test if you can log in into the database server by using the below command.

sudo mysql -uroot -p


[email protected]:~# mysql -uroot -p
 Enter password: 
 Welcome to the MariaDB monitor.  Commands end with ; or \g.
 Your MariaDB connection id is 38
 Server version: 10.4.11-MariaDB-1:10.4.11+maria~bionic-log binary distribution
 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 MariaDB [(none)]> 

Create a Database for the Nextcloud Server

Create a blank database in MariaDB for the Nextcloud server By running the below command.

mysql -uroot -p -e "CREATE DATABASE nextcloud;"

Now create a user for the above database by using this command. Remember to replace my_password with a strong password.

mysql -uroot -p -e "CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'my_password_here';"

Giving full permission to the nextcloud user for the Database by using the below command.

mysql -uroot -p -e "GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' WITH GRANT OPTION;"

After that, apply changes with the below command.

mysql -uroot -p -e "FLUSH PRIVILEGES;"

After that, we have our Web Server and Database Server up and running. Now We are ready to install the Nextcloud Web App in our Server.

Step 4: Download and Install Nextcloud 17.0.2

The latest stable version of Nextcloud is 17.0.2 which is released on 20 December 2019. Download the zip file by running this command.

cd /var/www/

If unzip is not installed then run this command to install unzip.

sudo apt-get install unzip

After that, Unzip the downloaded file by using this command.


Apply the required permissions to the extracted folder by using this command.

chown -R www-data:www-data /var/www/nextcloud/
chmod -R 775 /var/www/nextcloud/

Configure Apache for Nextcloud

After unzipping the files, we have to configure apache for serving the nextcloud directory as our root directory. For configuring apache disable the default host configuration by using this command.

a2dissite 000-default.conf

Now we create a new file with a custom configuration for our Nextcloud server. So create a new file in apache sites-available directory by using this command.

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

Now copy and paste the below configuration in the file and save it. Remember to replace by your own domain name.

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/nextcloud/

     <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud

     ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
     CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined


Enable the nextcloud config and apache rewrite module

After creating a configuration file for our nextcloud server we have to enable it by using the below command.

sudo a2ensite nextcloud

Apache rewrite module is recommended for the nextcloud. So Enable it by running the below command.

sudo a2enmod rewrite

After that, restart the apache web server by running this command.

sudo service apache2 restart

As a result, you can see the initial configuration page when you point your browser to your domain.


Provide the required details and click on Finish Setup. You can see the below screen after you click on the Finish setup button.



In this article we learn, How to install and configure Nextcloud 17 Server with Apache, PHP 7.3 and MariaDB. You can share your thoughts and suggestions in the comment section. Share It if you like the article.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *