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

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 ##

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

Download Nextcloud 12

cd /var/www
mkdir nextcloud
cd nextcloud
wget https://download.nextcloud.com/server/installer/setup-nextcloud.php
chown -R www-data:www-data /var/www/nextcloud
chmod -R g+s /var/www/nextcloud

Install MySQL server

apt-get install mariadb-server
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 nextcloud18 --database-user root --database-pass ROOT_PASSWORD --admin-user admin --admin-pass password

Setup Redis Cache

apt-get install redis-server
systemctl start redis-server
systemctl enable redis-server
apt install php-redis
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,

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,