NextCloud on your shared VPS

Nextcloud is a suite of client-server software for creating and using file hosting services. It is functionally similar to Dropbox, although Nextcloud is free and open-source, allowing anyone to install and operate it on a private server.

In contrast to proprietary services like Dropbox, the open architecture allows adding additional functionality to the server in form of applications and enables the user to have full control of their data.

The original ownCloud developer Frank Karlitschek forked ownCloud and created Nextcloud, which continues to be actively developed by Karlitschek and other members of the original ownCloud team.


  • your server is and it is running Ubuntu 16.04;
  • you already have a configured subdomain in the dns:;
  • your sudo user is admin;
  • the user you want to create for NextCloud is nextcloud;
  • the database main user is root and the password is mysqlpassword;
  • the database you will use is named nextclouddbwith the user nextclouddbuser with the password password

Create a new user and add it to Apache group

  • sudo adduser nextcloud
  • sudo usermod -a -G www-data nextcloud

Create the virtualhost for Apache

Apache specials

Please be sure to have an Apache configuration similar to what the following commands give:

  • sudo a2enmod rewrite
  • ​sudo a2enmod headers
  • sudo a​2enmod env
  • ​sudo a2enmod dir
  • ​sudo a2enmod mime
  • sudo a2enmod ssl
  • sudo a2ensite default-ssl
  • sudo service apache2 restart

Actually creating the host

  • su - nextcloud
  • cd ~
  • mkdir public_html
  • chmod 755 ./public_html
  • exit
  • sudo chgrp -R www-data /home/nextcloud/public_html
  • sudo chmod -R g+w /home/nextcloud/public_html
  • sudo nano /etc/apache2/sites-available/
  • <VirtualHost *:80>
      <Directory "/home/nextcloud/public_html">
        Allow from all
        Options +Indexes
        <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteBase /
          AllowOverride All
        <IfModule mod_dav.c>
          Dav off
      DocumentRoot /home/nextcloud/public_html
      SetEnv HOME /home/nextcloud/public_html
      SetEnv HTTP_HOME /home/nextcloud/public_html
  • sudo a2ensite
  • sudo service apache2 reload

Create the database

  • mysql -uroot -pmysqlpassword -e "CREATE DATABASE nextclouddb /*\!40100 DEFAULT CHARACTER SET utf8 */;"
  • mysql -uroot -pmysqlpassword -e "CREATE USER nextclouddbuser@localhost IDENTIFIED BY 'password';"
  • mysql -uroot -pmysqlpassword -e "GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextclouddbuser'@'localhost';"
  • mysql -uroot -pmysqlpassword -e "FLUSH PRIVILEGES;"
  • sudo nano /etc/mysql/my.cnf
    Add binlog-format = MIXED

Install other packages

  • sudo apt-get install apache2 mariadb-server libapache2-mod-php7.0
  • ​sudo apt-get install php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring
  • ​sudo apt-get install php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip
  • ​sudo apt-get install unzip


  • sudo su - nextcloud
  • cd ~/public_html
  • wget -O nextcloud-13-latest.tar.bz2
  • tar -xvjf nextcloud-13-latest.tar.bz2
  • rm nextcloud-13-latest.tar.bz2
  • cd nextcloud
  • mv ./* ../
  • cd ..
  • rm -rf nextcould
  • sudo chmod 0770 /home/nexcloud/public_html/data

Access to finish the setup. Also, be sure to check:

Also, do remember to check the firewall rules.

Activate SSL

  • sudo add-apt-repository ppa:certbot/certbot
  • sudo apt-get update
  • sudo apt-get install python-certbot-apache
  • sudo certbot --apache -d
  • sudo su - nextcloud
  • nano /home/nextcoud/public_html/config/config.php
    Change the option for overwrite.cli.url from http:// to https://

Activate opcache

  • sudo su - nextcloud
  • nano /home/nextcloud/php.ini
  • opcache.enable=1 opcache.enable_cli=1 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.memory_consumption=128 opcache.save_comments=1 opcache.revalidate_freq=1
  • Ctrl+x and Y to save

  • exit
  • sudo nano /etc/apache2/sites-available/
  • add PHPINIDir /home/nextcloud below the ServerName line
  • sudo nano /etc/apache2/sites-available/