L'installation de nexctloud s'est révélée fastidieuse, la documentation étant un jeu de piste qui ne respecte pas un ordre chronologique surtout dans le cas d'une utilisation avec nginx et postgresql.
Voici donc un mémo pour ne pas perdre de temps.
Pour vérifier vos versions :
$ lsb_release -a
$ nginx -v
$ psql --version
$ sudo apt update && sudo apt upgrade
Ci dessous la liste des paquets php nécessaires. En particulier :
Les autres paquets sont ceux de la documentation officielle/installation
$ sudo apt install php-gd php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick imagemagick php-zip php-bz2 php-fpm php-pgsql php-apcu
$ sudo -u www-data php --define apc.enable_cli=1
$ sudo systemctl status php7.4-fpm
On peut voir dans /etc/php/7.4/fpm/conf.d les modules activés (normalement ils le sont par défaut après installation).
$ sudo phpenmod pgsql
$ sudo systemctl restart php7.4-fpm.service
$ sudo systemctl restart php7.4-fpm.service
Positionnez vous dans /var/www
$ sudo wget https://download.nextcloud.com/server/releases/latest.tar.bz2
$ sudo tar -xjvf latest.tar.bz2
$ sudo chown -R www-data:www-data /var/www/nextcloud
J'ai choisi d'encoder la base en UTF8.
Remplacez les valeurs %DbName%, %Username% et %Password%.
Pensez à conserver ses valeurs pour la suite.
Ne pas oublier la timezone si vous n'êtes pas en France.
Deux solutions, en ligne de commande ou via mon script de création de base de donnée postgresql (UTF8/read committed/timezone Paris)
$ sudo -u postgres psql
CREATE DATABASE %DbName%;
CREATE USER '%Username%' WITH PASSWORD '%Password%';
ALTER ROLE %Username% SET client_encoding TO 'utf8';
ALTER ROLE %Username% SET default_transaction_isolation TO 'read committed';
ALTER ROLE %Username% SET timezone TO 'Europe/Paris';
GRANT ALL PRIVILEGES ON DATABASE %DbName% TO %Username%;
$ chmod +x filename.sh
$ sudo ./newdatabase.sh
$ cd /opt
$ sudo mkdir -p nextcloud/data
$ sudo chown -R www-data:www-data /opt/nextcloud
$ cd /var/www/nextcloud
$ sudo -u www-data php occ maintenance:install --database "pgsql" --database-name "%DbName%" --database-user "%Username%" --database-pass "%Password%" --admin-user "%NextcloudAdminUserName%" --admin-pass "%NextcloudAdminPassword%" --data-dir "/opt/nextcloud/data" --verbose
/var/www/nextcloud/config/config.php car il ne sera pas recréé par un nouvel appel.
$ sudo touch /etc/nginx/sites-availables/nextcloud
$ sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled
Éditez le fichier ```/etc/nginx/sites-available/nextcloud
Voici la configuration (adaptez les %valeurs%).
Le premier # CUSTOM PARAM evite un waring de sécurité et le deuxième configure 2Go de RAM pour le serveur (512MO mini recommandé)
server {
server_name %maybeyoursubdomain.yourdomain.topleveldomain%;
# Add headers to serve security related headers
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
# CUSTOM PARAM
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
#I found this header is needed on Ubuntu, but not on Arch Linux.
add_header X-Frame-Options "SAMEORIGIN";
# Path to the root of your installation
root /var/www/nextcloud/;
access_log /var/log/nginx/nextcloud.access;
error_log /var/log/nginx/nextcloud.error;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
# The following rule is only needed for the Social app.
# Uncomment it if you're planning to use this app.
rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
location = /.well-known/webfinger {
return 301 /index.php$uri;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
location ~ /.well-known/acme-challenge {
allow all;
}
location ^~ /.well-known {
return 301 /index.php$uri;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
try_files $fastcgi_script_name =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
#CUSTOM PARAM
fastcgi_param PHP_VALUE "memory_limit = 2048M";
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
Si vous avez l’œil vous avez remarqué qu'il manque des configurations.
certbot va s'en charger en activant le ssl (https)
Si vous ne l'avez pas déjà voici comment installer et utiliser certbot pour nginx sous ubuntu server :
Sinon la commande est simple :
$ sudo certbot --nginx
$ cd /var/www/nextcloud/config/
Le reste a déjà été rempli automatiquement.
<?php
$CONFIG = array (
'passwordsalt' => 'dejaremplinepastoucher',
'secret' => 'dejaremplinepastoucher',
'trusted_domains' =>
array (
0 => '%YOURSERVERIP%',
1 => '%maybeyoursubdomain.yourdomain.topleveldomain%',
),
'datadirectory' => '/var/www/nextcloud/data',
'dbtype' => 'pgsql',
'version' => '24.0.5.1',
//'overwrite.cli.url' => 'http://localhost',
'overwrite.cli.url' => 'https://%maybeyoursubdomain.yourdomain.topleveldomain%',
'dbname' => '%DBNAME%',
'dbhost' => 'localhost',
'dbport' => '',
'dbtableprefix' => 'oc_',
'dbuser' => '%DBUSER%',
'dbpassword' => '%DBUSERPASSWORD%',
'installed' => true,
'instanceid' => 'dejaremplipastoucher',
'filelocking.enabled' => true,
'memcache.distributed' => '\OC\Memcache\Redis',
<------>'redis' => array(
<------> 'host' => 'localhost',
<------> 'port' => 6379,
<------>),
);
Bien sur cela est extrêmement lent et pas recommandé (mais par défaut...lol)
$ crontab -u www-data -e
$ */5 * * * * php -f /var/www/nextcloud/cron.php
sudo -u www-data php /var/www/nextcloud/occ files:scan --all
Je vous déconseille d'utiliser au quotidien le compte admin de nextcloud : logguez vous en admin avec les %user% et %password% choisi lors de l'appel à occ et créez vous un user.
dans les réglages en mode admin spécifiez que vous utilisez cron et non ajax (une fois cron utilisé le serveur n'est pas au courant et dit qu'il y a un problème mais le cron s’exécute bien)
Il y a plein d'app à ajouter à nextcloud via l'interface (todolist, calendrier, etc)
Si quelque chose n'est pas pris en compte vous pouvez utiliser la commande maintenance:repair de occ
amusez vous bien !