User Tools

Site Tools


computing:nextcloud

This is an old revision of the document!



  • Nextcloud
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

Nextcloud


This tutorial is for users of Debian GNU/Linux seeking to set up a basic self-hosted or VPS Nextcloud instance. Before you start, you should read The issue with Public Cloud, which covers a little more about the value of hosting your own content/cloud instance. Also, do not proceed with this tutorial until you have a LAMP stack set up and until you have properly configured TLS encryption for your site. If you need help with doing that, please see the Apache Survivial tutorial. Now that your webserver is set up and securely accessed, proceed:

cd /var/www/test.com/public_html/
sudo wget https://download.nextcloud.com/server/releases/nextcloud-14.0.1.zip
sudo unzip nextcloud-14.0.1.zip
sudo mv /var/www/test.com/public_html/nextcloud/* /var/www/test.com/public_html/
sudo rm -r nextcloud  

Make sure to see if there is a newer version than what I have in the example above. The latest version of Nextcloud server can be found here Next Cloud Download. Okay, now it is time to set up permissions. Basically, Nextcloud relies on a set up similar to Moodle or DokuWiki, where the primary web root is owned by www-user and is also part of that group. For security, place the Nextcloud data directory outside of the web server's root directory. Here goes:

cd /var/www/test.com/public_html/
sudo chown www-data:www-data -R /var/www/test.com/public_html/* 
sudo mkdir /var/www/test.com/nextclouddata
sudo chown www-data:www-data -R /var/www/test.com/nextclouddata

Now it is time to set up the database so that when we leverage the web app to finish setup, it actually has a dedicated database to connect to. Again, since this tutorial assumes you have a basic LAMP stack already set-up, it skips right to set up in MySQL:

sudo mysql -u root -p

Enter your password for sudo and then for MySQL. Once inside MySQL command mode, you will have a “>” prompt. You will need to create a separate database for Nextcloud, a dedidcated database user for Nextcloud, and establish proper permissions for the dedicated database user. Here goes:

> CREATE DATABASE nextcloud;
> CREATE USER nextcloud@localhost IDENTIFIED BY 'put-password-here';
> GRANT ALL PRIVILEGES ON nextcloud.* to nextcloud@localhost IDENTIFIED BY 'put-password-here';
> FLUSH PRIVILEGES;
> EXIT;

Okay, you can now proceed to the website test.com and make finish the remaining set up using the Nextcloud website that is now active. Let's first restart the web server and mysql services:

sudo systemctl restart mysql
sudo systemctl restart apache2

Ok, now that those services are restarted, you should be able to access your website. Visit test.com in your browser, or if you are not using a domain, then visit localhost in your web browser of choice. When you do that you are given the following choices that match the configuration options above:

  • create new user name: <yourchoice, but do not use root, admin, etc., since this is public facing>
  • create new user pass: <this is public facing and is the admin user, so make it a bit beefy>
  • specify data folder: /var/www/test.com/nextclouddata
  • database user name: nextcloud
  • database name: nextcloud
  • database location: localhost

Once you are done, you can now use Nextcloud at will. Make sure you have a good backup in place, however, before you put significant time into migrating your files, calendars, contacts, and other workflow into it. With regard to backups, visit my RAID tutorial, or my rsync and rsnapshot tutorial. Happy clouding.

Nextcloud offered this:

sudo find /var/www/codetalkers.group/public_html/ -type f -print0 | xargs -0 chmod 0640
sudo find /var/www/codetalkers.group/public_html/ -type d -print0 | xargs -0 chmod 0750

But that gives me errors, so I developed this (also two lines), from within /var/www/codetalkers.group/public_html/ …

sudo chmod 0640 *.php *.txt *.html AUTHORS COPYING
sudo chmod 0750 {3rdparty,apps,assets,config,core,data,lib,ocm-provider,ocs,ocs-provider,resources,settings,themes,updater}

Then, the root directory:

sudo chown -R root:www-data /var/www/codetalkers.group/public_html

Now, the different sub-directories:

sudo chown -R www-data:www-data /var/www/codetalkers.group/public_html/apps/
sudo chown -R www-data:www-data /var/www/codetalkers.group/public_html/assets/
sudo chown -R www-data:www-data /var/www/codetalkers.group/public_html/config/
sudo chown -R www-data:www-data /var/www/codetalkers.group/public_html/data/
sudo chown -R www-data:www-data /var/www/codetalkers.group/public_html/themes/
sudo chown -R www-data:www-data /var/www/codetalkers.group/public_html/updater/

I suppose we could have just done:

sudo chown www-data:www-data {apps,assets,config,data,themes,updater}  

At any rate, now some other tweaks and hardening:

sudo chmod +x /var/www/codetalkers.group/public_html/occ
sudo chmod 0644 /var/www/codetalkers.group/public_html/.htaccess
sudo chown root:www-data /var/www/codetalkers.group/public_html/.htaccess

Oh yeah! Here is my Nextcloud instance: Nextcloud.

oemb1905 2018/10/09 20:51

computing/nextcloud.1543384391.txt.gz · Last modified: 2018/11/28 05:53 by oemb1905