learn how to install nextcloud on a debian 10.8 on premise or cloud hosted virtual machine

Nextcloud is a open source, self hosted collaboration solution that can be used to share and collaborate on documents, send and receive email, manage your calendar and more. It is a software solution that can be used in a home office, small corporate office or large enterprise and is suitable for use in industries such as RETAIL, HEALTHCARE, EDUCATION, FINANCIAL SERVICES, GOVERNMENT, MEDIA & ADVERTISING, CONSTRUCTION & MANUFACTURING and more! It is a solution that works in that same way as sharing services like Amazon Drive, Google Drive, Dropbox and OneDrive. With Nextcloud, you can do things such as storing and backing up important files, folders, documents, pictures, videos all on a single central location. You can even share files, contacts, and any many types of media files with friends and work / team mates. Furthur more you can integrate your email, calendar, contacts into Nextcloud thereby making it possible to access all your work from a single application. You can also install the Nextcloud client app on almost any mobile phone, laptop or desktop so you can have access to your information at work, at home or on the go. Continue reading this tutorial to learn how to install Nextcloud on a Debian 10.8 virtual machine.
REQUIREMENTS
In order to complete this tutorial successfully, the following is a list of items that may be needed. Please ensure to have these items available before taking implementation action on this tutorial:
1) A desktop or laptop with a dual core processor, 4GB RAM and 50GB of free disk space
2) Virtualization software – VirtualBox, VMware Workstation, VMware ESXi, VMware Fusion, Hyper-V, Proxmox VE
3) The Debian 10.8 disk image file (ISO FILE)
4) Nextcloud installation files for
5) A cloud hosting account on AWS, AZURE, ALIBABA, ORACLE CLOUD etc. (An AWS free tier account also works)
OVERVIEW
1) NEXTCLOUD system requirements
2) Download the Debian 10.8 disk image file and create a DEBIAN virtual machine
3) Log into your Amazon Web Services account and create a DEBIAN 10.8 BUSTER, virtual machine.
4) Set a static IP address on the DEBIAN virtual machine.
5) Connect to the instance using the AWS LIGHTSAIL browser-based SSH client and install NEXTCLOUD
6) Open the NEXTCLOUD web interface, configure database settings and create the NEXTCLOUD admin account.
Nextcloud System Requirements
11) The table BELOW is a list of minimum system requirements that you need to consider when planning to deploy NEXTCLOUD in your environment.

Step 1: Download The Debian 10.8 Disk Image File And Create A DEBIAN Virtual Machine
1) Click HERE to go to the DEBIAN website to download the DEBIAN 10.8 disk image file. Please note that the disk image file is about GB in size

2) The virtual machine creation process depends on the software that you choose to use. You may have choose to use VIRTUALBOX, VMWARE WORKSTATION, HYPER-V or PROXMOX-VE. The creation process is unique to each software platform.
Below are links to tutorials that will show you how to create a DEBIAN 10.8 virtual machine on the above mention virtualization softwares:
1) How to install DEBIAN on VMware ESXi.
2) How to install DEBIAN on VirtualBox
3) How to install DEBIAN on HYPER-V
4) How to install DEBIAN on VMware Workstation
5) How to install DEBIAN on VMware Fusion

Step 2: Log Into Your Amazon Web Services Account And Create A DEBIAN 10.8 BUSTER, Virtual Machine
3) Click HERE to go to the AWS console login page. Click on the IAM USER radio button, enter your 12 digit AWS ACCOUNT ID or ACCOUNT ALIAS and click on NEXT.
If you do not have an AWS free tier account. click HERE to sign up now.
NB: You need to ensure that your AWS IAM account is authorized to access AWS LIGHTSAIL

4) Enter your IAM username and password and click on SIGN IN

5) Click on SERVICES and on the COMPUTE category, click on LIGHTSAIL to open the AWS LIGHTSAIL web application.

6) On the INSTANCES tab click on the CREATE INSTANCE button to start the DEBIAN virtual machine creation process.
AWS LIGHTSAIL will automatically select the best instance location for you but if you would like to change it click on the CHANGE AWS REGION AND AVAILABILITY ZONE link.
On the PICK YOUR INSTANCE IMAGE section, click on LINUX / UNIX and on the SELECT A BLUEPRINT section click on the OS ONLY button.
Select DEBIAN 10.8 and scroll down to the CHOOSE YOUR INSTANCE PLAN section

7) Click on on the PRICE PER MONTH tab and select the $3.50, $5 , or $10 plans. For best perfomance we recommend that your select the $10 plan.
NB: The first 3 months of the $3.50, $5 and $10 plans are free!
Add a name to identify the instance on the IDENTIFY YOUR INSTANCE text input box, scroll down and click on the CREATE INSTANCE button.

Step 3: Set A Static IP Address On The DEBIAN Virtual Machine.
8) The next step is to set a STATIC IP ADDRESS on the DEBIAN virtual machine.
On the INSTANCES tab, right click on the newly created debian instance and click on MANAGE.

9) Click on the NETWORKING tab and click on the CREATE STATIC IP button.
NB: When a instance is created on AWS Lightsail, a dynamic public IP address is allocated to it and this address changes when the instance stops or starts. Since this is a NEXTCLOUD server it is recommended to allocate a static IP address that will not change.

10) On the CREATE A STATIC IP ADDRESS page, you will see the STATIC IP LOCATION and the INSTANCE that the STATIC IP ADDRESS will be attached to.
Enter a unique name to identify the STATIC IP ADDRESS on the IDENTIFY YOUR STATIC IP text box and click on the CREATE button.

Step 4: Connect To The Instance Using The AWS LIGHTSAIL Browser-Based SSH Client And Install NEXTCLOUD
11) The next step, is to connect to the instance using the AWS Lightsail browser-based SSH client so as to start the NEXTCLOUD installation process.
To do this, click on the HOME button at the top on the page and on the NEXTCLOUD instance click on the menu button with three dots.
Click on the CONNECT option to open the browser-based SSH client.

12) Run the following commands to install DEBIAN package updates:
sudo su
apt-get update && apt-get upgrade
The system will prompt you to confirm the installation by entering the letter Y and hitting the ENTER key.

13) Once the installation is complete, click on the menu icon with the three dots on the NEXTCLOUD instance and click on REBOOT.

14) Wait for about two minutes and connect to the instance once more using the browser based SSH client. Run the following command to install Apache, MariaDB, PHP and other required packages:
apt-get install apache2 libapache2-mod-php mariadb-server php-xml php-cli php-cgi php-mysql php-mbstring php-gd php-curl php-zip wget unzip -y

15) Next, there is need to make changes to the php.ini configuration file to permitt large file uploads, more execution time, etc. Run the following command to open the PHP.INI file:
nano /etc/php/7.3/apache2/php.ini
Then make the following changes in the PHP.INI file:
memory_limit = 512M
upload_max_filesize = 1024M
post_max_size = 2048M
max_execution_time = 300
date.timezone = Africa/Harare
The parameters listed above are in different sections of the file, to find a parameter PRESS CONTROL + W, enter the name of the parameter and press ENTER, Nano will automatically search the file and scroll to the line where the parameter is located and all you have to do is to change the value configured on the parameter as indicated above.

16) Next, press CONTROL + O and press ENTER to save changes made to the PHP.INI file and run the following commands to start the Apache and MariaDB service and enable them to start after system restart:
systemctl start apache2
systemctl start mariadb
systemctl enable apache2
systemctl enable mariadb
To check if the mariadb and apache service is running. use the following commands:
systemctl status apache2
systemctl status mariadb

17) Run the following commands to remove some dangerous defaults and lock down access to the MYSQL database system. Start the interactive script by running :
sudo su
mysql_secure_installation
When you run the command you will be prompted to enter a password however MYSQL has no default password, simple press ENTER to proceed.
You will be prompted to SET ROOT PASSWORD, type in the letter Y and press ENTER. Enter your desired password on the next prompts.
On all the other prompts, type in the letter Y and press ENTER.

18) Now you need to create a MYSQL database that will be using by the NEXTCLOUD application to store and retrieve user data. To create the database, open the MARIADB shell by running the following command:
mysql -u root -p
Enter your MYSQL password and run the following commands to create the NEXTCLOUD database
MariaDB [(none)]> CREATE DATABASE nextclouddatabase;
MariaDB [(none)]> CREATE USER ‘nextcloudadmin’@’localhost’ IDENTIFIED BY ‘nextcloudpassword’;

19) Next, grant all the privileges to the nextcloud database, flush the privileges and exit from the MariaDB shell with the following commands:
MariaDB [(none)]> GRANT ALL ON nextclouddatabase.* TO ‘nextcloudadmin’@’localhost’;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

20) WGET is a common linux package that is mainly used to retrieve files from the internet using common TCP / IP protocols such as HTTP, HTTPS, FTP and FTP. Run the commands indicated below to download the NEXTCLOUD installation files to the DEBIAN instance:
cd /
sudo su
wget https://download.nextcloud.com/server/releases/nextcloud-22.1.1.zip

21) Next, extract the NEXTCLOUD archive file and move the extracted directory to the /var/www/html folder by running the following commands in the order shown below:
unzip nextcloud-17.0.1.zip
mv nextcloud /var/www/html/

22) Set file permissions for the NEXTCLOUD web application files so they can be accessible from a web browser. Also change the owner of the files to the www-data user so that the APACHE web server can have access. The commands for doing this are as follows:
chown -R www-data:www-data /var/www/html/nextcloud/
chmod -R 755 /var/www/html/nextcloud/

22) The next step is to create a virtual host configuration file that will be used by the APACHE web server to serve the nextcloud web application when requested by a web browser.
Run the following command to create this file:
nano /etc/apache2/sites-available/nextcloud.conf

22) Add the configuration shown below into this file:
<VirtualHost *:80>
ServerAdmin Admin@192.168.56.101
DocumentRoot /Var/Www/Html/Nextcloud/
ServerName Nextcloud.Billysoftacademy.Com
Alias /Nextcloud "/Var/Www/Html/Nextcloud/"
<Directory /Var/Www/Html/Nextcloud/>
Options +FollowSymlinks
AllowOverride All
Require All Granted
<IfModule Mod_dav.C>
Dav Off
</IfModule>
SetEnv HOME /Var/Www/Html/Nextcloud
SetEnv HTTP_HOME /Var/Www/Html/Nextcloud
</Directory>
ErrorLog ${APACHE_LOG_DIR}/Error.Log
CustomLog ${APACHE_LOG_DIR}/Access.Log Combined
</VirtualHost>

23) Next, run the following command to enable the apache virtual host file as well as other required modules by running the following commands:
a2ensite nextcloud.conf
a2enmod rewrite
a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime
Then restart the apache web server by running the following command:
systemctl restart apache2
If you encounter errors after restarting the apache service, verify that there are no syntax errors in the nextcloud.conf file

Open The NEXTCLOUD Web Interface, Configure Database Settings And Create The NEXTCLOUD Admin Account.
24) Open any web browser, enter the public IP address of the NEXTCLOUD instance in the browser address and press ENTER. You should also append the nextcloud folder at the end of the IP address using the following format:
https://PUBLIC-IP-ADDRESS-OF-NEXTCLOUD-INSTANCE/nextcloud

25) Enter the nextcloud database name, username and password as shown in the image on the right and click on FINISH SETUP

26) A post installation slide show will be displaying show information about some of the things that NEXTCLOUD can do, Click on the CLOSE button on the top right corner of the page to access the NEXTCLOUD dashboard.

27) On the top right corner of the dashboard you will see option for managing files, folders, images and more. Click on the FOLDER icon as indicated by the red arrow in the image on the right

28) This is were you can upload your important work files and folders, share and collaborate on documents with your peers and work mates.
NEXTCLOUD has many functionalites and apps that you can use, some which need to be paid for, click HERE to learn more
