Install and configure Nextcloud with Redis


For those of you who do not know what nextcloud is, this part is for you.

Nextcloud is an open source, self-hosted file share and communication platform. Access & sync your files, contacts, calendars & communicate and collaborate across your devices. You decide what happens with your data, where it is and who can access it!

Nextcloud products are designed with compliance in mind, providing extensive data policy enforcement, encryption, user management, and auditing capabilities.

It is functionally similar to Dropbox out of the box, but with the ability to install addon’s like video conference calling, facebook style messenger, antivirus, and online office document editing to compete and replace Microsoft Office 365 or Google Drive/Docs.

Video Guide on Installing Nextcloud

Step 1: Prerequisites

In order to get up and running with Nextcloud, we are going to have to install a few more packages to your server.

*NOTE* This guide assumes you have already installed the LAMP stack
from Install the latest LAMP stack on Ubuntu 16.04 Server

Nextcloud needs a minimum of 128MB RAM, and they recommend a minimum of 512MB to get started, however I would recommend a minimum of 2GB to be able to run all the cool addons, but if all you want is a dropbox replacement without all the extras then 512MB should work just fine, however keep in mind this guide is prepping for all the frills down the road.

* PHP module bz2 (required for extraction of apps)
* PHP module SimpleXML
* PHP module XMLReader
* PHP module XMLWriter
* PHP module intl ()
* PHP module smbclient
* PHP module imap

sudo apt install php7.0-bz2 php7.0-xml php7.0-pspell php7.0-intl php7.0-gmp php7.0-imap php-smbclient php-redis

Optional but recommended packages:

sudo apt install ffmpeg libreoffice php-imagick

Step 2: Configure the PHP.ini file

Alright so here we have 2 files to edit, one is the config apache will use and the other the system will use.

First let’s configure the apache php.ini

sudo nano /etc/php/7.0/apache2/php.ini

We are going to be doing some search, to search with nano you press “Ctrl + w”

Find ;date.timezone = and delete the ; and make it look like this
date.timezone = America/New_York

Find upload_max_filesize = and change it to at least 500M
upload_max_filesize = 500M

Find max_execution_time = 30 and change it to
max_execution_time = 360

Find ;opcache.enable= and delete the ; and make it

Do the same for the following

Ctrl + x followed by y then enter to save

Now to edit the systems php.ini

sudo nano /etc/php/7.0/cli/php.ini

Same as above, find and change these

date.timezone = America/New_York


Ctrl + x followed by y then enter to save

Step 3: Configure MySQL/MariaDB Server

Now before we go and create the database & user we need to make a slight adjustment to MySQL.

The change we are making is just telling the server to use InnoDB storage engine as nextcloud doesn’t support MyISAM (Default).

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Alright, now we can go about this 1 of 2 ways depending on how you like to organize your settings.

We can create a new section in the config under [mysqld] with a collection of all your new tweaks, or we can add them to their own preexisting section # * InnoDB.

I’m going to create a new section below.

find [mysqld] and under it enter this

### Nextcloud Settings ###

Ctrl + x followed by y then enter to save

Next lets go ahead and enter the mysql server’s cli

sudo mysql -uroot

To create the database we need to enter


And the username & password, replace nextclouduser with whatever you want.  *NOTE* this account should only ever be used by nextcloud

CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'new_secure_password_here';

Lets give the user you created above permission to use the new database

GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' WITH GRANT OPTION;

Finally we need to save the changes & exit


Step 4: Downloading Nextcloud

Navigate to https://nextcloud.com/install/ and click Download.

Click “Details and Download” options, and then right click on “.tar.bz2” and copy link/copy link location.

Switch back to your server and pushd to tmp & download the link we copied from the browser

pushd /tmp

wget https://download.nextcloud.com/server/releases/nextcloud-14.0.1.tar.bz2

Once the download has finished we need to extract it

sudo tar xf ./nextcloud-14.0.1.tar.bz2 -C /opt/


After it finishes extracting, we need to change some permissions and create a data directory.

Nextcloud will default the data directory inside of the nextcloud folder, and for security reasons, you should never store private/personal data where an HTTP server is accessing to serve a website.

sudo chown -R www-data:www-data /opt/nextcloud
sudo chmod -R 755 /opt/nextcloud
sudo mkdir /media/nextcloud
sudo chown -R www-data:www-data /media/nextcloud

Step 5: Configuring Apache

Almost there, next step is to create the apache config we will use to serve the nextcloud site.

Go ahead and create the config file

sudo nano /etc/apache2/sites-available/nextcloud.conf

Now we need to create the virtual host.

Change ServerAdmin to match one of your emails
Set ServerName & ServerAlias to your domain name

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /opt/nextcloud/
     ServerName ncsite.com
     ServerAlias www.ncsite.com

     Alias /nextcloud "/opt/nextcloud/"

     <Directory /opt/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
        SetEnv HOME /opt/nextcloud
        SetEnv HTTP_HOME /opt/nextcloud

	 <IfModule headers_module>
		RequestHeader set X-HTTPS 1
        Header set Referrer-Policy "no-referrer-when-downgrade"

     ErrorLog /var/log/apache2/nc-error.log
     CustomLog /var/log/apache2/nc-access.log combined

Ctrl + x followed by y then enter to save

Next, we need to enable the config and a few modules.

sudo a2ensite nextcloud.conf
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod env
sudo a2enmod dir
sudo a2enmod mime

If you would also like it to be the default site, i.e. type in the ip and it will server nextcloud go ahead and enter this

sudo a2dissite 000-default

Now we just need to restart apache

sudo service apache2 restart

Step 6: Install & Configure Redis Caching Server

Using a memory caching server can significantly improve the performance of Nextcloud, where frequently requested objects are stored in memory for faster retrieval.

To install this wonder enter the following

sudo apt install redis-server

Once installed lets go and configure it

sudo apt install redis-server

We dont have to do much, the only thing we are going to do is enable the redis socket, and make it writable.

Find ;unixsocket /var/run/redis/redis.sock and remove the ;
It should look like this
unixsocket /var/run/redis/redis.sock

Next right under it you should see unixsocketperm 700, go ahead and change it to this
unixsocketperm 766

Ctrl + x followed by y then enter to save

Now restart the Redis server

sudo service redis restart

Step 7: Nextcloud Installer

Go back to your browser and navigate to your nextcloud server’s domain name.

Create Admin

Enter the username and password you would like for the admin account.

Set Data Folder

Enter /media/nextcloud

Database config

For the database user, enter the mysql user we created back in step 3 followed by the password you used in the database password field.

For the database name, enter “nextcloud” unless you chose a different name back in step 3.

Leave localhost alone

Step 8: Final Configuration of nextcloud’s config.php

We are going to be adding 2 things to nextcloud’s config.php. 1 is to enable prettyurls.

Pretty URLs remove the index.php-part in all Nextcloud URLs, for example in sharing links like https://ncsite.com/index.php/s/somethingmaking URLs shorter and prettier. Second is to enable the Redis Caching Server.

First lets open the config in nano

sudo nano /opt/nextcloud/config/config.php

Next add this line under ‘overwrite.cli.url’ => ‘https://ncsite.com/’,

'overwrite.cli.url' => 'https://ncsite.com/',
'htaccess.RewriteBase' => '/',

Now to add the Redis server, goto the end of the file right after ‘installed’ => true, and right before );

*NOTE* Make sure you set a good secure password, as redis does not
use authentication and anyone with access could potentially read
the cache

'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
     'host' => '/var/run/redis/redis.sock',
     'port' => 0,
     'dbindex' => 0,
     'password' => 'secret',
     'timeout' => 1.5,

and finally we can add a cron job to automate nextcloud’s background tasks

crontab -u www-data -e

If it prompts you for which editor you would like to use, choose nano (2)

Once in nano, goto the bottom of the file and add this

*/15  *  *  *  * php -f /var/www/nextcloud/cron.php

Step 9: Nextcloud Settings

From the desktop browser, navigate back to your new nextcloud domain and login. 

Once logged in, click the top right colored circle with the first letter of your username and then “Settings”

Then “Basic settings” in the menu on the left.

Under “Background Jobs”, change it from AJAX to Cron.

You have finished install Nextcloud!

I will write a guide on setting up and securing SSL as well as an in-depth guide on setting up and using some of the bigger addons available

If you are interested I will also be writing a guide on how to install collabora both from source and from docker in the future along with a guide on OwnPad and maybe EtherCalc.

Hope you enjoyed it, and if you have any topics you would like me to cover please comment below!

Leave a Reply

Your email address will not be published. Required fields are marked *