How to Create Your Own Private Cloud with Nextcloud on Debian or Ubuntu
The cloud is one of the more prominent IT buzzwords of recent times. While it can have a number of meanings based on who is selling you a cloud solution, one of the main ones is referencing the use of resources on a remote computer. A number of companies offer similar cloud tools incorporating storage, file synchronization, document editing and more. The downside to public offerings is that you are sharing resources with other customers as well as being at the mercy of your provider with regards to security and protection.
Enter Nextcloud, the cloud storage and document editing solution that you manage yourself. If you have a dedicated server or VPS running a major Linux distribution, then Nextcloud is simple to install and provides many of the features you’d expect from a number of public cloud providers. It provides storage options with a number of apps to enable file synchronization from your PC, phone or tablet, calendar and contacts management, built-in chat features, and even version tracking of your files enabling you to restore a previous version should the worst happen. Nextcloud is also open source, which means that you can download, install and use it for free. And as it’s hosted on your server, you can lock it down to be as secure as you wish.
How to Install Nextcloud onto a Server
As it is a web based application the core requirements are for the Apache web server, PHP >= 5.6 and MySQL or MariaDB for a database. This means that it can be installed on a wide variety of systems, including alongside other sites on an existing web server.
If you are going to be setting up Nextcloud on a server with a control panel such as cPanel or Virtualmin installed on it, then you can use your control panel to set up an account for your Nextcloud installation.
If you don’t have anything configured on your server so far, then you can preconfigure it with the following commands:
sudo apt-get update
sudo apt-get install apache2 mariadb-server libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip
During this task, you will be prompted to set a password for MySQL’s root user. It’s important that you make a note of this password, as you will need it later.
Unless Nextcloud is going to be running as the only website on your server, then you’ll need to create a virtualhost for it. You can see our articles here on getting a virtualhost configured if you are unsure how.
Once you have an account/virtualhost set up for Nextcloud to work from, you can proceed to download the Nextcloud installer from the website. At the time of writing this post, 12.0.0 was the current version. Visit http://nextcloud.com/install to get the latest version.
This will download an archive of the software, extract it and copy the files contained within to the directory you have set up for Nextcloud. For example, assuming the usage of a virtualhost with the /var/www/nextcloud directory:
sudo mv -R * /var/www/nextcloud/
Next, we need to ensure that all the files are owned by the web-server’s user:
sudo chown -R www-data:www-data /var/www/nextcloud/
Finally, we’ll need to create a database user and account for Nextcloud to use. If you are using a control panel and have configured an account for Nextcloud, then the chances are that it will set up the database user account and database for you. First log into your database with the following command:
mysql -u root -p
You will be prompted for your password. Enter it and you will be at a command prompt starting with “mysql>”. At this prompt, enter the following commands:
create database nextcloud CHARACTER SET utf8 COLLATE utf8_bin;
grant all privileges on nextcloud.* to nextcloud@localhost identified by ‘mypasswd’;
You can change the database and usernames from nextcloud to whatever you want, and change mypasswd to the password you want to use. This will create the database details you need to use NextCloud on your server and then quit the MySQL command line.
Once the files are on your webserver and are accessible from the internet, it’s now time to move over to a web browser and start the configuration of Nextcloud. By navigating to the URL you chose for your Nextcloud installation in the web browser, you will be greeted with a simple form for you to perform the configuration.
First, it requires you to provide a username and password for the administrative user for the Nextcloud installation. Next is the path for where the Nextcloud files should be stored,. This defaults to the data directory inside the location where you installed Nextcloud. If you wish to use a different directory (for instance if you have disks on your server to be specifically used by Nextcloud for it’s storage) ensure that the path is owned by the www-data user on your server and enter it here. Finally, you need to provide the login credentials for your database.
Clicking the “Finish” button at the bottom will cause Nextcloud to complete its setup and take you to a screen providing information on how to get client software to allow your computer, tablet,or phone to synchronize files, calendars and contacts with your Nextcloud server. This final step means you are done and ready to go.