Read in 3 minutes
How To Install and Configure Nextcloud with Apache on Ubuntu 18.04
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 already 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
PHP 7.2, the default PHP version in Ubuntu 18.04 is not supported by Nextcloud.
To install PHP 7.1 on your server you can either follow this tutorial or enable the PHP 7.1 repository and install Apache and all required PHP extensions with the following commands:
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt install apache2 php7.1 php7.1-gd php7.1-json php7.1-mysql php7.1-curl php7.1-mbstring php7.1-intl php7.1-mcrypt php7.1-imagick php7.1-xml php7.1-zip libapache2-mod-php7.1
Step 3: Configuring firewall
Assuming you are using
UFW to manage your firewall, you 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
Download the latest version of Nextcloud from the Nextcloud download page:
cd /tmp wget https://download.nextcloud.com/server/releases/nextcloud-14.0.0.tar.bz2
At the time of writing this article, the latest version of Nextcloud is version 14.
Once the download is completed extract the Nextcloud archive and move the Nextcloud extracted files to the
tar xf nextcloud-*.tar.bz2 sudo mv /tmp/nextcloud /var/www/
Set the correct permissions 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.