How To Install and Configure Nextcloud with Apache on Ubuntu 18.04
3 min read
Nextcloud is an open source, self-hosted file share and collaboration platform, similar to Dropbox. It comes bundled with media player, calendar and contact management.
Nextcloud is extensible via apps and has desktop and mobile clients for all major platforms.
In this tutorial we’ll show you how to install and configure Nextcloud with Apache on an Ubuntu 18.04 machine.
Before starting with the tutorial, make sure you are logged in as a user with sudo privileges.
Step 1: Creating MySQL Database
NextCloud can use SQLite, PostgreSQL or MySQL database to store all its data. In this tutorial we will use MySQL as the database of choice.
If you don’t have MySQL or MariaDB installed on your Ubuntu server you can install by following one of the instructions below:
To create a database and user, first login to the MySQL shell by typing the following command:
Run the following SQL statements to create a database named
nextcloud, user named
nextclouduser and to grant all necessary permissions to the user:
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'change-with-strong-password'; FLUSH PRIVILEGES; EXIT;
Step 2: Installing PHP and Apache
Nextcloud is a PHP application. PHP 7.2 which is the default PHP version in Ubuntu 18.04 is fully supported and recommended for Nextcloud.
sudo apt install apache2 php7.2 php7.2-gd php7.2-json php7.2-mysql php7.2-curl php7.2-mbstring php7.2-intl php7.2-imagick php7.2-xml php7.2-zip libapache2-mod-php7.2
Step 3: Configuring firewall
Assuming you are using
UFW to manage your firewall, you’ll need to open HTTP (
80) and HTTPS (
443) ports. You can do that by enabling the ‘Apache Full’ profile which includes rules for both ports:
sudo ufw allow 'Apache Full'
Step 4: Downloading Nextcloud
At the time of writing this article, the latest stable version of Nextcloud is version 15.0.0. Before continuing with the next step visit the Nextcloud download page and check if there is a new version of Nextcloud available.
Start by download the latest version of Nextcloud using the following wget command:
wget https://download.nextcloud.com/server/releases/nextcloud-15.0.0.zip -P /tmp
Once the download is complete, extract the archive to the /var/www directory:
sudo unzip /tmp/nextcloud-15.0.0.zip -d /var/www
Set the correct ownership so that the Apache web server can have full access to the Nextcloud’s files and directories.
sudo chown -R www-data: /var/www/nextcloud
Step 5: Configure Apache
Open your text editor and create the following Apache configuration file.
sudo nano /etc/apache2/conf-available/nextcloud.conf
Alias /nextcloud "/var/www/nextcloud/" <Directory /var/www/nextcloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/nextcloud SetEnv HTTP_HOME /var/www/nextcloud </Directory>
Enable the newly added configuration and all required Apache modules with:
sudo a2enconf nextcloud sudo a2enmod rewrite sudo a2enmod headers sudo a2enmod env sudo a2enmod dir sudo a2enmod mime
Activate the changes by restarting Apache service:
sudo systemctl reload apache2
Step 6: Installing Nextcloud
Now that Nextcloud is downloaded and all necessary services are configured open you browser and start the Nextcloud installation by visiting your server’s domain name or IP address followed by
You will be presented with the Nextcloud setup page.
Enter your desired admin username and password and the MySQL user and database details you previously created.
Click on the
Finish setup button and once the installation process is completed you will be redirected to the Nextcloud dashboard logged in as admin user.
You have learned how to install and configure Nextcloud on your Ubuntu 18.04 machine. If you have a domain name associated with your Nextcloud server, you can follow this guide and secure your Apache with Let’s Encrypt.
To find more information about how to manage your Nextcloud instance visit the Nextcloud documentation page.
If you have any question, please leave a comment below.