If you followed this you now have a server. It's now time to start utilizing it. In this guide we will be setting up Nextcloud.
To allow Synchronization between server, desktop and mobile phone, Nextcloud provides applications for Windows, Linux and Mac desktop. As well as a mobile app for Android and iOS.
Nextcloud is not just a Dropbox clone. It provides additional features like Calendar, Contacts, Scheduled tasks and web forms.
In this tutorial, we will show you how to install and configure the latest Nextcloud release (at the time of writing it's version 23) on a Debian 11 server. We will run Nextcloud with an Nginx web server and PHP7.4-FPM and use MariaDB server as the database system.
This tutorial has been tested using Debian 11.
- Server running Debian 11 or derivatives
- Root privileges
- Install Nginx webserver
- Install and Configure PHP7.4-FPM
- Install and Configure MariaDB
- Generate SSL Let’s Encrypt
- Download Nextcloud 23
- Configure Nginx Host for Nextcloud
- UFW Firewall Configuration
- Nextcloud Post-Installation
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 upgrade -y 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.
sudo systemctl start nginx sudo systemctl enable nginx
The Nginx service is up and running, check it using the following command.
sudo systemctl status nginx
And you will get the result as below:
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Tue 1998-05-21 22:10:13 EST; 4 days ago Docs: man:nginx(8) Process: 27176 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 27177 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 1328730 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS) Main PID: 27178 (nginx) Tasks: 5 (limit: 4144) CPU: 4min 57.436s CGroup: /system.slice/nginx.service ├─ 27178 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─1328731 nginx: worker process ├─1328732 nginx: worker process ├─1328733 nginx: worker process └─1328734 nginx: worker process
Install PHP and PHP-FPM packages neede by Nextcloud using the apt command below:
sudo apt install php7.4 php7.4-fpm php7.4-common php7.4-pgsql php7.4-cli php7.4-gd php7.4-json php7.4-curl php7.4-zip php7.4-xml php7.4-mbstring php7.4-bz2 php7.4-intl php7.4-bcmath php7.4-gmp php-imagick php7.4-opcache php7.4-readline 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.
Change memory limit to 512M
Change max_execution_time to 256
Uncomment those lines below:
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
Restart the PHP7.4-FPM service and enable it to launch every time on system boot.
sudo systemctl restart php7.4-fpm sudo systemctl enable php7.4-fpm
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.
sudo apt install mariadb-server -y
After the installation is complete, start the MariaDB service and enable it to launch every time at system boot.
sudo systemctl start mariadb sudo systemctl enable mariadb
Next, we will configure the MariaDB root password using the ‘mysql_secure_installation’ command.
Run the following command:
You will be asked for some configuration of MariaDB Server. 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
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.
sudo mysql -u root -p
Now create the database and user with a password by running following MySQL queries.
'Nextclouduser421@' with your password.
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;
The new database and user for the nextcloud installation has been created.
We will secure Nextcloud using a free SSL Certificate from Let’s Encrypt. Install the Let’s Encrypt tool:
sudo apt install certbot -y
Next we will generate the SSL certificate for our domain name “cloud.example.com”:
If you followed this giude to set up a Cloudeflare tunnel you will need to add an additional service for this domain.
certbot --standalone -d cloud.example.com
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 Nextcloud domain name has been generated, all located at the ‘/etc/letsencrypt/live/your-domain’ directory.
/var/www directory and download the latest version of Nextcloud:
cd /var/www/ sudo wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.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’.
sudo unzip nextcloud-23.0.0.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/ sudoedit nextcloud
There, paste the following configuration.
Save and exit.
Enable the virtual host and make sure there is no errors:
sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/ sudo nginx -t
Now restart Nginx service using the command:
sudo systemctl restart nginx
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.
sudo ufw allow ssh sudo ufw allow http sudo ufw allow https
Now Enable the firewall and check the allowed service and port:
sudo ufw enable sudo status numbered
And you will see HTTP port 80 and HTTPS port 443 is on the list.
Open a Browser on your local network and go to the nextclud URL:
On the top of the page we need to create an admin user for Nextcloud. Type in a user name and password. On the 'data folder' type the full of the 'data' directory.
On the bottom of the page you will need to enter the database info from step 3. Then click the 'Finish Setup' button.
After the installation is complete, you will get the Nextcloud dashboard.