1.2 How to Build a Home Server?

Sonu Malik
5 min readOct 17, 2021

--

Hello, in the previous blog, we had successfully installed and accessed our home server. Today, we will be focusing on

  1. How can we extend our home server storage?
  2. How can we install and set up an open-source Nextcloud application to sync data from different devices?

Let’s start

STEP 1
Open the terminal on your laptop and go to the server using the IP address.
In my case, IP is 192.168.1.24 , it might differ in your case.

ssh pi@192.168.1.24

Go to root user using the password we have changed in the last step of the previous blog.
su -

STEP 2
Connect your hard drive to the device and verify using the following commands
lsusb andlsblk

STEP 3
In this step, we are going to work with disk-partitioning.
Make sure that your drive is empty, the below steps will format all your data.

  • fdisk /dev/sda
    use the above command to go to fdisk for /dev/sda. Press mto see the help.

We use d , n and w .
type d to delete a partition.
then type n to create a new partition and use default values only.
and after that w to apply the changes and exit.

Be careful before using the write command

STEP 4
Here, we will be changing the hard drive format to ext4
mkfs -t ext4 /dev/sda1

STEP 5
Now, the hard drive is ready to use and fully compatible with the device. Now we mount our drive to the specified folder. We are providing a dedicated folder to the hard drive. So that we do not have to check the hard drive location every time.

Create an empty directory
mkdir /mnt/NETDATA

Now, mount the hard drive to the above-created directory.
mount /dev/sda1 /mnt/NETDATA

Automount hard drive.
Till now, we have successfully mounted our hard drive to /mnt/NETDATA but this is temporary. We need to automount the hard drive in the same directory when the system booted. For that, you need to add a single line in /etc/fstab .

type nano /etc/fstab

and add the line: /dev/sda1 /mnt/NETDATA ext4 defaults 0 0

Hurray, now the drive will automatically mount on every boot. You can verify by using lsblk command.

Install NextCloud

Let’s move to set up a web application for accessing data from different devices. For this, we will be installing multiple services.

  1. Install Web Server (Apache and PHP)
apt update
apt install apache2
apt install libapache2-mod-php
apt install php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip

2. Download NextCloud

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

3. unzip to the folder /var/www/html

apt-get install unzip
unzip nextcloud-19.0.1.zip -d /var/www/html/

4. Install Database

apt install mariadb-server

5. Create user and grant privileges

mysqlCREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; create user admin@localhost identified by 'admin';grant all privileges on nextcloud.* to admin@localhost;

6. Now, setup Virtualhost, for path /nextcloud

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

paste the below code in nextcloud.conf

Alias /nextcloud "/var/www/html/nextcloud/"
<VirtualHost *:80>
DocumentRoot /var/www/html/nextcloud/
<Directory /var/www/html/nextcloud/>
Require all granted
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>
</VirtualHost>

7. Enable the following extension modules and restart Apache.

a2ensite nextcloud.conf
a2enmod rewrite
a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime
systemctl reload apache2

8. Last, change the permissions of working directories.

sudo chown -R www-data:www-data /var/www/html/nextcloud/
sudo chown -R www-data:www-data /mnt/NETDATA
sudo chmod 750 /mnt/NETDATA

Done.
We are done with the installation part. Now just open your browser and set up the Nextcloud admin account.
Go to http://192.168.1.24/nextcloud

  • Create an admin user
  • Under the Storage and Database section.

The data storage path is your drive mounted path. i.e. /mnt/NETDATA

Fill database creds, this will the same we created while setting the database (In the 5th step of Install NextCloud).

Note: If you do not want to install recommended apps. Please do uncheck the checkbox.

Finish Setup

Click on the Finish setup button and let the initialization happen. After few minutes you will be redirected to NextCloud home page.

Now you can download NextCloud Client apps and sync your data.
https://nextcloud.com/install/#install-clients

Thank you!

We have successfully done with our home server. Now, you can access it from all types of smart devices. And can auto-sync your data to the server. As of now, you can only access your server using local network only. This means the device should be connected to the same network.

In the next blog, we’ll do some settings in our router to access using public IP and also configure it to DDNS(Dynamic DNS).

--

--

Sonu Malik

Creator of Firepro | Technical Lead | NodeJs | Golang | javascript | AWS