Latest

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

By July 29, 2020 No Comments

 

This tutorial shall be exhibiting you how you can set up NextCloud on Ubuntu 20.04 LTS with Nginx net server.

What’s NextCloud?

NextCloud is a free open-source self-hosted cloud storage answer. It’s functionally just like Dropbox. Proprietary cloud storage options (Dropbox, Google Drive, and many others) are handy, however at a value: they can be utilized to gather private information as a result of your recordsdata are saved on their computer systems. If you happen to anxious about privateness, you may swap to NextCloud, which you’ll be able to set up in your non-public residence server or on a digital non-public server (VPS). You may add your recordsdata to your server by way of NextCloud after which sync these recordsdata to your desktop laptop, laptop computer or smartphone. This manner you could have full management of your information.

NextCloud Options

  • Free and open-source
  • Finish-to-end encryption, that means recordsdata may be encrypted on shopper units earlier than uploaded to the server, so even when somebody steals your server, they cannot learn your recordsdata.
  • Could be built-in with an internet workplace suite (Collobora On-line, OnlyOffice) so you may create and edit your doc, ppt, xls recordsdata instantly from NextCloud.
  • The app retailer accommodates lots of of apps to increase performance (like calendar app, contacts app, note-taking app, video conferencing app, and many others).
  • The sync shopper is obtainable on Linux, macOS, Home windows, iOS and android.

Stipulations

NextCloud is written in PHP programing language. To observe this tutorial, you first want to put in LEMP stack on Ubuntu 20.04. If you happen to haven’t already accomplished so, please take a look at the next tutorial.

You may set up NextCloud on your private home server or a VPS (digital non-public server). You additionally want a site identify, so later in your will have the ability to allow HTTPS to encrypt the HTTP site visitors. I registered my area identify from NameCheap as a result of the worth is low and so they give whois privateness safety free for all times.

Now let’s set up NextCloud.

Step 1: Obtain NextCloud on Ubuntu 20.04

Log into your Ubuntu 20.04 server. Then obtain the NextCloud zip archive onto your server. The most recent secure model is 18.0.Four at time of this writing. Chances are you’ll want to alter the model quantity. Go to https://nextcloud.com/set up and click on the obtain for server button to see the most recent model.

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

You may run the next command to obtain it in your server.

wget https://obtain.nextcloud.com/server/releases/nextcloud-18.0.4.zip

You may all the time use the above URL format to obtain NextCloud. If a brand new model comes out, merely substitute 18.0.Four with the brand new model quantity.

As soon as downloaded, extract the archive with unzip.

sudo apt set up unzip

sudo unzip nextcloud-18.0.4.zip -d /usr/share/nginx/

The -d possibility specifies the goal listing. NextCloud net recordsdata shall be extracted to /usr/share/nginx/nextcloud/. Then we have 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 Person for Nextcloud in MariaDB Database Server

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

sudo mysql

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 should use your most popular identify for this consumer. Substitute your-password together 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;

exit;

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Step 3: Create a Nginx Config File for Nextcloud

Create a nextcloud.conf file in /and many others/nginx/conf.d/ listing, with a command-line textual content editor like Nano.

sudo nano /and many others/nginx/conf.d/nextcloud.conf

Copy and paste the next textual content into the file. Substitute nextcloud.instance.com with your individual most popular sub-domain. Don’t neglect to create DNS A file for this sub-domain in your DNS zone editor. If you happen to don’t have an actual area identify, I like to recommend going to NameCheap to purchase one. The worth is low and so they give whois privateness safety free for all times.

server {
hear 80;
hear [::]:80;
server_name nextcloud.instance.com;

# Add headers to serve safety associated headers
add_header X-Content material-Kind-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;
add_header Referrer-Coverage no-referrer;

#I discovered this header is required on Ubuntu, however not on Arch Linux.
add_header X-Body-Choices “SAMEORIGIN”;

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

access_log /var/log/nginx/nextcloud.entry;
error_log /var/log/nginx/nextcloud.error;

location = /robots.txt

# The next 2 guidelines are solely wanted for the user_webfinger app.
# Uncomment it if you happen to’re planning to make use of 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
enable all;

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

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

# Uncomment in case your server is construct with the ngx_pagespeed module
# This module is at present 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|assessments|config|lib|3rdparty|templates|information)/ {
deny all;
}
location ~ ^/(?:.|autotest|occ|challenge|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(?:$|/)
embody 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.4-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 recordsdata
# Make certain it’s BELOW the PHP block
location ~* .(?:css|js)$

location ~* .(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$
}

Save and shut the file. (To avoid wasting a file in Nano textual content editor, press Ctrl+O, then press Enter to verify. To exit, press Ctrl+X.)

Then check Nginx configuration.

sudo nginx -t

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

sudo systemctl reload nginx

Step 4: Set up and Allow PHP Modules

Run the next instructions to put in PHP modules required or really helpful by NextCloud.

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

Step 5: Allow HTTPS

Now you may entry the Nextcloud net set up wizard in your net browser by coming into the area identify on your Nextcloud set up.

nextcloud.instance.com

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

If the online web page can’t load, you in all probability must 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 coming into any delicate info, we must always allow safe HTTPS connection on Nextcloud. We will acquire a free TLS certificates from Let’s Encrypt. Set up Let’s Encrypt shopper (certbot) from Ubuntu 20.04 repository.

sudo apt set up certbot python3-certbot-nginx

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

sudo certbot –nginx –agree-tos –redirect –staple-ocsp –email [email protected] -d nextcloud.instance.com

The place:

  • –nginx: Use the Nginx authenticator and installer
  • –agree-tos: Conform to Let’s Encrypt phrases of service
  • –redirect: Implement HTTPS by including 301 redirect.
  • –staple-ocsp: Allow OCSP Stapling.
  • –electronic mail: E-mail used for registration and restoration contact.
  • -d flag is adopted by a listing of domains, separated by comma. You may add as much as 100 domains.

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

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

I discovered that Certbot can’t mechanically add HSTS header within the Nginx config file for Nextcloud. If you need to allow HSTS (HTTP Strict Transport Safety), then edit the file.

sudo nano /and many others/nginx/conf.d/nextcloud.conf

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 may allow HTTP2 protocol by including the choice http2, which is able to pace up webpage loading.

hear 443 ssl http2; # managed by Certbot

Like beneath.

Install NextCloud on Ubuntu 20.04 using Nginx (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 configuration will get A+ rating on SSL check.

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Step 6: End the Set up in your Internet Browser

Now you may entry the Nextcloud net set up wizard utilizing HTTPS connection.

https://nextcloud.instance.com

To finish the set up, it’s worthwhile to create an admin account, enter the trail of Nextcloud information folder, enter database particulars you created in step 2. You need to use the default localhost as host deal with, or you may enter localhost:3306, as MariaDB listens on port 3306.

The information folder is the place customers’ recordsdata are saved. For safety, it’s greatest to position the information listing exterior of Nextcloud webroot listing. So as an alternative of storing customers’ recordsdata beneath /usr/share/nginx/nextcloud/information/, we will change it to /usr/share/nginx/nextcloud-data. which may be created with the next command:

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

Then ensure Nginx consumer (www-data) has write permission to the information listing.

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

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Click on the End Setup button, you will note the Internet interface of Nextcloud. Congrats! You can begin utilizing it as your non-public cloud storage.

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Find out how to Arrange NextCloud E-mail Notification

In case your NextCloud occasion shall be utilized by a couple of individual, it’s necessary that your NextCloud server can ship transactional emails, equivalent to password-resetting electronic mail. First, it’s best to set an electronic mail deal with on your personal account. Go to Settings -> Private Data and set an electronic mail deal with on your account.

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Then go to Settings -> Primary settings. You will see the e-mail server settings. There are two ship modes: sendmail and smtp. You may select the sendmail mode in case your NextCloud host has an SMTP server operating.

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

If you need to make use of an SMTP server operating on one other host, then select smtp mode and enter the SMTP server deal with and login credentials like beneath. Select STARTTLS for encryption.

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

For how you can arrange an electronic mail server, please take a look at the next tutorial:

Find out how to Transfer the Information Listing

In case it’s worthwhile to transfer the NextCloud information listing, there are Four steps to perform this. First, it’s worthwhile to use the cp command to repeat the information 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 information listing on the exterior onerous drive.

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

Then I copy the unique information listing to the brand new information 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 repeat the .ocdata file.

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

Subsequent, it’s worthwhile 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, it’s worthwhile 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 accomplished.

Step 7: Improve PHP Reminiscence Restrict

The default PHP reminiscence restrict is 128MB. NextCloud recommends 512MB for higher efficiency. To alter PHP reminiscence restrict, edit the php.ini file.

sudo nano /and many others/php/7.4/fpm/php.ini

Discover the next line. (line 409)

memory_limit = 128M

Change the worth.

memory_limit = 512M

Save and shut the file. Alternatively, you may run the next command to alter the worth with out manually opening the file.

sudo sed -i ‘s/memory_limit = 128M/memory_limit = 512M/g’ /and many others/php/7.4/fpm/php.ini

Then reload PHP-FPM service for the adjustments to take impact.

sudo systemctl reload php7.4-fpm

Step 8: Set Up PHP to Correctly Question System Atmosphere Variables

Edit the www.conf file.

sudo nano /and many others/php/7.4/fpm/pool.d/www.conf

Discover the next line (line 396).

;clear_env = no

Take away the semicolon to uncomment this line.

clear_env = no

Save and shut the file. Alternatively, you may run the next command to uncomment this line with out manually opening the file.

sudo sed -i ‘s/;clear_env = no/clear_env = no/g’ /and many others/php/7.4/fpm/pool.d/www.conf

Then reload PHP-FPM service for the adjustments to take impact.

sudo systemctl reload php7.4-fpm

Step 9: Improve Add File Dimension Restrict

The default most add file measurement restrict set by Nginx is 1MB. To permit importing massive recordsdata to your NextCloud server, edit the Nginx configuration file for NextCloud.

sudo nano /and many others/nginx/conf.d/nextcloud.conf

Now we have already set the utmost file measurement on this file, as indicated by

client_max_body_size 512M;

You may change it if you happen to want, like 1G.

client_max_body_size 1024M;

Save and shut the file. Then reload Nginx for the adjustments to take impact.

sudo systemctl reload nginx

PHP additionally units a restrict of add file measurement. The default most file measurement for importing is 2MB. To extend the add measurement restrict, edit the PHP configuration file.

sudo nano /and many others/php/7.4/fpm/php.ini

Discover the next line (line 846).

upload_max_filesize = 2M

Change the worth like beneath:

upload_max_filesize = 1024M

Save and shut the file. Alternatively, you may run the next command to alter the worth with out manually opening the file.

sudo sed -i ‘s/upload_max_filesize = 2M/upload_max_filesize = 1024M/g’ /and many others/php/7.4/fpm/php.ini

Then restart PHP-FPM.

sudo systemctl restart php7.4-fpm

Step 10: Configure Redis Cache for NextCloud

If you happen to go to your NextCloud settings -> overview web page, you may see the next warning:

No reminiscence cache has been configured. To reinforce your efficiency please configure a memcache if accessible.

We are going to allow reminiscence caching for nextCloud by utilizing Redis. Run the next command to put in Redis server from Ubuntu repository.

sudo apt set up redis-server

You may test the model with:

redis-server -v

Pattern output:

Redis server v=5.0.7 sha=00000000:Zero malloc=jemalloc-5.2.1 bits=64 construct=636cde3b5c7a3923

Now we will test if redis server is operating.

systemctl standing redis

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Trace: If the above command didn’t stop instantly, you may press the Q key to realize again management of the terminal.

From the above screenshot, we will see that it’s operating and auto-start is enabled. If for any motive it’s not operating, execute the next command:

sudo systemctl begin redis-server

And if auto-start at boot time is just not enabled, you should use the next command to allow it:

sudo systemctl allow redis-server

In an effort to configure Redis as a cache for nextCloud, we have to set up the PHP extension for interfacing with Redis.

sudo apt set up php-redis

Test if the extension is enabled.

php –ri redis

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

We will see that Redis extension is enabled. If it’s not enabled, run the next command:

sudo phpenmod redis

Subsequent, edit nextCloud configuration file.

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

Add the next strains above the ending ); line.

‘memcache.distributed’ => ‘OCMemcacheRedis’,
‘memcache.native’ => ‘OCMemcacheRedis’,
‘memcache.locking’ => ‘OCMemcacheRedis’,
‘redis’ => array(
‘host’ => ‘localhost’,
‘port’ => 6379,
),

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Save and shut the file. Then restart Nginx and PHP-FPM.

sudo systemctl restart nginx php7.4-fpm

Now go to NextCloud settings -> overview web page once more and refresh the online web page, the warning about reminiscence caching must be gone.

Including Lacking Indexes

If you happen to see the next message within the NextCloud Settings -> Overview web page,

The database is lacking some indexes. Resulting from the truth that including indexes on massive tables might take a while they weren’t added mechanically.

Then it’s worthwhile to manually add these indexes. Change to the Nextcloud webroot listing.

cd /usr/share/nginx/nextcloud/

Run the next command so as to add indexes to the Nextcloud database.

sudo -u www-data php occ db:add-missing-indices

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Now if you happen to refresh the NextCloud Settings -> Overview web page, the warning about lacking indexes must be gone.

Conversion to Large Int

If you happen to see the next message within the NextCloud Settings -> Overview web page,

Some columns within the database are lacking a conversion to massive int. Resulting from the truth that altering column varieties on massive tables might take a while they weren’t modified mechanically.

Then it’s worthwhile to manually change the column kind. Change to the Nextcloud webroot listing.

cd /usr/share/nginx/nextcloud/

Change your Nextcloud into upkeep mode to stop customers from logging in and making adjustments.

sudo -u www-data php occ upkeep:mode –on

Then run the next command to alter the column kind.

sudo -u www-data php occ db:convert-filecache-bigint

As soon as it’s accomplished, swap off the upkeep mode.

sudo -u www-data php occ upkeep:mode –off

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Now if you happen to refresh the NextCloud Settings -> Overview web page, the warning about massive int must be gone.

Find out how to Set up NextCloud Consumer on Ubuntu 20.04 Desktop

Run the next instructions on Ubuntu 20.04 desktop to put in the shopper from the default repository.

sudo apt set up nextcloud-client

NextCloud Consumer on Ubuntu 20.04

Install NextCloud on Ubuntu 20.04 using Nginx (LEMP Stack)

Consumer software program for macOS, Home windows, Android and iOS may be discovered on the Nextcloud obtain web page.

Find out how to Allow OnlyOffice/Collabora On-line

By default, Nextcloud ships with help for OnlyOffice, which an internet workplace suite that permits you to edit your doc, ppt, xls recordsdata instantly from NextCloud. Nonetheless, I discovered this app isn’t very dependable. And the neighborhood version enable solely 20 customers at most. It’s essential buy an enterprise version you probably have greater than 20 customers. There’s one other open-source LibreOffice-based on-line workplace suite known as Collabora On-line that has the identical performance. You may learn the next article to combine it with Nextcloud.

Troubleshooting Ideas

If you happen to encounter errors, you may test one of many following log recordsdata to seek out out what’s flawed.

  • Nginx error log: /var/log/nginx/error.log
  • Nginx error log for the Nextcloud digital host: /var/log/nginx/nextcloud.error
  • Nextcloud utility log: /usr/share/nginx/nextcloud/information/nextcloud.log

Wrapping Up

I hope this tutorial helped you put in NextCloud on Ubuntu 20.04 server with Nginx. As all the time, if you happen to discovered this put up helpful, then subscribe to our free publication to get extra ideas and methods. Take care 🙂

Charge this tutorial

[Total: 0 Average: 0]