Deploying and Securing Nextcloud on Debian Using Nginx

Introduction

Nextcloud is a powerful open-source software suite that provides cloud storage and services. In this guide, we will walk through deploying Nextcloud on a Debian server using Nginx and securing it with SSL.

Prerequisites

  • A Debian server with sudo privileges
  • A domain name pointed to your server’s IP address
  • Basic knowledge of Linux command line

Step 1: Update Your System

First, make sure your system is up to date:sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx, MariaDB, and PHP

Install Nginx:sudo apt install nginx -y

Install MariaDB:sudo apt install mariadb-server -y

Secure your MariaDB installation:sudo mysql_secure_installation

Follow the prompts to set the root password and secure your installation.

Install PHP and required modules:sudo apt install php-fpm php-mysql php-zip php-dom php-curl php-gd php-xml php-mbstring php-intl php-bcmath php-gmp -y

Step 3: Configure MariaDB for Nextcloud

Login to MariaDB:sudo mysql -u root -p

Create a database and user for Nextcloud:CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Download and Configure Nextcloud

Download the latest version of Nextcloud:cd /tmp
wget https://download.nextcloud.com/server/releases/latest.zip
unzip latest.zip
sudo mv nextcloud /var/www/

Set the appropriate permissions:sudo chown -R www-data:www-data /var/www/nextcloud
sudo chmod -R 755 /var/www/nextcloud

Step 5: Configure Nginx

Create an Nginx configuration file for Nextcloud:sudo nano /etc/nginx/sites-available/nextcloud

Add the following configuration:server {
 listen 80;
 server_name your_domain.com;
 root /var/www/nextcloud;

 location / {
  index index.php index.html /index.php$request_uri;
 } 

 location ~ \.php$ {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  fastcgi_index index.php;
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param PATH_INFO $fastcgi_path_info;
 } 

 location ~* \.(?:css|js|woff|svg|gif|map)$ {
  try_files $uri /index.php$request_uri;
 } 

 location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
  try_files $uri /index.php$request_uri;
 } 
}

Enable the new configuration and restart Nginx:sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 6: Secure Nextcloud with SSL

Install Certbot:sudo apt install certbot python3-certbot-nginx -y

Obtain and install an SSL certificate:sudo certbot --nginx -d your_domain.com

Follow the prompts to complete the SSL setup.

Step 7: Complete the Installation via Web Interface

Open your browser and navigate tohttps://your_domain.com. Follow the on-screen instructions to complete the Nextcloud setup. Enter the database details configured earlier and finish the installation.

Conclusion

Congratulations! You have successfully deployed and secured Nextcloud on your Debian server using Nginx. Enjoy your private cloud storage solution.

Other Recent Posts