How to Setup Your Own Cloud Server with NextCloud

A step-by-step guide to creating your own cloud server with NextCloud, potentially saving money and boosting security.

Despite my affection for various cloud services and their cheap storage, there's something to be said for making your own "cloud server" with NextCloud. The biggest advantage with NextCloud is also a practical one – user control. Anything I load onto my NextCloud instance is as secure or insecure as I choose to make it. Plus, if I keep my NextCloud instance local to my LAN only, I greatly reduce the opportunity for my data being hacked. Today's various cloud services simply can't make that promise.

This article will show you how to setup your own NextCloud server on Ubuntu 16.04. You can set it up at your home, office or even make it available over the Internet.

Select your NextCloud server location

This first step might seem pretty obvious, however choosing the install location of your NextCloud server is an important step. Before you decide, let's examine the benefits and disadvantages of each choice.

VPS or similar – The advantage to using a VPS (Virtual Private Server) is that you're then free to access the server from anywhere with an Internet connection. Added bonus points go to keeping this from being associated with your home network. The disadvantage here is that it will cost you money. Also, you're exposing the contents of this server to the Internet. Even with server hardening and promptly applied patches as they're available, you're putting a lot of trust in NextCloud and your server's configuration.

Old PC on your LAN – The first big advantage here is obviously price. Short of potentially expanding the storage capacity of the old PC in question, running NextCloud on it will translate into a huge savings in comparison to buying a new server. The biggest advantage in my mind however is that you can make your NextCloud instance available for your LAN only. This means no exposure to the Internet and a malicious person must first penetrate your LAN's defenses before even touching your NextCloud install. Unfortunately you might find that using an older PC for NextCloud means extra power consumption added to your electric bill. If it's a really old PC like a Pentium 4 box, the costs could be quite noticeable.

Raspberry Pi on your LAN – Right off the bat, with a Pi you're running NextCloud on a low power consumption device. Also great is the fact that the hardware is decent enough to power NextCloud despite the Pi's low power footprint. The only downside I see to using a Pi is that your storage is running through USB ports to a secondary device. In some cases this can bottleneck a bit when sharing resources to other USB devices. For most people this is a moot issue, however I'd suggest that you'd want to limit your Pi to images and documents only.

What about NAS (Network Attached Storage) or exposing a PC to the Internet? As a standalone type of thing, I think that running a NAS is overkill. That said, it would be doable to do so with the NAS running other tasks like Plex, etc.

As for exposing an old PC to the Internet, well, that's fine if you want to get into VLANs, really strip down what the PC has access to and are comfortable advertising your network to co-workers and others accessing your NextCloud. From my perspective, I would rather keep it on LAN only.

Installing NextCloud

By now, I assume you've settled on the destination for your NextCloud instance. The next step is to begin the installation process.

Before we do anything, we need to make sure you're ready to run what's called a LAMP stack. This is Linux, Apache, MariaDB and PHP.

sudo apt-get update && sudo apt-get upgrade

Then install the LAMP stack:

sudo apt-get install apache2 apache2-utils

Now let's enable Apache.

sudo systemctl restart apache2

If for some reason this gives you an error, try this after checking the journalctl for errors…

sudo systemctl restart apache2.service

I prefer to use restart vs start as it saves us the extra hassle of checking for its status first. But, that's just my preferred approach to handling services. Now let's make sure Apache runs on each reboot.

sudo systemctl enable apache2.service

Now browse to your PC's LAN address and make sure you see the Apache welcome default page. This is how you know things are working.

Now that we have Apache setup, we need to make sure the directory where you'll house your NextCloud configuration has the right permissions.

sudo chown www-data /var/www/html/ -R

Okay, Apache is all set. Now it's time to install MariaDB so we can setup and manage the NextCloud database.
sudo apt-get install mariadb-server mariadb-client

With MariaDB installed, let's make sure it's enabled and running.
sudo systemctl restart mysql.service

Then make sure its enabled so it starts after a reboot.

sudo systemctl enable mysql.service


The final step of setting up MariaDB is to run the secure installation script. This will enable your root password and complete the overall MariaDB configuration.
sudo mysql_secure_installation

From this point forward, the script is going to prompt you along. You'll be asked to setup a root password unique to MariaDB(MySQL), disallow remote root access, remove the test database and so on. Once you've hit enter for each option, you'll see "Thanks for using MariaDB!"

With our database software installed, we need to install the last component – PHP. So let's start off by installing PHP7.

sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl libapache2-mod-php7.0

Once installed, we need to make sure Apache's PHP is enabled.

sudo a2enmod php7.0 && sudo service apache2 restart

The next step with PHP is to test it. There are a number of ways to do this, however most of those "in the know" agree that using this method is the most reliable way.
sudo touch /var/www/html/test.php

And then...

sudo echo "" >> /var/www/html/demo.php

Using the echo command, we're able to append the code to the demo file without needing to mess with any extra editing. Once the code is added, you can verify your Apache PHP settings are working by now browsing to your server's http://IP/demo.php

If you're looking at a neatly formatted page containing your PHP configuration, you're all set.

At this stage, you're ready to download the latest release of NextCloud. I recommend manually getting the latest release link from this link. For those of you doing this on a "headless server", you could do the following (making sure your link is up to date first).

wget https://download.nextcloud.com/server/releases/nextcloud-11.0.2.zip

With the zipped folder containing NextCloud downloaded, you're free to unzip its contents. Pro tip: make sure you have unzip installed first via your package manager.

unzip nextcloud-11.0.2.zip

With NextCloud's contents extracted, you're now ready to move the extracted files into the correct Apache enable directory.
sudo chown www-data:www-data /var/www/nextcloud/ -R

This is the point where you're actually moving past initial server setup and into actually configuring your NextBox installation itself.

Now it's time to set up your NextBox database in MariaDB.

First login to your MariaDB root password:

mysql -u root -p

Once logged into the MySQL prompt, you'll want to create your NextCloud database (remember you can choose the database name):

create database YourCreatedDatabaseName;

Next, we want to create a non-root user for this database (You can create any username you wish):

create user UserNameForDatabase@localhost identified by 'YourPassword';

Now we're ready to setup the proper database permissions for this NextCloud installation:

grant all privileges on YourCreatedDatabaseName.* to UserNameForDatabase@localhost identified by 'YourPassword';

With your database created and configured, we're ready to flush the privileges:

flush privileges;

And finally, we exit the MySQL prompt:

exit;

Still with me? Great! We're almost ready to finish this up. The next step is a tricky one where we setup the VirtualHost file for NextCloud.
sudo nano /etc/apache2/sites-available/nextcloud.conf

The contents of the conf file will be as follows:

  
DocumentRoot "/var/www/nextcloud"  
ServerName YourSelectedDomain.Whatever   

ErrorLog ${APACHE_LOG_DIR}/error.log  
CustomLog ${APACHE_LOG_DIR}/access.log combined  

  
Options +FollowSymlinks  
AllowOverride All   

  
Dav off  
   

SetEnv HOME /var/www/nextcloud  
SetEnv HTTP_HOME /var/www/nextcloud  
Satisfy Any  
  

If you're unsure about the domain for the servername for a LAN installation, you can use the IP address. If this is for a server on a VPS or similar, the same applies.

With the VirtualHost set up and ready to go, we need to move it from available to enabled status.

sudo ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf

Next, let's enable the needed modules to make sure NextCloud has everything it needs and restart Apache.
sudo a2enmod rewrite headers env dir mime setenvif

And then:

sudo systemctl restart apache2
  1. Now we're done and ready to browse to the NextCloud instance from a web browser. You can browse to the instance with either the IP address or if you setup your VirtualHost for it, you can use a domain name instead. Browse to the instance and you'll be asked to create an admin account. Also make sure your data folder looks right from what we setup earlier in the article.
  2. Still in the browser, we'll also be asked to enter the database user, database password and database name that we setup earlier. Remember this isn't the MySQL root info, this is the database info we setup specifically for NextCloud.

Don't let NextCloud setup intimidate you

If these steps seem a bit overwhelming for you, I would suggest the following – use VirtualBox. By setting up a VirtualBox VM with a bridged network adapter, you're able to test out a local configuration without needing to worry about messing up a server configuration. Once you feel comfortable with your skills in VirtualBox, you're then ready to try out NextCloud on an actual PC, Pi or server.

Do you use use NextCloud alternatives like Dropbox? Perhaps you're looking to try something new? Hit the comments, I'd be happy to listen to your NextCloud experiences.




Tags: cloud computing, Open Source App, NextCloud


0 Comments (click to add your comment)
Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 

IT Management Daily
Don't miss an article. Subscribe to our newsletter below.