If you’re looking for a true self-hosted file share and sync platform, then Nextcloud is a good place to start. Here I will show you how to install Nextcloud on Ubuntu in a few easy-to-follow steps.
Nextcloud is a self-hosted file sharing application server that allows you to store your files, documents, and contacts from a centralized location. It is a true open source platform similar to Dropbox, Google Drive, OneDrive and other proprietary online storage services.
The problem with the big players is that you don’t know where your data is exactly and whether it is really safe from access by others. When it comes to some classified data that you don’t want to store on some third-party servers then it is good to go for something that you can control completely.
With Nextcloud you can synchronize everything between your devices and share files with others as well. Furthermore, you can create multiple accounts for friends/family. They will then be able to log into the server and store data, very similar to Dropbox, etc.
The server-side program of Nextcloud is meant to work on Linux operating systems, therefore any Linux user even the beginner one can easily install it. So without further ado, let’s get down to installation.
1. Install Apache Web Server
Since Nexcloud will run on a web browser, the first step will be to install the Apache Web Server.
sudo apt install apache2
Once installed, verify the status of Apache:
sudo systemctl status apache2
From the output above, we can see that the Apache Web Server is up and running.
2. Install PHP
Nextcloud is written in PHP programing language, so PHP is a basic requirement for Nextcloud code. Run the following commands to install PHP modules required or recommended by Nextcloud.
sudo apt install php libapache2-mod-php php-imagick php-common php-mysql php-gd php-json php-curl php-zip php-xml php-mbstring php-bz2 php-intl php-bcmath php-gmp php-dom unzip
Confirm your PHP version:
Reload Apache for the changes to take effect.
sudo systemctl reload apache2
3. Install and Configure MariaDB Database Server
sudo apt install mariadb-server
With the MariaDB servers installed, we need to set a password for the MariaDB admin user:
When it asks you to enter MariaDB root password, press
Enter key as the root password isn’t set yet. Then enter
Y to set the root password for MariaDB server. Remember to give the MariaDB root user a strong password.
Next, you can press
Enter to answer all remaining questions, which will remove anonymous user, disable remote root login and remove test database.
4. Create a Database and User for Nextcloud
Login as a root user to MariaDB:
sudo mysql -u root -p
Then create a new database for Nextcloud. This tutorial name the database
nextcloud, but you can use whatever name you like.
CREATE DATABASE nextcloud;
Next, create the database user and grant permissions on the
nextcloud database. I choose
nextcloud-user for a username, but you can use your preferred name for this user.
Don’t forget to replace
your-password with your preferred password.
GRANT ALL ON nextcloud.* TO 'nextcloud-user'@'localhost' IDENTIFIED BY 'your-password';
Reload privileges and exit.
FLUSH PRIVILEGES; EXIT;
Confirm if the user can connect to the database with the provided password:
mysql -u nextcloud-user -p
5. Download and Install Nextcloud
With the database configured, now it’s time to download Nexcloud. Nextcloud is distributed as a zip file. Check for the latest release from Nextcloud download page before pulling the archive.
As of this writing, the latest release is 23.0. Use the following command to download NextCloud:
Execute the below commands to unzip the package into
data directory where Nextcloud to store the user data, and set appropriate directory permissions:
sudo unzip nextcloud-23.0.0.zip -d /var/www/html/ sudo mkdir /var/www/html/nextcloud/data sudo chown -R www-data:www-data /var/www/html/nextcloud/
6. Configure Nextcloud
Nextcloud is now successfully installed. Open a web browser and point it to
http://server-ip/nextcloud/ to complete the final steps.
- Enter Username and Password to create an admin account.
- Specify Data folder. In our case it is
- Provide database connection settings (database user, password, and database name) as created in Step 4.
- Click the Finish setup button to complete installation of Nextcloud on Ubuntu.
You’ll find yourself logged in as the admin user, where you can start customizing your Nextcloud instance. Congratulation! You can start using it as your private cloud storage.
Optionally, you can secure your Nextcloud installation with free Let’s Encrypt SSL Certificate for your domain.
Thanks for using our tutorial to install Nextcloud on Ubuntu. I hope this was helpful.