Nextcloud is open-source software that allows you to host your own iCloud, Google Drive or Dropbox, with a suite of applications. Their application suite includes a calendar, email client, instant messenger, and video chat just to name a few. If you would like to visit the Nextcloud app store to view their large library of applications click on the link below:
When using Nextcloud, you can take full control of your cloud storage from installation to storage space. And using it with ShellsTM you can create your own unique cloud experience. In this article, we will cover the installation and configuration of Nextcloud with Ubuntu 20.04 using the Nginx webserver.
Before moving on to installation, if you would like to make Nextcloud accessible remotely please click on the link below to purchase a public IP address.
How to Purchase and Activate a Dedicated Public IP Address for your Shell™
Installing a LEMP stack (Linux Nginx Mysql and PHP)
Let's begin by selecting the on the bottom left on Ubuntu and searching for a terminal up top in the search bar and clicking on the Terminal icon to open a session and update our system packages.
sudo apt update
After that, we can move on to installing and enabling Nginx
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
Once installed and enabled, let's check the status of Nginx
sudo systemctl status nginx
or
Open up your web browser and type localhost in the address bar. You should see the following below:
For those who have purchased a public IP, make sure to download and enable your firewall and open port: 80 with the following three commands so you can access Nextcloud remotely.
sudo apt install ufw
sudo ufw enable
sudo ufw allow http
To check the status of the firewall, use the command below.
sudo ufw status
Next, we will install PHP 7.4 and download all the dependencies needed for Nextcloud with the following commands.
sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl php-imagick php7.4-zip php7.4-xml php7.4-bz2 php7.4-intl php7.4-bcmath php7.4-gmp
After PHP installation, let's start, enable and check the status of PHP.
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
systemctl status php7.4-rpm
Next let's install, and verify the status of MariaDB
sudo apt install mariadb-server mariadb-client
sudo systemctl status mariadb
After that, let's create a MySQL root password using the command below following the steps instructed to create root password.
sudo mysql_secure_installation
Now we need to log in to Mysql as root so we can create a database.
sudo mysql -u root -p
Creating a database for Nextcloud
We will need to create a Mysql database for our Nextcloud server with the following commands below.
CREATE DATABASE nextcloud;
CREATE USER 'shells_user'@'localhost' IDENTIFIED BY 'My$hell123';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'shells_user'@'localhost';
FLUSH PRIVILEGES;
exit
In this example above, we are using nextcloud (database name), shell_user (username), My$hell123(password) for the database, however, it is recommended to use your own credentials when creating your database.
Configuring Nginx for Nextcloud
We need to create an nextcloud.conf file. In this example, we will be using Nano to create and edit the file
sudo nano etc/nginx/conf.d/nextcloud.conf
Paste the following below in that file. In server_name I am using localhost because I am just accessing locally for now. However, if you have a domain name you would add it to the right of server_name.
server {
listen 80;
listen [::]:80;
server_name localhost;
# Add headers to serve security related headers
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
add_header X-Frame-Options "SAMEORIGIN";
# Path to the root of your installation
root /usr/share/nginx/nextcloud/;
access_log /var/log/nginx/nextcloud.access;
error_log /var/log/nginx/nextcloud.error;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
location ~ /.well-known/acme-challenge {
allow all;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
try_files $fastcgi_script_name =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
#Avoid sending the security 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;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
Once saved and closed, test the nextcloud.conf file to make sure there are no syntax errors.
sudo nginx -t
You should see the output below if the config has no errors
If there are no errors, restart Nginx.
sudo systemctl restart nginx
Installing Nextcloud
Now we can move on to Nextcloud installation using the wget command to download the zipped folder.
wget https://download.nextcloud.com/server/releases/nextcloud-20.0.7.zip
Next, unzip Nextcloud to the directory usr/share/nginx
sudo unzip nextcloud-20.0.7.zip -d /usr/share/nginx/
Now let's change ownership to www-data for the Nextcloud directory
sudo chown -R www-data:www-data /usr/share/nginx/nextcloud
Conclusion
Now we should be able to access Nextcloud using our web browser with http://your_public_ip if you purchased a public IP or with http:/localhost to access it locally. Once you reach your Nextcloud website, you must create a username/password and access Nextcloud with the database info from what we created earlier. When entering the database info, make sure to add the port number 3306 by localhost. For example, localhost:3306, that is the port number MariaDB listens on.
After that, you should now be able to access Nextcloud on the first login.
Comments
0 comments
Article is closed for comments.