Nextcloud is a free, open-source, self-hosted file sharing and collaboration platform. It gives you a private cloud storage alternative to Dropbox or Google Drive, with file syncing, calendar, contacts, a media player, and an app store of hundreds of extensions you can install to expand its capabilities.
Desktop clients for Windows, macOS, and Linux and mobile apps for Android and iOS keep your files synced across every device.
This guide covers how to install Nextcloud on Ubuntu 18.04 using Apache as the web server and MySQL as the database backend.
<strong>Prerequisite:</strong> You need sudo access and an existing MySQL or MariaDB installation on your server.
Log in to the MySQL shell:
bashsudo mysql
Create a dedicated database and user for Nextcloud. The utf8mb4 character set is used instead of plain utf8 because it supports the full Unicode standard, including four-byte characters such as emoji — which standard MySQL utf8 cannot store:
sqlCREATE 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;
Replace change-with-strong-password with a strong password. You will need these database credentials during the web setup wizard.
Nextcloud is a PHP application. PHP 7.2 is the default version in Ubuntu 18.04 and is fully supported by Nextcloud.
Install Apache, PHP 7.2, and all required extensions:
bashsudo 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
libapache2-mod-php7.2 integrates PHP into the Apache process through mod_php — this is what lets Apache execute .php files directly. Each extension covers a specific Nextcloud function: php7.2-imagick handles image thumbnails, php7.2-intl handles internationalization, php7.2-gd handles image processing, and php7.2-zip handles archive operations.
Open UFW ports for HTTP and HTTPS using the Apache Full profile:
bashsudo ufw allow 'Apache Full'
Download and extract Nextcloud. Check the Nextcloud download page for the latest version before running this command:
bashwget https://download.nextcloud.com/server/releases/nextcloud-15.0.0.zip -P /tmpsudo unzip /tmp/nextcloud-15.0.0.zip -d /var/wwwsudo chown -R www-data: /var/www/nextcloud
Apache runs as the www-data user. Setting ownership to www-data gives Apache full read and write access to Nextcloud’s files and directories. Without this, the server cannot write uploaded files, cached data, or configuration changes.
Create the Apache configuration file at /etc/apache2/conf-available/nextcloud.conf:
apacheAlias /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>
AllowOverride All allows Nextcloud’s .htaccess files to manage URL rewriting and access control. Dav off disables mod_dav on this directory to prevent conflicts with Nextcloud’s own built-in WebDAV implementation.
Enable the configuration and required Apache modules, then reload:
bashsudo a2enconf nextcloudsudo a2enmod rewrite headers env dir mimesudo systemctl reload apache2
Open http://your_domain_or_ip/nextcloud in a browser. The Nextcloud installation wizard loads.
Enter an admin username and password for your Nextcloud administrator account. Scroll down to the Database section, select MySQL, and fill in the database name (nextcloud), the username (nextclouduser), and the password you created earlier.
Click Finish setup. Nextcloud creates its database schema, prepares the file structure, and redirects you to the dashboard logged in as admin.
From the dashboard you can:
Important security step: Running Nextcloud over plain HTTP sends your login credentials and file data unencrypted. If your server has a domain name, add a Let’s Encrypt SSL certificate through Apache before making this installation accessible to users.
Nextcloud is now installed and running on Ubuntu 18.04. Set up your desktop and mobile sync clients, install the apps you need, and start using your private cloud. Leave a comment below if you run into any issues.