The first step we will do in this nextcloud guide is to install the Nginx web server. We will be using the Nginx web server instead of Apache webserver.
Log in to the server and update the repository, then install the Nginx web server using the apt command as shown below.
sudo apt update sudo apt install nginx -y
After the installation is complete, start the Nginx service and enable the service to launch every time at system boot using systemctl.
systemctl start nginx systemctl enable nginx
The Nginx service is up and running, check it using the following command.
systemctl status nginx
As a result, the Nginx web server has been installed on Ubuntu 20.04.
By default, the Ubuntu 20.04 comes with default version PHP 7.4.
Install PHP and PHP-FPM packages needed by Nextcloud using the apt command below.
sudo apt install php-fpm php-curl php-cli php-mysql php-gd php-common php-xml php-json php-intl php-pear php-imagick php-dev php-common php-mbstring php-zip php-soap php-bz2 -y After the installation is complete, we will configure the php.ini files for php-fpm and php-cli.
Go to the '/etc/php/7.4' directory.
Edit the php.ini files for php-fpm and php-cli using vim.
vim fpm/php.ini vim cli/php.ini
Uncomment the 'date.timezone' line and change the value with your own timezone.
date.timezone = North_America/New_York
Uncomment the 'cgi.fix_pathinfo' line and change the value to '0'.
Save and exit.
Next, edit the php-fpm pool configuration 'www.conf'.
Uncomment those lines below.
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
Save and exit.
Restart the PHP7.4-FPM service and enable it to launch every time on system boot.
systemctl restart php7.4-fpm systemctl enable php7.4-fpm
Now check the PHP-FPM service using the following command.
ss -xa | grep php systemctl status php7.4-fpm
And you will get the php-fpm is up and running under the sock file '/run/php/php7.4-fpm.sock'.
In this step, we will install the latest MariaDB version and create a new database for the nextcloud installation. The latest version MariaDB packages are available on the repository by default.
Install MariaDB server's latest version using the apt command below.
sudo apt install mariadb-server -y
After the installation is complete, start the MariaDB service and enable it to launch everytime at system boot.
systemctl start mariadb systemctl enable mariadb
Now check the MySQL service using the following command.
systemctl status mariadb
The MariaDB server is up and running on Ubuntu 20.04.
Next, we will configure the MariaDB root password using the 'mysql_secure_installation' command.
Run the following command.
And you will be asked for some configuraiton of MariaDB Server. Also, type the new root password for MariaDB Server.
Enter current password for root (enter for none): Press Enter Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
And the MariaDB root password has been set up.
Next, we will create a new database for nextcloud installation. We will create a new database named 'nextcloud_db' with the user 'nextclouduser' and password 'Nextclouduser421@'.
Login to the MySQL shell as a root user with mysql command.
mysql -u root -p TYPE THE MYSQL ROOT PASSWORD
Now create the database and user with the password by running following MySQL queries.
create database nextcloud_db; create user nextclouduser@localhost identified by 'Nextclouduser421@'; grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'Nextclouduser421@'; flush privileges;
And the new database and user for the nextcloud installation has been created.
The MariaDB installation and configuration for nextcloud has been completed.
In this tutorial, we will secure nextcloud using free SSL from Letsencrypt, and we will generate certificates files using the letsencrypt tool.
If you do not have a domain name or install nextcloud on the local computer, you can generate the Self-Signed certificate using OpenSSL.
Install the 'letsencrypt' tool using the apt command below.
sudo apt install certbot -y
After the installation is complete, stop the nginx service.
systemctl stop nginx
Next, we will generate the SSL certificates for our domain name 'nextcloud.hakase-labs.io' using the cerbot command line. Run the command below.
certbot certonly --standalone -d cloud.hakase-labs.io
You will be asked for the email address, and it's used for the renew notification. For the Letsencrypt TOS agreement, type 'A' to agree and for the share email address, you can type 'N' for No.
The SSL certificates Letsencrypt for the netxcloud domain name has been generated, all located at the '/etc/letsencrypt/live/your-domain' directory.
Before downloading the nextcloud source code, make sure the unzip package is installed on the system. If you don't have the package, install it using the apt command below.
sudo apt install wget unzip zip -y
Now go to the '/var/www' directory and download the latest version of Nextcloud using the following command.
cd /var/www/ wget -q https://download.nextcloud.com/server/releases/latest.zip
Extract the Nextcloud source code and you will get a new directory 'netxcloud', change the ownership of the nextcloud directory to user 'www-data'.
unzip -qq latest.zip sudo chown -R www-data:www-data /var/www/nextcloud
As a result, the Nextcloud has been downloaded under the '/var/www/nextcloud' directory, and it will be the web root directory.
In this step, we will configure the nginx virtual host for nextcloud. We will configure nextcloud to run under the HTTPS connection and will force the HTTP connection automatically to the secure HTTPS connection.
Now go to the '/etc/nginx/sites-available' directory and create a new virtual host file 'nextcloud'.
cd /etc/nginx/sites-available/ vim nextcloud
There, paste the following nextcloud virtual host configuration.
Save and exit.
Enable the virtual host (i.e. create a symlink from /sites-available/ over to /sites-enabled/ to enable nextcloud block / virtual host .conf file) and test the configuration, and make sure there is no error.
ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/ nginx -t
Now restart PHP7.4-FPM service and nginx service using the systemctl command below.
systemctl restart nginx systemctl restart php7.4-fpm
The Nginx virtual host configuration for nextcloud has been created.
In this tutorial, we will turn on the firewall, and we will be using the UFW firewall for Ubuntu.
Add the SSH, HTTP and HTTPS to the UFW firewall list using the command below.
for svc in ssh http https do ufw allow $svc done
After that, enable the UFW firewall and check the allowed service and port.
ufw enable ufw status numbered
And you will get the HTTP port 80 and HTTPS port 443 is on the list.
Open your web browser and type the nextcloud URL address.
And you will be redirected to the secure HTTPS connection.
On the Top page, we need to create the admin user for nextcloud, type the admin user password. On the 'Data folder' configuration, type the full path of the 'data' directory '/var/www/nextcloud/data'.
Scroll the page to the bottom, and you will get the database configuration. Type the database info that we've created in step 3 and then click the 'Finish Setup' button.
If you check the option 'Install recommended apps', you will get a page listing the recommended apps to be installed.
Nextcloud is installing additional recommended applications for you.
And after the installation is complete, you will see the Nextcloud Dashboard in your browser.
The Nextcloud 18 installation with Nginx web server and MySQL database on Ubuntu 20.04 has been completed successfully.
And Muhammad Arul and his article at