How to install Nextcloud (Nginx + PostgreSQL) This note was created on 2020-01-19 This note was last edited on 2023-02-01 Nextcloud offers the industry-leading, on-premises content collaboration platform. Its technology combines the convenience and ease of use of consumer-grade solutions like Dropbox and Google Drive with the security, privacy and control business needs. Source code available at [GitHub](https://github.com/nextcloud/server). === Firewall configuration === 1. Open ports 80 and 443: # firewall-cmd --permanent --zone=public --add-port=80/tcp # firewall-cmd --permanent --zone=public --add-port=443/tcp # firewall-cmd --reload 2. Make sure that required ports are open: # firewall-cmd --permanent --zone=public --list-ports === Installation === 1. Install Nginx: # apt install nginx 2. Install required PHP modules: # apt install php7.4 php7.4-fpm php7.4-common php7.4-pgsql php7.4-cli php7.4-gd php7.4-json php7.4-curl php7.4-zip php7.4-xml php7.4-mbstring php7.4-bz2 php7.4-intl php7.4-bcmath php7.4-gmp php-imagick php7.4-opcache php7.4-readline 3. Install "certbot": # apt install certbot python3-certbot-nginx 4. Install PostgreSQL: # apt install postgresql postgresql-contrib 5. Install "unzip": # apt install unzip 6. Use "wget" to download Nextcloud: $ wget https://download.nextcloud.com/server/releases/nextcloud-20.0.5.zip === Main configuration === 1. Configure PostgreSQL: - Connect to PostgreSQL with: # sudo -u postgres psql - Create user and database for Nextcloud: > CREATE USER nextcloud WITH PASSWORD 'your_password'; > CREATE DATABASE nextcloud TEMPLATE template0 ENCODING 'UNICODE'; > ALTER DATABASE nextcloud OWNER TO nextcloud; > GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud; > \q Note: don't forget to set your own password instead "your_password". 2. Unzip archive with Nextcloud: # unzip nextcloud-20.0.5.zip -d /usr/share/nginx/ 3. Change owner for Nextcloud directory: # chown www-data:www-data /usr/share/nginx/nextcloud/ -R 4. Create folder for Nextcloud data: # mkdir /usr/share/nginx/nextcloud-data 5. Change owner for Nextcloud data directory: # chown www-data:www-data /usr/share/nginx/nextcloud-data -R 6. Remove default Nginx website: # mv /etc/nginx/sites-enabled/default /home/$USER 7. Create Nginx configuration file for Nextcloud: # nano /etc/nginx/conf.d/nextcloud.conf You can find an example file here: https://gitlab.com/-/snippets/2063273 Don't forget to change the domain and PHP version. 8. Check configuration file for errors: # nginx -t 9. Enable and start Nginx: # systemctl enable --now nginx 10. Enable and start php-fpm: # systemctl enable --now php7.4-fpm 11. Order an SSL certificate for your domain: # certbot --nginx --agree-tos --redirect --staple-ocsp --email your-email-address -d nextcloud.your-domain.com 12. Update Nginx configuration file ("/etc/nginx/conf.d/nextcloud.conf") by adding the following: ~~~ add_header Strict-Transport-Security "max-age=31536000" always; listen 443 ssl http2; # managed by Certbot ~~~ 13. Go to "nextcloud.your-domain.com" and finish the configuration. === Additional configuration === - Increase PHP memory limit by editing "/etc/php/7.4/fpm/php.ini": ~~~ memory_limit = 512M ~~~ Note: don't foreget to restart php-fpm by running "sudo systemctl reload php7.4-fpm". - Increase PHP execution time by editing "/etc/php/7.4/fpm/php.ini": ~~~ max execution time 256 ~~~ Note: don't foreget to restart php-fpm by running "sudo systemctl reload php7.4-fpm". - Configure PHP to properly query system environment variables by adding the following line to "/etc/php/7.4/fpm/pool.d/www.conf": ~~~ clear_env = no ~~~ Note: don't foreget to restart php-fpm by running "sudo systemctl reload php7.4-fpm". - Increase upload file size limit: 1. Add or change the following line in "/etc/nginx/conf.d/nextcloud.conf": ~~~ client_max_body_size 1024M; ~~~ 2. Change "upload_max_filesize" parameter to "1024M" in "/etc/php/7.4/fpm/php.ini". 3. Restart Nginx and php-fpm: # systemctl reload nginx # systemctl reload php7.4-fpm - Configure Redis: 1. Install Redis and its PHP module: # apt install redis-server php-redis 2. Add the following code to "/usr/share/nginx/nextcloud/config/config.php" above the ");" line: ~~~ 'memcache.distributed' => '\OC\Memcache\Redis', 'memcache.local' => '\OC\Memcache\Redis', 'memcache.locking' => '\OC\Memcache\Redis', 'redis' => array( 'host' => 'localhost', 'port' => 6379, ), ~~~ 3. Restart Nginx and php-fpm: # systemctl restart nginx php7.4-fpm - Use Cron instead of AJAX jobs: 1. Open crontab file: # crontab -u www-data -e 2. Add the following line and save the file: ~~~ */5 * * * * php -f /usr/share/nginx/nextcloud/cron.php ~~~ - Hide Nginx version by changing the following line in "/etc/nginx/nginx.conf": ~~~ server_tokens off; ~~~ - Hide "Get your own free account" link by adding the wollowing line to "/usr/share/nginx/nextcloud/config/config.php": ~~~ 'simpleSignUpLink.shown' => false, ~~~ === Read more === Don't forget to check out the official documentation: https://docs.nextcloud.com/server/20/admin_manual/index.html