Installing NextCloud in Cloud Raya- Detail Steps from the Beginning to the Very End

How can we help?
< All Topics
Print

Installing NextCloud in Cloud Raya- Detail Steps from the Beginning to the Very End

Have you ever saved your data without the ability to configure it in a more customizable way and free? It must be hard, isn’t it? 

One of the solutions in managing our data in a more advanced and safer way is by using NextCloud.

What is NextCloud?

In short, NextCloud is an open-source platform for cloud storage solutions that allow users to self-host. Functionally it is similar to cloud storage solution that we often hear and of course, most of us have used them (Dropbox, Google Drive, One Drive, etc.). 

Unlike other cloud providers, NextCloud gives more concern to our data privacy. Besides that, NextCloud can be installed on our on-premise server or in private virtual server (Cloud Raya’s VM for example). By that, we have more control over our data. 

We are also able to upload files to our NextCloud and then synchronize the files to our computer, laptop, or smartphone. 

NextCloud also provides many additional extension apps, making it more useful than just cloud storage.  

The Impact and Benefit from Using NextCloud

There are many impacts and benefits that we can get by using NextCloud, they are:  

  • Full control of our infrastructure 
  • Accessible from all devices, anywhere 
  • Groupware, sharing files within users or groups will be so much easier and well-controlled
  • Reliable and safe 
  • All-in-one-platform (file, address, calendar, chat, edit, email) 
  • Open-source and free 
  • End-to-end encryption, meaning the file can be encrypted in client’s device before uploaded to the server. So, even when someone tried to breach our server, they could not read our file.  

When Do We Need NextCloud Solution? 

From the benefits mentioned, these are the right moments for us using NextCloud: 

  • When cyber security becomes your main concern 
  • If you want to have alternative media for your main public cloud storage 
  • When you need more control of your data 
  • When you want to handle the limitation of scalability  

Cloud Raya x NextCloud

Deploying NextCloud in Cloud Raya’s VM will give many benefits and advantages to you, they are:   

  • Helps you to manage cloud storage in a much easier way 
  • Enjoy the best time to use NextCloud and Cloud Raya’s user-friendly panel  
  • Increase your storage capacity easier needs anytime 
  • Advance security with Cloud Raya’s Security Profile 
  • Responsive support from Cloud Raya’s support team who is always ready to help 

System & Specification Requirements 

There are several requirements that are recommended by NextCloud to be followed so the performance, stability, and functionality can run well: 

  • OS: Ubuntu 20.04 lts (recommended) 
  • Database: MySQL 8.0+ or MariaDB 10.2/10.3/10.4/10.5 (recommended) 
  • Webserver: Apache 2.4 with mod php or php-fpm (recommended) 
  • PHP Runtime: 7.4, 8.0, 8.1 (recommended) 

The system’s Requirement specification in running NextCloud’s server varies depending on the total user, application, file, and server’s activity volume. 

Though NextCloud needs a minimum of 128MB RAM, but NextCloud recommends us if we have minimum 512MB RAM in our system. 

For the number of CPU, can be started with 1 CPU, but also can use minimum 2 CPU if the number of users and workloads is increasing. 

Install NextCloud in Cloud Raya 

There are several steps that we should take before installing NextCloud in Cloud Raya’s VM. 

1. Prepare VM 

 First, prepare VM in Cloud Raya. For this article I will use VM with this specification: 

  • Linux Ubuntu 20.04 
  • 2 Core CPU 
  • 2GB RAM 

2. Ubuntu Software Packages Updates 

Access the VM, then we have to update the repository and software package first 

#sudo apt update 
#sudo apt upgrade 

3. Install LAMP Stack (Apache MariaDB PHP) 

Because NextCloud is written in PHP, so they need to install LAMP Stack first in our Ubuntu VM. 

Install Apache Web Server

Insert this command:

#sudo apt install -y apache2 apache2-utils

Apache20-utils command will install some utilities that can be useful, like Apache HTTP Server Benchmarking Tool and etc. 

After finishing the installation, Apache must be automatically turned on, we can check the status with systemcl. 

#systemctl status apache2 

Use this command to let the Apache always on automatically: 

#sudo systemctl enable apache2 

↳ Now we access the public IP from our VM in a browser, there should appear a default page from Apache2 Ubuntu. 

Now we need to set www-data (Apache user) as owner of a web root, because in default, web root is owned by the root user. Use this command: 

#sudo chown www-data:www-data /var/www/html/ -R 
Install MariaDB Database Server 

In this article we will use MariaDB as server database. Insert this command to install it: 

#sudo apt install mariadb-server mariadb-client 

After installing, MariaDB will automatically be active, we can check the status with systemctl 

#systemctl status mariadb 

 Use this command to make MariaDB always automatically active on every system booting: 

#sudo systemctl enable mariadb 

Now we run the post-installation security script 

#sudo mysql_secure_installation 

↳ When we asked to insert root password from MariaDB, we only need to click Enter because we just installed MariaDB. Then, push the Y button to start set root password. 

For further steps, you can look into this image below: 

In default, MariaDB’s package in Ubuntu uses unix_socket to authenticate user login. In other words, we can use user pass from OS for login to MariaDB’s console. So, we can run the command to login without having to insert password root from MariaDB. 

#sudo mariadb -u root 
Installing PHP 

In this article I will be using version 7.4 which is a stable version of PHP and so far running smoothly with NextCloud. Enter the following command to install php and some common PHP modules. 

#sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline 

Activate the PHP’s module and then restart Apache Web Server. 

#sudo a2enmod php7.4 
#sudo systemctl restart apache2 

 We also can check the information of PHP by giving below command. 

#php -–version 

4. Installing NextCloud 

 Okay, after LAMP stack is installed in our VM, now we can move to the NextCloud installation and configure some of the essential things so that NextCloud can runs well. 

Download NextCloud in Ubuntu 

 In the terminal, insert this command to download the newest version from NextCloud. 

#wget https://download.nextcloud.com/server/releases/latest.zip 

Once the download is finished, extract this archieve by using package unzip. Then we can process the package installation. 

#sudo apt install unzip 
#sudo unzip latest.zip -d /var/www/ 

–d option in the command functioned to decide the target directory. Meaning, the NextCloud files will be extracted to /var/www/nextcloud/

After that we need to change the owner from this directory to www-data so that the web server (Apache) can access and write to this directory. 

#sudo chown www-data:www-data /var/www/nextcloud/ -R 
Making Database and user for NextCloud in MariaDB 

Log in to MariaDB 

# sudo mariadb -u root 

Then we make a database for NextCloud. For this article I will add the database that is nextcloud_db. You can customize it into your needs. 

create database nextcloud_db; 

 Now let’s make user for this database, you can set username and password based on your needs. 

create user admin@localhost identified by 'password-anda'; 

The last step, give this user all the privileges in the NextCloud database.

grant all privileges on nextcloud_db.* to admin@localhost identified by 'password-anda'; 
flush privileges; 

Then, insert exit as the command. 

exit; 
Create Apache Virtual Host for NextCloud 

We need to create and edit the file nextcloud.conf from /etc/apache2/sites-available/ directory. 

#sudo nano /etc/apache2/sites-available/nextcloud.conf 

Then, copy-paste this text below into a file. After that, save the file. 

<VirtualHost *:80>
        DocumentRoot “/var/www/nextcloud”
        ServerName files.tiyanwants.website
 
        ErrorLog ${APACHE_LOG_DIR}/nextcloud.error
        CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined
 
        <Directory /var/www/nextcloud/>
            Require all granted
            Options FollowSymlinks MultiViews
            AllowOverride All
 
           <IfModule mod_dav.c>
               Dav off
           </IfModule>
 
        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
        Satisfy Any
 
       </Directory>
 
</VirtualHost>

I will use files.tiyanwants.website as the domain in this article. You can always suit your needs. And of course, don’t forget to add DNS A record for this domain inside your DNS Zone editor. 

After that, activate this virtual host. 

#sudo a2ensite nextcloud.conf 

Run this command to activate the Apache module you need 

#sudo a2enmod rewrite headers env dir mime setenvif ssl 

Lastly, restart Apache to deploy the changes. 

#sudo systemctl restart apache2 
Install and Activate PHP Modul 

Run this command for PHP module installation that is required and recommend by NextCloud. 

#sudo apt install imagemagick php-imagick libapache2-mod-php7.4 php7.4-common php7.4-mysql php7.4-fpm php7.4-gd php7.4-json php7.4-curl php7.4-zip php7.4-xml php7.4-mbstring php7.4-bz2 php7.4-intl php7.4-bcmath php7.4-gmp 

 Reload Apache to activate this module with below command 

#sudo systemctl reload apache2 
Activate HTTPS 

At this point, we should be able to access NextCloud web install wizard in our browser. 

But before entering sensitive information, it will be better to activate HTTPS inside our NextCloud domain. 

#sudo apt install certbot python3-certbot-apache 

Python3-certbot-apache is an Apache plugins. 

Run belows command to get free TLS certificate using Apache Plugin. 

#sudo certbot --apache --agree-tos --redirect --staple-ocsp --email wisesa.tiyan@gmail.com -d files.tiyanwants.website 

Where: 

  • –apache2: use Apache’s authenticator and installation 
  • –agree-tos: Agree to Let’s Encrypt service requirement 
  • –redirect: Implement HTTPS by adding 301 redirect 
  • –staple-ocsp: Activate Stapel OCSP 
  • –email: Email used for registration and recovery contact 
  • -d is followed by a list of domain names, separated by commas. You can add up to 100 domain names 

There will be some options that we need to fill. Once it finishes, TLS certification will automatically obtain and configured for us, it shows by the message below. 

The next configuration is to enable HSTS (HTTP Strict Transport Security). Because sometimes Certbot can’t automatically add HSTS header in Apache configuration file for NextCloud. Let’s edit this file first. 

#sudo nano /etc/apache2/sites-enabled/nextcloud-le-ssl.conf 

 Then, add this line to SSL server block to activate HSTS header. 

Header always set Strict-Transport-Security "max-age=31536000" 

Lastly, restart Apache so the changes will be successfully implemented.

#sudo systemctl reload apache2 
Cloud Finalization 

Now when we want to access our NextCloud dashboard, we are automatically use HTTPS. 

To finish the installation, in this wizard page we need to do several things: 

  1. Create admin account 
  1. Decide NextCloud’s data folder location 
  1. entering database detail that have been made in step 2, and 
  1. Decide the host address 

↳ Input username and password for admin user. 

↳ Data folder is a place where the user’s file being saved. It would be better to place data directory outside of webroot directory from NextCloud. Instead of saving the users file in /var/www/nextcloud/data/, we can change it to /var/www/nextcloud-data

To do it, we can do it with this command 

#sudo mkdir /var/www/nextcloud-data 

Then, make sure Apache’s user (www-data) has the permission to write into the data directory.

#sudo chown www-data:www-data /var/www/nextcloud-data -R 

↳ Re-input the database detail that we have made on previous steps. 

↳ We can use default localhost as host address, or we can input localhost:3306, because MariaDB use port 3306. 

After that, click “install”. Then we will be redirected to the main page of NextCloud’s dashboard. 

Okay, now we can use NextCloud as our Private Cloud Storage.

5. Essential Additional Configuration 

Increase PHP Memory Limit 

The default limitation of PHP memory is 128MB, but NextCloud recommend 512MB for better performance. To change PHP memory limit, edit this PHP file, 

#sudo nano /etc/php/7.4/apache2/php.ini 

Direct to this line 

memory_limit = 128M 

Change the value into 

memory_limit = 512M 

Save & close, then restart Apache so the company will implement the changes. 

#sudo systemctl reload apache2 
Configure Redis Cache for NextCloud 

We will actvate the cache memory for NextCloud by using redis. Run this command to install Redis  from Ubuntu repositoory. 

#sudo apt install redis-server 

To configure Redis as cache for NextCloud, we need to install PHP extension so it can interact with Redis.

#sudo apt install php-redis 

Next, edit NextCloud’s file configuration. 

#sudo nano /var/www/nextcloud/config/config.php 

Add the following line before the end. ); 

‘memcache.distributed’ => ‘\OC\Memcache\Redis’,
‘memcache.local’ => ‘\OC\Memcache\Redis’,
‘memcache.locking’ => ‘\OC\Memcache\Redis’,
‘redis’ => array(
     ‘host’ => ‘localhost’,
     ‘port’ => 6379,
     ),

Save and close file. Then, restart Apache and PHP-FPM. 

#sudo systemctl restart apache2 

Case Study

Okay, after we have successfully installed NextCloud in the VM, let’s try to make a case study in using NextCloud. With the following case studies: 

  1. Have 2 group of divisions
    a. Sales
    b. Billing
  1.  Will choose one divisions leader to manage the group.  
  1. Making “file-sharing” based on the groups. However, the Customer’s Invoice file from Billing division, is shared with the Sales Division as well.

Let’s see these steps to achieve the goal. 

↳ First, access Users menu 

↳ Then, click Add Group, and input the group’s name. 

↳ Now we are adding new users then deciding which group the new user belongs to. 

↳ In Active Users menu, edit the user that will become the administrator for the group’s division. 

↳ After that, now let’s switch account to one of the users that we have been made, then access menu File

↳ Decide which file that we will share and choose the group. In the Sharing tab, decide which group will be shared the file with. 

↳ We can see the file shared by the Billing gorup to Sales group also appear inside the file list. 

Conclusion 

From this article we learned together how to install NextCloud. Starting from how to install it on Cloud Raya’s VM, its configuration, to the case study examples in it. 

If you want to see the video tutorial version, you can access it in Cloud Raya’s Youtube channel or through this link.

For questions or discussions about this tutorial, you can directly submit them in the comments column. 

Table of Contents

Ready, Set, Cloud

Ready, Set, Cloud