Next Cloud Installation

From Scottworld
Jump to navigation Jump to search


Set up DNS (CNAME) to point to your nextcloud server. CNAME ---> Solaris

Also make sure it is set internally (if we are using split DNS)

Set up some directories

Create a directory to hold the nextcloud files .. make this outside the standard WWW readable dirrectory

mkdir /opt/nextcloud/

Create a directory (outside of your WWW to hold the personal cloud files for our users)

mkdir /srv/data/scottcloud

Download Nextcloud

We can down grab a copy of the latest NetCloud install.

Check the latest version.
cd /opt/
wget  (for example)
tar -xvf <tarfile>

Change the perms to let apache can r/w

chown www-data:www-data /opt/nextcloud -R
chmod 770 /opt/nextcloud -R

Create the database

We should create the NextCloud database first. I tend to use phpMyAdmin (you can use the terminal if you are savvy)

Make sure the charset is    utf8mb4_unicode_ci  (this ensure you have the full character set)

Create a user "scottcloud" with an empty database of the same name with full privileges.

php Tweaks

We need some extra php modules.

apt install php-gd php-json php-mysql php-curl php-mbstring php-intl php-gmp php-imagick php-zip php-xml php-smbclient smbclient php-bcmath

Apache Web Server Configuration

On Debian, Ubuntu, and their derivatives, Apache installs with a useful configuration so all you have to do is create a /etc/apache2/sites-available/scottcloud.conf file with these lines in it, replacing the Directory and other filepaths with your own filepaths:

<VirtualHost *:80>
        Redirect permanent /

<IfModule mod_ssl.c>
        <VirtualHost *:443>
                DocumentRoot /opt/nextcloud
                CustomLog ${APACHE_LOG_DIR}/scottcloud.log combined
                SSLEngine On
                SSLCertificateFile /etc/letsencrypt/live/
                SSLCertificateKeyFile /etc/letsencrypt/live/
                Include /etc/letsencrypt/options-ssl-apache.conf
                <Directory /opt/nextcloud>
                        Require all granted
                        AllowOverride All
                        Options FollowSymLinks MultiViews
                        <IfModule mod_dav.c>
                                Dav Off

                <IfModule mod_headers.c>
                        Header always set Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"
                        Header always set X-Frame-Options SAMEORIGIN

Additional Apache Configurations

For Nextcloud to work correctly, we need the module mod_rewrite. Enable it by running:

   a2enmod rewrite
   a2enmod headers
   a2enmod env
   a2enmod dir
   a2enmod mime

When using SSL, take special note of the ServerName. You should specify one in the server configuration, as well as in the CommonName field of the certificate. If you want your Nextcloud to be reachable via the internet, then set both of these to the domain you want to reach your Nextcloud server.

Now restart Apache:

 a2ensite scottcloud.conf

Add SSL cert for scottcloud via letsencrypt

Web Installation

Point a browser at...

Fill in the fields for your admin user / database / default data directory

House Keeping

Create a file in /etc/cron.d

nano /etc/crond.d/scottcloud

Add the line to do some housekeeping every 15 mins.

 */15  *  *  *  * www-data php -f /opt/scottcloud/cron.php

Certbot SSL

Enable SSL on your cloud install with LetsEncrypt.

Clone into a git repository

cd /opt/
git clone

Now enter the git and run ...

cd /opt/
./letsencrypt-auto --non-interactive --agree-tos --email --apache -d --hsts

You should now have a A* rating.. check here

Set up a renewal check...

nano /etc/cron.d/letsencrypt
* 1 * * 1 root /etc/certbot/certbot-auto renew --quiet

Make things look a bit nicer

Make browsers redirect to HTTPS

nano /opt/nextcloud/config/config.php

Add / check these lines... to make a clean URL and set default locale etc.

 'overwrite.cli.url' => '',
 'htaccess.RewriteBase' => '/',
 'default_locale' => 'en_GB',

sudo -u www-data php /opt/nextcloud/occ maintenance:update:htaccess

Setup Memory caching (REDIS)

apt install redis-server php-redis
adduser www-data redis
nano /etc/redis/redis.conf

Comment out the bind line

#bind ::1

Change the following lines

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 0
# Unix socket.
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
unixsocket /run/redis/redis.sock
unixsocketperm 770

Edit the /opt/nextcloud/config/config.php and add these lines.

  'memcache.local' => '\OC\Memcache\Redis',
  'memcache.distributed' => '\OC\Memcache\Redis',
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => [
             'host' => '/run/redis/redis.sock',
             'port' => 0,

Restart ...

systemctl restart redis
systemctl restart apache2