Cloud Storage Content Linux Nextcloud Self Hosted Ubuntu Ubuntu Server

How to Install NextCloud on Ubuntu 18.04 with Nginx (LEMP Stack)

ubuntu 18.04 nextcloud

This tutorial shall be displaying you ways to set up NextCloud on Ubuntu 18.04 LTS with Nginx. As you might in all probability know, NextCloud is a free open-source self-hosted cloud storage answer that’s forked from ownCloud. On the time of this writing, the newest secure model is NextCloud, which is suitable with PHP7.2.


To comply with this tutorial, you first want to set up LEMP stack on Ubuntu 18.04. Should you haven’t already accomplished so, please take a look at the next tutorial.

Optionally, if you need to create database from phpMyAdmin, you possibly can comply with the tutorial under to set up phpMyAdmin on Ubuntu 18.04 with LEMP.

Now let’s set up NextCloud.

Step 1: Obtain NextCloud 13 on Ubuntu 18.04

Login into your Ubuntu 18.04 server. Then obtain the NextCloud zip archive onto your server. The newest secure model is at time of this writing. Chances are you’ll want to change the model quantity. Go to and click on the obtain button to see the newest model.

ubuntu 18.04 nextcloud

You’ll be able to run the next command to obtain it on your server.


As soon as downloaded, extract the archive with unzip.

sudo apt set up unzip

sudo unzip -d /usr/share/nginx/

The -d choice specifies the goal listing. NextCloud net information can be extracted to /usr/share/nginx/nextcloud/.  Then we’d like to change the proprietor of this listing to www-data in order that the online server (Nginx) can write to this listing.

sudo chown www-data:www-data /usr/share/nginx/nextcloud/ -R

Step 2: Create a Database and Consumer in MariaDB

Log into MariaDB database server with the next command. Since MariaDB is now utilizing unix_socket plugin to authentication consumer login, there’s no want to enter MariaDB root password. We simply want to prefix the mysql command with sudo.

sudo mysql

Alternatively, you may as well use this command to login.

sudo mariadb

Then create a database for Nextcloud. This tutorial identify the database nextcloud. You need to use no matter identify you want.

create database nextcloud;

Create the database consumer. Once more, you need to use your most popular identify for this consumer. Exchange your-password with your most popular password.

create consumer [email protected] recognized by ‘your-password’;

Grant this consumer all privileges on the nextcloud database.

grant all privileges on nextcloud.* to [email protected] recognized by ‘your-password’;

Flush privileges and exit.

flush privileges;


Step three: Create a Nginx Config File for Nextcloud

Create a nextcloud.conf file in /and so on/nginx/conf.d/ listing.

sudo nano /and so forth/nginx/conf.d/nextcloud.conf

Put the next textual content into the file. Exchange the red-colored textual content with your precise knowledge. Don’t overlook to set A document for the area identify.

pay attention 80;

# Add headers to serve safety associated headers
add_header X-Content material-Sort-Choices nosniff;
add_header X-XSS-Safety “1; mode=block”;
add_header X-Robots-Tag none;
add_header X-Obtain-Choices noopen;
add_header X-Permitted-Cross-Area-Insurance policies none;

#This header is already set in PHP, so it’s commented out right here.
#add_header X-Body-Choices “SAMEORIGIN”;

# Path to the basis of your set up
root /usr/share/nginx/nextcloud/;

location = /robots.txt
permit all;
log_not_found off;
access_log off;

# The next 2 guidelines are solely wanted for the user_webfinger app.
# Uncomment it when you’re planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta final;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# final;

location = /.well-known/carddav
return 301 $scheme://$host/distant.php/dav;

location = /.well-known/caldav
return 301 $scheme://$host/distant.php/dav;

location ~ /.well-known/acme-challenge
permit all;

# set max add measurement
client_max_body_size 512M;
fastcgi_buffers 64 4K;

# Disable gzip to keep away from the removing of the ETag header
gzip off;

# Uncomment in case your server is construct with the ngx_pagespeed module
# This module is presently not supported.
#pagespeed off;

error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

location /
rewrite ^ /index.php$uri;

location ~ ^/(?:construct|exams|config|lib|3rdparty|templates|knowledge)/
deny all;

location ~ ^/(?:.|autotest|occ|problem|indie|db_|console)
deny all;

location ~ ^/(?:index|distant|public|cron|core/ajax/replace|standing|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34]).php(?:$|/)
embrace fastcgi_params;
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
#Keep away from sending the safety headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;

location ~ ^/(?:updater|ocs-provider)(?:$|/)
try_files $uri/ =404;
index index.php;

# Including the cache management header for js and css information
# Be sure it’s BELOW the PHP block
location ~* .(?:css|js)$
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Management “public, max-age=7200”;
# Add headers to serve safety associated headers (It’s meant to
# have these duplicated to those above)
add_header X-Content material-Sort-Choices nosniff;
add_header X-XSS-Safety “1; mode=block”;
add_header X-Robots-Tag none;
add_header X-Obtain-Choices noopen;
add_header X-Permitted-Cross-Area-Insurance policies none;
# Elective: Do not log entry to belongings
access_log off;

location ~* .(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$
try_files $uri /index.php$uri$is_args$args;
# Elective: Do not log entry to different belongings
access_log off;

Save and shut the file. Check Nginx configuration, then reload Nginx for the modifications to take impact.

sudo nginx -t

sudo systemctl reload nginx

Step four: Install and Allow PHP Modules

Run the next instructions to set up PHP modules required or beneficial by NextCloud.

sudo apt set up php-imagick php7.2-common php7.2-gd php7.2-json php7.2-curl  php7.2-zip php7.2-xml php7.2-mbstring php7.2-bz2 php7.2-intl

Step 5: Allow HTTPS

Now you possibly can entry the Nextcloud net set up wizard in your browser by getting into the area identify on your Nextcloud set up.

ubuntu 18.04 nextcloud nginx

If the online web page can’t load, you in all probability want to open port 80 in firewall.

sudo iptables -I INPUT -p tcp –dport 80 -j ACCEPT

And port 443 as properly.

sudo iptables -I INPUT -p tcp –dport 443 -j ACCEPT

Earlier than getting into any delicate info, we should always allow safe HTTPS connection on Nextcloud. We will get hold of a free TLS certificates from Let’s Encrypt. Install Let’s Encrypt shopper (certbot) from Ubuntu 18.04 repository.

sudo apt set up certbot python3-certbot-nginx

Python-certbot-nginx is the Nginx plugin. Subsequent, run the next command to get hold of a free TLS certificates utilizing the Nginx plugin.

sudo certbot –nginx –agree-tos –redirect –hsts –staple-ocsp –email your-email-address -d


  • –nginx: Use the Nginx authenticator and installer
  • –agree-tos: Agree to Let’s Encrypt phrases of service
  • –redirect: Add 301 redirect.
  • –hsts: Add the Strict-Transport-Safety header to each HTTP response.
  • –staple-ocsp: Allows OCSP Stapling.
  • -d flag is adopted by an inventory of domains, separated by comma. You’ll be able to add up to 100 domains.
  • –e-mail: E-mail used for registration and restoration contact.

You may be requested if you’d like to obtain emails from EFF(Digital Frontier Basis). After selecting Y or N, your TLS certificates might be mechanically obtained and configured for you, which is indicated by the message under.

ubuntu 18.04 nextcloud 13

The Nginx plugin isn’t sensible sufficient to deal with such complicated configuration file. It failed to redirect HTTP to HTTPS and the HSTS header wasn’t added. We will open the configuration file and enabled these two function manually.

sudo nano /and so forth/nginx/conf.d/nextcloud.conf

To redirect HTTP to HTTPS, your Nginx configuration file wants to embrace a 301 redirect like under.

pay attention 80;
return 301$request_uri;

pay attention 443 ssl; # managed by Certbot
ssl_certificate /and so forth/letsencrypt/reside/; # managed by Certbot
ssl_certificate_key /and so forth/letsencrypt/reside/; # managed by Certbot
embrace /and so on/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /and so forth/letsencrypt/ssl-dhparams.pem; # managed by Certbot

remaining configurations

We will then add the next line within the ssl server block to allow HSTS header.

add_header Strict-Transport-Safety “max-age=31536000” all the time;

Additionally, you possibly can allow HTTP2 protocol by including the choice http2.

pay attention 443 ssl http2; # managed by Certbot

Right here’s a part of the configurations on my server.

nextcloud 13 ubuntu 18.04 LEMP stack

Save and shut the file. Then textual content Nginx configurations.

sudo nginx -t

If the check is profitable, reload Nginx for the change to take impact.

sudo systemctl reload nginx

The above configuation will get A+ rating on SSL check.

install nextcloud 13 ubuntu 18.04

End the Set up in your Net Browser

Now you possibly can entry the Nextcloud net set up wizard utilizing HTTPS connection. To finish the set up, you want to create an admin account, enter the trail of Nextcloud knowledge folder, enter database particulars created earlier. You should use the default localhost as host tackle, or you possibly can enter localhost:3306, as MariaDB listens on port 3306.

The info folder is the place customers’ information are saved. For safety, it’s greatest to place the info listing outdoors of Nextcloud net root. So as an alternative of storing customers’ information underneath /usr/share/nginx/nextcloud/knowledge/, we will change it to /usr/share/nginx/nextcloud-data. which could be created with the next command:

sudo mkdir /usr/share/nginx/nextcloud-data

Then make certain Nginx consumer (www-data) has write permission to the info listing.

sudo chown www-data:www-data /usr/share/nginx/nextcloud-data -R

nextcloud ubuntu 18.04 install guide

As soon as it’s executed, you will notice the Net interface of Nextcloud. Congrats! You can begin utilizing it as your personal cloud storage.

setup nextcloud ubuntu nginx

How to Install NextCloud Shopper on Ubuntu 18.04 Desktop

The NextCloud staff offers an official PPA. Run the next instructions on Ubuntu 18.04 desktop to isntall the shopper.

sudo add-apt-repository ppa:nextcloud-devs/shopper

sudo apt set up nextcloud-client

Notice that you simply don’t want to run sudo apt replace anymore in Ubuntu 18.04 when addding PPA. It should run routinely ?

ubuntu 18.04 nextcloud ppa

NextCloud Shopper on Ubuntu 18.04

ubuntu 18.04 nextcloud client

How to Transfer the Knowledge Listing

In case you want to transfer the NextCloud knowledge listing, there are four steps to accomplish this. First, you want to use the cp command to copy the info listing to the brand new listing. For instance, the mount level of my exterior onerous drive is /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731. I create the brand new knowledge listing on the exterior arduous drive.

sudo mkdir /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/

Then I copy the unique knowledge listing to the brand new knowledge listing. -R flag means the copy operation is recursive.

sudo cp /usr/share/nginx/nextcloud-data/* /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/ -R

You additionally want to copy the .ocdata file.

sudo cp /usr/share/nginx/nextcloud-data/.ocdata /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/

Subsequent, you want to set www-data (Nginx consumer) because the proprietor.

sudo chown www-data:www-data /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/ -R

Lastly, you want to edit the config.php file.

sudo nano /usr/share/nginx/nextcloud/config/config.php

Discover the next line and alter the worth of datadirectory.

‘datadirectory’ => ‘/usr/share/nginx/nextcloud-data’,

Save and shut the file. Reload NextCloud net web page and you’re carried out.

I hope this tutorial helped you put in NextCloud 13 on Ubuntu 18.04 server with Nginx. As all the time, for those who discovered this submit helpful, then subscribe to our free publication to get extra ideas and tips. Take care.

Fee this tutorial

[Total: 15 Average: 3.9]

(perform(d, s, id)
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); = id;
js.src = “//”;
fjs.parentNode.insertBefore(js, fjs);
(doc, ‘script’, ‘facebook-jssdk’));