apt-get -y install apache2 php unzip libapache2-mod-php php-mcrypt php-mysql
apt-get -y install php-ctype php-dom php-gd php-iconv php-json php-mbstring php-posix php-common
apt-get -y install php-simplexml php-xmlreader php-xmlwriter php-zip php-json php-mbstring
apt-get -y install php-curl php-fileinfo php-bz2 php-intl php-smbclient php-ftp php-imap php-xml
apt-get -y install php-exif php-gmp php-imagick

a2enmod rewrite
a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime
a2enmod setenvif 
a2enmod ssl

service apache2 restart

Disable default sites

a2dissite 000-default.conf
a2dissite default-ssl.conf

service apache2 restart

Setup Apache2 config

nano /etc/apache2/sites-available/cloud.conf
LoadModule headers_module modules/mod_headers.so

<VirtualHost *:80>
     DocumentRoot "/var/www/nextcloud"
     ServerName cloud.example.com
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
     Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;"
<IfModule mod_dav.c>
      Dav off
<Directory /var/www/nextcloud>
     AllowOverride None
     Order deny,allow
     deny from all
     SetEnv HOME /var/www/nextcloud
     SetEnv HTTP_HOME /var/www/nextcloud
     Satisfy Any
<Directory /var/www/nextcloud>
     AllowOverride All
     Order allow,deny
     allow from all

## If you are not using an proxy use this 443 config ##

<VirtualHost *:443>
     ServerName cloud.example.com:443
     DocumentRoot /var/www/nextcloud
     SSLEngine on
     SSLCertificateFile /mnt/certbot/letsencrypt/live/example.com/fullchain.pem
     SSLCertificateKeyFile  /mnt/certbot/letsencrypt/live/example.com/privkey.pem
     Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;"

## If you are not using an proxy use this 443 config ##

Pending changes to apache2 config...

ln -s /etc/apache2/sites-available/cloud.conf /etc/apache2/sites-enabled/cloud.conf
service apache2 restart

Download Nextcloud 14.0.4

cd /var/www
mkdir nextcloud
wget https://download.nextcloud.com/server/releases/nextcloud-14.0.4.zip && unzip nextcloud-14.0.4.zip
rm nextcloud-14.0.4.zip
chown -R www-data:www-data /var/www/nextcloud
chmod -R g+s /var/www/nextcloud

Install MySQL server

apt-get install mariadb-server -y
mysql -e "CREATE DATABASE nc_2018;"
mysql -e "GRANT ALL PRIVILEGES ON nc_2018.* TO 'ncuser'@'localhost' IDENTIFIED BY 'ncpass';"

Setup Nextcloud

Point your browser to your server and finish the setup of NextCloud.


cd /var/www/nextcloud
sudo -u www-data php occ  maintenance:install --database "mysql" --database-name nc_2018 --database-user ncuser --database-pass ROOT_PASSWORD --admin-user admin --admin-pass password

You should seeā€¦.

Nextcloud is not installed - only a limited number of commands are available

Setup Redis Cache

apt-get install redis-server php-redis -y
systemctl start redis-server
systemctl enable redis-server
php --ri redis
 See if redis is enabled.
systemctl restart apache2
nano /var/www/nextcloud/config/config.php

Add the below before the last );

'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
     'host' => 'localhost',
     'port' => 6379,

Change PHP Memory Limit

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

ctrl+w and find memory_limit

Change memory_limit=512M to at least %25 of your total ram.

systemctl restart apache2

Enable PHP Opcache

nano /etc/php/7.0/apache2/php.ini
ctrl+w and find [opcache]

put the below directly after [opcache]

systemctl restart apache2

updating nextcloud

occ command for updating NextCloud

sudo -u www-data php occ upgrade


Keepweb fix

nano /var/www/nextcloud/config/mimetypemapping.json
    "kdbx": ["x-application/kdbx"]
sudo -u www-data php /var/www/nextcloud/occ maintenance:mimetype:update-js

Slow login?

Add the following to the config file.

nano /var/www/nextcloud/config/config.php
'auth.bruteforce.protection.enabled' => false,

Forgot your password?

Login to the server using terminal and run the following. Change admin to the account name you want to change.

sudo -u www-data php /var/www/nextcloud/occ user:resetpassword admin