Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


install_nextcloud_nginx_let_encrypt_ssl_ubuntu_20_04_lts

This is an old revision of the document!


How to Install Nextcloud with Nginx and Let's Encrypt SSL on Ubuntu 20.04 LTS

https://www.howtoforge.com/tutorial/ubuntu-nginx-nextcloud/

Prerequisites

  • List ItemUbuntu 20.04
  • Root privileges
  • ItemWhat we will do
  • Install Nginx Webserver
  • Install and Configure PHP7.4-FPM
  • Install and Configure MySQL Server
  • Generate SSL Letsencrypt
  • Download Nextcloud 18
  • Configure Nginx Virtual Host for Nextcloud
  • UFW Firewall Configuration
  • Nextcloud Post-Installation

Step 1 - Install Nginx Webserver

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.

Step 2 - Install and Configure PHP7.4-FPM

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.

cd /etc/php/7.4/

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'.

cgi.fix_pathinfo=0

Save and exit.

Next, edit the php-fpm pool configuration 'www.conf'.

vim fpm/pool.d/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'.

Step 3 - Install and Configure MariaDB Server

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.

mysql_secure_installation

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.

Step 4 - Generate SSL Letsencrypt

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.

Step 5 - Download Nextcloud

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.

Step 6 - Configure Nginx Virtual Host for Nextcloud

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.

install_nextcloud_nginx_let_encrypt_ssl_ubuntu_20_04_lts.1592606593.txt.gz · Last modified: 2020/06/19 22:43 by wikiadmin