computing:nextcloud [Haack's Wiki]

User Tools

Site Tools


  • Nextcloud
  • Jonathan Haack
  • Haack's Networking


This tutorial is for a Nextcloud instance on Debian GNU/Linux. For why one would want such a thing, read: The issue with Public Cloud. This tutorial assumes you have LAMP/FEMP and TLS encryption for your site already, and if not, go here:Apache Survivial. So we begin:

sudo apt install apache2-utils php-xml php-curl php-gd php-cgi php-cli php-zip php-mysql php-mbstring php-intl php-fpm php-apcu php-gmp php-imagick php-bcmath wget unzip libapache2-mod-php

Or …

sudo apt-get install php-{xml,curl,gd,cgi,zip,mysql,mbstring,intl,fpm,apcu,gmp,imagick,bcmath}

Once these are installed, make sure you can enable them and that you have no errors in your configurations:

sudo a2enmod ssl
sudo a2enmod headers
sudo a2enmod proxy_fcgi 
sudo a2enmod setenvif 
sudo a2enconf php7.3-fpm 
sudo a2enconf php7.3-cgi 
sudo sudo apache2ctl configtest

There may be some others for your use case. Assuming you left the webroot in /var/www/html, the next step is downloading nextcloud, moving it to webroot, and setting up proper permissions:

cd /var/www/
sudo wget
sudo unzip
sudo rm
sudo rm public_html
sudo mv nextcloud public_html
cd public_html
sudo chown www-data:www-data -R /var/www/ 
sudo mkdir /var/www/
sudo chown www-data:www-data -R /var/www/
sudo chmod 750 -R /var/www/
sudo mkdir -p /var/www/
sudo chmod 0640 *.php *.txt *.html AUTHORS COPYING
sudo chmod 0750 {3rdparty,apps,config,core,data,lib,ocm-provider,ocs,ocs-provider,resources,settings,themes,updater} 
sudo chown root:www-data /var/www/
sudo chown www-data:www-data {apps,config,data,themes,updater}  
sudo chmod 0755 /var/www/
sudo chmod 0644 /var/www/
sudo chown root:www-data /var/www/
sudo systemctl restart mysql
sudo systemctl restart mysqld
sudo systemctl restart apache2
sudo systemctl restart php7.3-fpm.service

Prepare MariaDB server for 4-byte characters prior to creating database:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Once inside that file, copy these configurations under the [mysqld] block and restart the service:


It is now time to set up your database:

sudo mysql -u root -p

Enter your password for sudo and then for MySQL. Once inside MySQL command mode, you will have a “>” prompt. You will need to create a database for Nextcloud, a database user for Nextcloud, give that user permissions over the database as follows:

CREATE USER nextclouduser@localhost IDENTIFIED BY 'put-password-here';
GRANT ALL PRIVILEGES ON nextcloud.* to nextclouduser@localhost IDENTIFIED BY 'put-password-here';

Let's first restart the web server, php, and mysql:

sudo systemctl restart mysql
sudo systemctl restart apache2
sudo systemctl restart php7.3-fpm.service

Now, visit in your browser and then specify the following configuration options:

  • create new user name: adminname
  • create new user pass: password
  • specify data folder: /var/www/nextclouddata
  • database user name: nextclouduser
  • database name: nextcloud
  • database location: localhost

The first thing to do is to navigate to Settings, Overview. Nextcloud has a built in system recommendation tool that will specify remaining set up optimizations, etc. The first one I needed was to optimize opcache settings, so I opened the opcache file to adjust its settings:

sudo nano /etc/php/7.0/cli/conf.d/10-opcache.ini

I entered the following settings, currently recommended by Nextcloud. You should always check/verify this before copying and pasting:


Find the `memory_limit = ` line and change the value to 1G. Sometimes, the memory limit error persists, and you may need to also edit .user.ini inside the nextcloud directory with the following parameters:

cd /var/www/html
sudo nano .user.ini

Add these three lines to the configuration file there (the first two are optional for the memory limit problem, but super helpful for regular use):


You may also need to adjust the memory limit for php by to 1G in these locations also:

sudo nano /etc/php/7.3/cli/php.ini
sudo nano /etc/php/7.3/apache2/php.ini

Next, you may get a Header error for your SSL configuration. To adjust that, either adjust your <VirtualHost *:443> as follows:

sudo nano /etc/apache2/sites-enabled/default-ssl.conf

Add the following Header parameter with the other parameters, or anywhere before the </IfModule> marker:

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

Lastly, Nextcloud uses an .htaccess file inside the webroot, and in order for that configuration to be utilized, Overrides must be enabled:

sudo nano /etc/apache2/apache2.conf

Scroll down to the web server root section and adjust it to read as follows:

<Directory />
      Options FollowSymLinks
      AllowOverride All
      Require all denied

Also, your cal and card dav need redirects for some reasons a bit unclear to me, so adjust your ssl.conf as follows:

sudo nano /etc/apache2/sites-enabled/default-ssl.conf

Place the following redirects after <VirtualHost> and before any <IfModules>. If you are using a directory called nextcloud for your instance, change the path to reflect that location instead of the web-root as my configuration utilizes:

Redirect 301 /.well-known/carddav /remote.php/dav
Redirect 301 /.well-known/caldav /remote.php/dav

Okay, that is the majority of fundamental configuration details required to have it running smoothly. Here are a few more optional configurations. The first of those is enabling memcache:

sudo apt install php7.0-apcu

After installing the package, make sure to adjust your config.php as follows:

sudo nano /var/www/html/config/config.php

Add the following line to the config file so that Nextcloud knows which program is handling your caching:

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

Lastly, I ran into an error that stated that the database I created above was not set to handle “13 big integers” which are used to “store identifiers and auto-increment keys in the database.” First, disable the apache and php services and take your instance offline:

sudo systemctl stop apache2
sudo systemctl stop php7.0-fpm

Now that your services are stopped, you can safely run Netcloud's “occ” program which will identify the tables that require updating and prompt you to adjust them (> v.12). They do warn this can take some time, so I recommend doing this on your fresh instance before you have accumulated lots of data (if not, email me as I did find the solution for manually altering the db and tables):

sudo -u www-data php occ db:convert-filecache-bigint

Follow the prompts, and then run it again once it completes in order to verify that “All tables are already up to date!” Ok …, almost done, but some apps require a cron job to update cron.php instead of ajax running, so in that case

sudo crontab -e -u www-data

<*/5  *  *  *  * php -f /var/www/ > /dev/null 2>&1>

Ok, now you can run the News app and others … phew! Fine tuning server

sudo nano /etc/php/7.2/fpm/pool.d/www.conf

For a 4GB server:

pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18

For a 1GB server, use defaults:

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Time to restart services …

sudo systemctl restart mysql

sudo systemctl restart mysqld
sudo systemctl restart apache2
sudo systemctl restart php7.0-fpm.service
sudo reboot

To reset permissions after an update:

cd /var/www/
sudo chown www-data:www-data -R /var/www/* 
sudo chown www-data:www-data -R /var/www/
sudo chmod 0640 *.php *.txt *.html AUTHORS COPYING
sudo chmod 0750 {3rdparty,apps,config,core,data,lib,ocm-provider,ocs,ocs-provider,resources,settings,themes,updater} 
sudo chown root:www-data /var/www/
sudo chown www-data:www-data {apps,config,data,themes,updater}  
sudo chmod 0755 /var/www/
sudo chmod 0644 /var/www/
sudo chown root:www-data /var/www/
sudo systemctl restart mysql
sudo systemctl restart mysqld
sudo systemctl restart apache2pm = dynamic
sudo systemctl restart php7.3-fpm.service

Need to manually move files from an old NAS or elsewhere to Nextcloud:

sudo -u www-data php /var/www/html/nextcloud/occ files:scan --all
sudo -u www-data php occ files:scan --path=/oemb1905/files/Movies/Television/Twilight/
sudo -u www-data php occ files:scan --path=/heather/files/
sudo -u www-data php occ files:scan --help

Okay, and for Nextcloud Talk configuration, you need a Turn server for video chat to work:

sudo apt install coturn
sudo nano /etc/turnserver.conf
openssl rand -hex 32

The Nextcloud guide recommends these minimum values:

static-auth-secret=<use hex key from last step above>
systemctl restart coturn

After doing this, go to Nextcloud / Settings / Talk, and enter localhost:3478 for the TURN server, and put the same hex key from above in for the secret key field. Restart all your services and test - should work. Some apps, like the Community Document Server, take too long to download for the default php settings. In this case, extend the execution time:

sudo nano /etc/php/7.3/cli/php.ini
sudo nano /etc/php/7.3/apache2/php.ini
sudo nano /etc/php/7.3/fpm/php.ini
sudo nano /var/www/html/.user.ini
max_excution_time = 240 (for all of them)

Now, try to down the server again and it should not time out. Missing indices error? try this …

sudo -u www-data php occ db:add-missing-indices

Brute force won't permit log in

select database;
delete FROM oc_bruteforce_attempts;
flush privileges;

Log in normally after that. My latest command is for Stubborn files that won't delete from trashbin:

sudo -u www-data php occ trashbin:cleanup --all-users

Phone region issue

sudo nano /var/www/nextcloud/config/config.php
'default_phone_region' => 'GB',

New weird error about svg support for phpimagick

sudo apt install libmagickcore-6.q16-6-extra

New version of apcu pitches error and causes cron to spam you every 5 minutes

sudo nano /etc/php/7.x/mods-available/apcu.ini

Upgrade & Update:

cd /var/www/html/nextcloud/
sudo -u www-data php occ upgrade
cd /var/www/html/nextcloud/updater/
sudo -u www-data php updater.phar

oemb1905 2022/11/06 00:40

computing/nextcloud.txt · Last modified: 2023/04/10 14:08 by oemb1905