So many different cloud storage solutions out there such as Dropbox, Google Drive, One Drive and so on. But what if you want to manage all your data yourself, in the comfort of your own home, NextCloud could be just what you're looking for.
In this article, I'm going to go through how to setup your own cloud server at home, you need an install of Linux, I've used Ubuntu Mini for this, you need to setup a static IP for the computer that is going to be the cloud server and you also need to forward ports 80 and 443 to that IP address. If you can't install Linux and don't know how to forward the ports then this isn't for you.
The only thing you really need to do during the installation is enable the ssh server so you can do the rest remotely.
The computer I'm using is a small form factor machine with a 250GB SSD and an external RAID enclosure with 2 x 4TB drives connected by USB
Plug the RAID device and the run dmesg shows the RAID device on my machine at /dev/sda
As it's a big drive we need to partition using
sudo parted /dev/sda
mklabel gpt
mkpart ext4 0% 100%
quit
Now time to format it with
sudo mkfs.ext4 /dev/sda
This will give you an output similar to this:
Found a gpt partition table in /dev/sda
Proceed anyway? (y/N) y
Creating filesystem with 976740352 4k blocks and 244187136 inodes
Filesystem UUID: 8da4f15d-2def-4cb9-ab7f-c972479529bd
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
Copy that UUID number, it will be different for you, we will now be modifying the fstab file with
sudo nano /etc/fstab
Add a line like this to the end, using your UUID.
UUID=8da4f15d-2def-4cb9-ab7f-c972479529bd /mnt/Data ext4 defaults,noatime 0 1
Then CTRL X then Y and enter to save.
Make the mount point with;
sudo mkdir /mnt/Data
Then run sudo mount -a to mount the drive.
If you run df -h you should see something like this which shows the RAID drive up and running.
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 786M 820K 785M 1% /run
/dev/sdb5 228G 3.9G 213G 2% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sdb1 511M 4.0K 511M 1% /boot/efi
tmpfs 786M 0 786M 0% /run/user/1000
/dev/sda 3.6T 89M 3.4T 1% /mnt/Data
We're now going to create two directories, one for the Apache web server and one for the NextCloud data.
sudo mkdir /mnt/Data/www
sudo mkdir /mnt/Data/NextCloud
Now we create a symbolic link in the /var directory which points to the www directory we just created.
ln -s /mnt/Data/www/ /var/www
For now we are just going to set the permissions to 0777 with:
chmod 0750 -R /mnt/Data
Now it's time to start installing the required software to get our cloud server running.
sudo -s
apt update && apt upgrade
apt install ssh screen apache2 php mariadb-server php-fpm php-pear php-gd php-mysql php-redis php-curl php-json php-mbstring unrar lame mediainfo subversion ffmpeg redis software-properties-common mc net-tools unzip ufw curl mc php-zip -y
Time to secure the database with:
mysql_secure_installation
You should then see the following
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Now we create the database for the cloud server with the following, replace password with a good strong password of your own.
mysql -u root -p
<enter password>
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' WITH GRANT OPTION;
exit
Little bit of file editing now with the following :
nano /etc/mysql/conf.d/mysql.cnf
Add this to the bottom of the file and then save it:
[mysqld]
group_concat_max_len=8192
innodb_flush_log_at_trx_commit = 2
nano /etc/php/7.4/apache2/php.ini
Change the following lines to match shown below, the time zone one should be changed for your part of the world.
max_execution_time = 120
memory_limit = -1
date.timezone = Europe/London
nano /etc/php/7.4/cli/php.ini
Change the following lines to match shown below, the time zone one should be changed for your part of the world.
max_execution_time = 120
date.timezone = Europe/London
Time now to make the config file for the apache web server:
nano /etc/apache2/sites-available/nextcloud.conf
Add this in changing the ServerName and ServerAlias to your server name, you can use a dynamic host such as no-ip or duckdns to get an domain name, I use my NAS drive to provide one.
<VirtualHost *:80>
ServerName your_domain
ServerAlias www.your_domain
<Directory /var/www/nextcloud/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
DocumentRoot /var/www/nextcloud
</VirtualHost>
Let's get the Nextcloud software installed:
cd /var/www
wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip
unzip nextcloud-23.0.0.zip
rm nextcloud-23.0.0.zip
Set up permissions
chmod 0750 -R /var/www/
chmod 0750 -R /mnt/Data/NextCloud/
chown -R www-data:www-data /mnt/Data/NextCloud/
chown -R www-data:www-data /var/www/
Setup the firewall rules now with:
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow 80
ufw allow 443
ufw enable
Time now to activate the server config
a2dissite 000-default.conf
a2ensite nextcloud.conf
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm
a2enmod rewrite
systemctl restart php7.4-fpm
systemctl restart apache2
systemctl restart mysql
Now to setup some ssl security
apt install certbot python3-certbot-apache
Then just type certbot followed by enter.
And answer the questions.
On the screen that says "Which names would you like to activate HTTPS for" you should see the names of the ones you entered in the Apache config file earlier. Just press enter here.
And then select 2 to create a redirect.
That so far is all the installation done, now it's time to open up a web browser and point it to the domain you created for the cloud server, this is the dynamic dns one.
http://servername:
Fill in all the details requested and make sure you change the data path to
/mnt/Data/NextCloud or whatever you have set yours to.
Once that's all done you can install the desktop client and the mobile client and have a play around. That's all your data under your control.
No comments:
Post a Comment