Install Nextcloud on Ubuntu

This manual ist tested with Ubuntu 16.04 and is valid for Nextcloud 11, 12 and 13.

How to find the active php.ini

sudo -u www-data php -i | grep php\.ini

Check which PHP modules are loaded

php -m

Update server

apt-get update
apt-get upgrade
apt-get dist-upgrade

Install packages

PHP7, APCu for local caching and Redis for file locking.

apt-get install php-gd php-json php-mysql php-curl php-intl php-mcrypt
apt-get install php-imagick php-zip php-dom php-dompdf php-xml php-mbstring
apt-get install php7.0-xml php7.0-fpm php7.0-mysql php7.0-common php7.0-gd
apt-get install php7.0-json php7.0-cli php7.0-curl php7.0-zip 
apt-get install php7.0-mbstring libapache2-mod-php7.0
apt-get install wget unzip php-apcu redis-server php-redis

Modify php.ini

vi /etc/php.ini
memory_limit = 512M
date.timezone = Europe/Vienna
upload_max_filesize = 200M
post_max_size = 200M
service apache2 restart

Create database and database user

mysql -u root -p
CREATE DATABASE nextclouddb;
GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
\q

Download Nextcloud

cd /var/www
wget https://download.nextcloud.com/server/releases/nextcloud-11.0.0.zip
unzip nextcloud-11.0.0.zip
chown -R www-data:www-data nextcloud

Configure Apache

vi /etc/apache2/apache.conf
<Directory /var/www/>
    Options Indexes FollowSymLinks
    #AllowOverride None
    AllowOverride All
    Require all granted
</Directory>
vi /etc/apache2/conf-enabled/ssl-params.conf
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCompression off
SSLSessionTickets Off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"
vi /etc/apache2/sites-enabled/100-domain.xx.vhost
<IfModule mod_headers.c>
    Header always add Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
vi /etc/apache2/conf-available/nextcloud.conf
Alias /nextcloud "/var/www/nextcloud/"
<Directory /var/www/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
    
    <IfModule mod_dav.c>
        Dav off
    </IfModule>
    
    SetEnv HOME /var/www/nextcloud
    SetEnv HTTP_HOME /var/www/nextcloud
</Directory>

Enable conf & mods

a2enconf nextcloud
a2enmod php7.0 rewrite headers env dir mime setenvif ssl

Restart Apache

service apache2 restart

Start Nextcloud web installer

mkdir /var/ncdata
chown www-data:www-data /var/ncdata

Open your browser and navigate to https://domain.xx/nextcloud

Now Nextcloud is ready to use and it’s time to configure Nextcloud.

Add cronjob

crontab -u www-data -e
*/15  *  *  *  * php -f /var/www/nextcloud/cron.php
crontab -u www-data -l

Configure Redis & APCu

redis-server -v
systemctl status redis
systemctl enable redis    # enable autostart

php --ri redis            # check redis support in php
phpenmod redis
vi /var/www/nextcloud/config/config.php
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'memcache.local' => '\\OC\\Memcache\\APCu',
'redis' => array(
     'host' => 'localhost',
     'port' => 6379,
 ),
vi /etc/php/7.0/mods-available/apcu.ini
apc.enable_cli=1
service apache2 restart

Add Redis to services

vi /etc/services
redis           6379/tcp
netstat -a | grep redis
tcp    0    0 localhost:redis         *:*                  LISTEN

Configure PHP OPcache

vi /etc/php.ini
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1
service apache2 restart

Clean URLs

How to remove index.php of URLs.

vi /var/www/nextcloud/config/config.php
'htaccess.RewriteBase' => '/nextcloud',     # path to NC installation
sudo -u www-data php /var/www/nextcloud/occ maintenance:update:htaccess

Now index.php has disappeared of the urls.