Install the pre-requis

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

Create The Database

Nextcloud works with Squlite3, MySQL, and PostgreSQL. Since this guide is based on a LAMP stack, it’s going to use MySQL/MariaDB. You can use PostreSQL, if you want. Sqlite3 is not recommended. Start off by signing in as your database’s root user.

# mysql -u root -p

Once in MySQL, you can create a new cloud database.

CREATE DATABASE cloud;

Next, create a user. You can use an existing user and skip this step, if you would prefer.

CREATE USER 'clouduser'@'localhost' IDENTIFIED BY 'yourpassword';

Finally, grant that new user all privileges on the cloud database.

GRANT ALL ON cloud.* TO 'clouduser'@'localhost';

Now, just flush the privileges and exit.

FLUSH PRIVILEGES;
exit;

 

Get Nextcloud

With everything else set up and ready to go, you can now download Nextcloud and install it. Nextcloud is provided as a zip or tarball instead of a package. That’s actually okay. It’s easier to install and manage that way.

Rather than going the graphical route, just cd to your Downloads folder and get Nextcloud with wget You can go graphical, but this guide isn’t going to cover it.

$ cd ~/Downloads
$ wget https://download.nextcloud.com/server/releases/nextcloud-12.0.1.zip

Now, just unzip.

$ unzip nextcloud-12.0.1.zip

It’s finally time to stick that newly unzipped Nextcloud folder in your web root directory. You can copy it there as root.

# mv nextcloud cloud
# cp -r /home/user/Downloads/cloud /var/www/cloud

The folder permissions won’t be ideal for use. You need to make Apache’s user the owner of nextcloud in order for it to be able to write your files to the directory. On Debian, that user is www-data.

chown -R www-data:www-data /var/www/cloud

Create the VirtualHost

Nous allons créer un VirtualHost via la commande suivante :

# vi /etc/apache2/sites-available/cloud.conf

Et on y enregistre :

<VirtualHost *:80>
     ServerAdmin postmaster@moncloud.xxx
     ServerName cloud.moncloud.xxx
     DocumentRoot /var/www/cloud/
     <Directory /var/www/cloud/>
          Options +FollowSymLinks
          AllowOverride All
          <IfModule mod_dav.c>
               Dav off
          </IfModule>
          SetEnv HOME /var/www/cloud/
          SetEnv HTTP_HOME /var/www/cloud/
     </Directory>
     ErrorLog /var/log/apache2/cloud/error.log
     LogLevel warn
     CustomLog /var/log/apache2/cloud/access.log combined
     ServerSignature Off
</VirtualHost>

Maintenant que l’on a configuré, le virtualhost, nous devons l’activer. Pour cela nous tapons la commande suivante :

# a2ensite cloud

On va créer le répertoire qui contiendra les fichiers de log de Nextcloud via la commande suivante :

# mkdir /var/log/apache2/cloud/

Nous devons créer le répertoire data afin de procéder à la configuration de Nextcloud :

# mkdir /var/www/cloud/data

Nous allons modifier le propriétaire sur les répertoires et fichiers pour le bon fonctionnement de Nextcloud :

# chown -R www-data:www-data /var/www/cloud/apps/
# chown -R www-data:www-data /var/www/cloud/config/
# chown -R www-data:www-data /var/www/cloud/data/
# chown -R www-data:www-data /var/www/cloud/themes/
# chown -R www-data:www-data /var/www/cloud/updater/
# chown root:www-data /var/www/cloud/.htaccess

On vérifie que l’on n’a pas fait d’erreur lors de la configuration de notre VirtualHost via la commande suivant :

# apachectl configtest

Si en retour on obtient un « Syntax OK », on rend le VirtualHost créé disponible via la commande suivante :

# systemctl restart apache2.service

Install Let’s encrypt

sudo apt install letsencrypt python-certbot-apache

sudo letsencrypt --apache --agree-tos --email your-email-address -d office.mycloudnetwork.com

Now we need to ensure that HTTP reverse proxy is set up:

sudo a2enmod proxy proxy_wstunnel proxy_http ssl

Add in the SSL Vhosts configuration

<IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>

Cron

Using the operating system cron feature is the preferred method for executing regular tasks. This method enables the execution of scheduled jobs without the inherent limitations the Web server might have.

To run a cron job on a *nix system, every 15 minutes, under the default Web server user (often, www-data or wwwrun), you must set up the following cron job to call the cron.php script:

# crontab -u www-data -e
*/15  *  *  *  * php -f /var/www/cloud/cron.php

You can verify if the cron job has been added and scheduled by executing:

# crontab -u www-data -l
*/15  *  *  *  * php -f /var/www/cloud/cron.php

Memcache

add this line to your config.php file:

'memcache.local' => '\OC\Memcache\APCu',