Nextcloud is a suite of client-server software for creating and using file hosting services. It is functionally similar to Dropbox, although Nextcloud is free and open-source, allowing anyone to install and operate it on a private server.
In contrast to proprietary services like Dropbox, the open architecture allows adding functionality to the server in the form of applications and enables users to have full control of their data.
Before to start, we update our system on the last version of these packages.
apt update && apt full-upgrade
First step we install all depedencies needed by
apt install nginx php-common php-fpm php-gd php-imagick php-intl php-mbstring php-mcrypt php-mysql php-xml php-zip php7.0-curl php-redis mariadb-client mariadb-server certbot nginx
Set up a database for nextcloud.
create database mycloud; create user "$user"@"localhost" identified by "$pass"; grant all privileges on mycloud.* to "$user"@"localhost"; flush privileges;
Set up nginx
Before configuring your nginx server, you must create your SSL certificate by following this procedure let's encrypt.
When it's done we edit
/etc/nginx/sites-enabled/your.domain.com to configure nginx.
Get the installer
Get the tarball of the actual nextcloud version.
Uncompress and copy the instaler into the web directory.
unzip nextcloud-14.0.4.zip cp -r nextcloud/* /var/www/html/
We fix the permissions.
chown -R www-data:www-data /var/www/html
We'll restart nginx , open your nextcloud url into your web navigator and follow the steps to install it.
Uncomment the environment and log files related lines in
access.log = /var/log/$pool.access.log env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
Adjust the numbers of procces started by php-fpm.
pm = dynamic pm.max_children = 120 pm.start_servers = 12 pm.min_spare_servers = 6 pm.max_spare_servers = 18
Add the following content in
[mysql] mysql.allow_local_infile=On mysql.allow_persistent=On mysql.cache_size=2000 mysql.max_persistent=-1 mysql.max_links=-1 mysql.connect_timeout=60 mysql.trace_mode=Off
You can significantly improve your Nextcloud server performance with memory caching, where frequently-requested objects are stored in memory for faster retrieval.
There are two types of caches to use: a PHP opcode cache, which is commonly called opcache, and data caching for your Web server.
If you do not install and enable a local memcache you will see a warning on your Nextcloud admin page. A memcache is not required and you may safely ignore the warning if you prefer.
To install the apcu module & redis server follow these steps.
apt install php-apcu redis-server
We must set up opcache in
opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=256 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.revalidate_freq=1 opcache.save_comments=1
If opcache not working, copy the properties aftermentioned into
Configure memory caching in the
config.php of your nextcloud.
'memcache.locking' => '\OC\Memcache\Redis', 'memcache.local' => '\OC\Memcache\APCu', 'redis' => array( 'host' => 'localhost', 'port' => 6379, ),
Defining background jobs
A system like Nextcloud sometimes requires tasks to be done on a regular basis without the need for user interaction or hindering Nextcloud performance. For that purpose, as a system administrator, you can define background jobs (for example, database clean-ups) which are executed without any need for user interaction.
These jobs are typically referred to as cron jobs. Cron jobs are commands or shell-based scripts that are scheduled to run periodically at fixed times, dates, or intervals.
cron.php is an Nextcloud internal process that runs such background jobs on demand.
Nextcloud apps register actions with
cron.php automatically to take care of typical housekeeping operations, such as garbage collecting of temporary files or checking for newly updated files using
filescan() for externally mounted file systems.
So we adapt the behavior of NC by following these steps.
crontab -u www-data -e
And add the following line
*/15 * * * * php -f /var/www/html/cron.php
To verify if cronjob works
crontab -u www-data -l
Configure nextcloud log level in
'log_type' => 'owncloud', 'log_file' => 'nextcloud.log', 'loglevel' => '3', 'logdateformat' => 'F d, Y H:i:s',
To improve performance we adapt the settings of our mysql server in
# this is only for the mysqld standalone daemon [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 127.0.0.1 # # * Fine Tuning # key_buffer_size = 128M max_allowed_packet = 16M thread_stack = 256K thread_cache_size = 20 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam_recover_options = BACKUP max_connections = 250 table_cache = 64 thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 64M query_cache_size = 128M ## query_cache_type = 1 query_cache_min_res_unit = 2k tmp_table_size= 64M max_heap_table_size= 64M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error log - should be very few entries. # log_error = /var/log/mysql/error.log # # Enable the slow query log to see queries with especially long duration #slow_query_log_file = /var/log/mysql/mariadb-slow.log #long_query_time = 10 #log_slow_rate_limit = 1000 #log_slow_verbosity = query_plan #log-queries-not-using-indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = exclude_database_name # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! innodb_buffer_pool_size = 1G innodb_log_buffer_size = 256 innodb_flush_method = O_DIRECT innodb_flush_log_at_trx_commit=2 innodb_buffer_pool_instances = 1 ## innodb_max_dirty_pages_pct = 90 innodb_large_prefix=on innodb_file_format=barracuda innodb_file_per_table = 1 innodb_buffer_pool_instances = 1 # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates you can use for example the GUI tool "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem # # Accept only connections using the latest and most secure TLS protocol version. # ..when MariaDB is compiled with OpenSSL: # ssl-cipher=TLSv1.2 # ..when MariaDB is compiled with YaSSL (default in Debian): # ssl=on # # * Character sets # # MySQL/MariaDB default is Latin1, but in Debian we rather default to the full # utf8 4-byte character set. See also client.cnf # character-set-server = utf8mb4 collation-server = utf8mb4_general_ci
If you want to go far you can visit the official documentation of nextcloud here.