This may help you with an installation of NextCloud.
This will most likely also work to install version 22.
During this writing (10-10-2020) I am reinstalling NextCloud on the Hover. Reinstalling NextCloud is not that bad but first download calendar, tasks and contacts from your existing NextCloud for all users. Very important. It is necessary to do this on the server because different phones are different, VCF 2.1 and 3.0 are common which gives transfer issues sometimes.
Furthermore, the backup of the installation disk of the original installation is very useful if you no longer know what changes you made to configuration files. I am so happy I do that every night automatically.
User files are less troublesome because they are also on the devices. Rename the NextCloud directory so that the files can be reloaded afterwards.
Fresh Install of Ubuntu 20.04.1
Installation of this Ubuntu Server can be found on the Internet. Donât install anything extra besides SSH to make working on the server easier.
It appears that the new version of grub is causing spin-up of the drives to test for other operating systems. Because we have a headless server without other operating systems we do not require this feature. First find out which version of grub you are using.
grub-install --version
If it is above 2.0 zero you can switch of the checking of drives by editing:
sudo nano /etc/default/grub
Add the following lines:
# Don't test drives for operating systems
GRUB_DISABLE_OS_PROBER=true
First install WebMin
WebMin is a graphical user interface for your server. It allows you to do a lot of things without the command line. Webmin is easy to be able to adjust files and to carry out configurations remotely and easily. The file browser is really handy.
Edit the following file:
sudo nano /etc/apt/sources.list
Add the following line:
deb https://download.webmin.com/download/repository sarge contrib
You should also fetch and install my GPG key with which the repository is signed, with the commands:
cd /root
sudo wget https://download.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc
On Debian 11 and Ubuntu 22.04 or higher, the commands are
cd /root
sudo wget https://download.webmin.com/jcameron-key.asc
sudo cat jcameron-key.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/jcameron-key.gpg
You will now be able to install with the commands :
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install webmin
All dependencies should be resolved automatically.
Normally WebMin expects you to log in securely. Because we only use WebMin behind the router, extra security is not necessary. Therefore, change the required WebMin SSL to No. Edit:
sudo nano /etc/webmin/miniserv.conf
Change the line in "ssl=1"in âssl=0â and save the file.
Then restart WebMin:
sudo /etc/init.d/webmin restart
Now you can reach WebMin with http://yourserverip:10000 in your browser.
More changes to the configuration of Webmin:
Prevent WebMin from blocking hard disk spindown. Go to â Webmin-> Configuration â Collect Background Statuses â Collect System Status in Background. There you will find that this has a value of 5 minutes. Disable this option as this will prevent some hard disks from being stopped.
Automatic update of the system time can be set in WebMin under Hardware / System time.
Spindown of harddisks
Editing the hdparm file suddenly did not work any more. Why, I have no idea. I switched to using hd-idle which works fine for me. First install the package:
sudo apt install hd-idle
Then edit the configuration file:
sudo nano /etc/default/hd-idle
Then enable the hd-idle to work by commenting out âHD_IDLE_OPTS="-h"â. Then add the following just below it:
START_HD_IDLE=true
Then add the following line at then end of the configuration file:
HD_IDLE_OPTS="-i 0 -a sdb -i 1200 -a sdc -i 300 -a sdd -i 300 -a sde -i 300 -l /var/log/hd-idle.log"
Of course you have adjust as required for your system. The system drive sda is a SSD drive, it requires no spinning down. On sdb I have the data directory for NextCloud. The other drives are for backup purposes.
Install Samba
Samba ensures that files are accessible from Windows computers. As I have not all of my files within NextCloud I require separate storage for music, photoâs, archives and so on.
sudo apt-get update
sudo apt-get install samba -y
Make sure that the users, as you require at home for your users, are created in Ubuntu as well as are also creates in Samba server configuration. I use WebMin for the configuration of Samba.
Install Apache:
Apache provides the web server on the server.
sudo apt install -y apache2 apache2-utils
sudo systemctl enable apache2
Check if it works in a browser by putting yourserverip in a browser.
You should get the default page of Apache2
PHP 7.4 Installation
PHP explains as: Hypertext Pre-Processor. PHP is a widely used programming language.
sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
Extra packages for Nextcloud:
sudo apt install php-imagick php7.4-common php7.4-mysql php7.4-fpm 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 imagemagick
To test PHP scripts with Apache server, we need to create a info.php
file in the document root directory.
sudo nano /var/www/html/info.php
Paste the following PHP code into the file.
<?php phpinfo(); ?>
Check yourserverip/info.php
in the browser.
Make changes to php.ini
sudo nano /etc/php/7.4/apache2/php.ini
Change output_buffering from 4096 to Off
Change memory_limit to 512M
Change upload_max_filesize = 2048M
Check and adjust the following items:
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.save_comments=1
opcache.revalidate_freq=1
Save the file and restart apache2:
sudo systemctl restart apache2
Install MariaDB:
MariaDB is the database that is preferred for NextCloud.
sudo apt-get install mariadb-server php-mysql
New files in the database must be of the barracuda type in order to store emojis. Create a file:
sudo nano /etc/mysql/conf.d/00-innodb.cnf
Put the following text in the file:
[mysqld]
innodb_large_prefix=true
innodb_file_format=barracuda
innodb_file_per_table=1
Then restart mariadb:
sudo systemctl restart mariadb
To secure the installation, the following command is executed:
sudo mysql_secure_installation
enter a strong password and answer all questions with Y.
Then configure a database for NextCloud
sudo mysql -u root -p
The following are commands used within MariaDB:
CREATE DATABASE nextcloud;
The following creates a user within MariaDB NOT within Ubuntu which is not required it looks like:
CREATE USER 'ncroot'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncroot'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Barracuda was chosen as the default file format this way, which is required for NextCloud.
Install NextCloud:
Find out the latest version of NextCloud at the site https://nextcloud.com/install/#instructions-server
Take the version number and put it in the following line:
wget https://download.nextcloud.com/server/releases/latest.zip
Install unzip utility:
sudo apt install unzip
Unzip may already be installed, ignore the error and continue. Now unpack NextCloud in the current in the current directory by:
unzip nextcloud-20.0.2.zip
Move the directory to the webserver directory:
sudo mv nextcloud /var/www/
The NextCloud data directory is standard at the webserver. This makes backup difficult and also you would like your data to be on a different disk as the system is. Therefore create an external directory:
sudo md /media/d1/nextcloud
Of course you can have an other data directory somewhere else to your liking. Make sure all files in the /var/www/nextcloud directory belong to www-data:
sudo chown -R www-data:www-data /var/www/
Make sure the data directory exists and is writable by www-data:
sudo chown -R www-data:www-data /media/d1/nextcloud
Create a âVirtual Host Fileâ for Nextcloud. Edit een nieuwe file:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Paste the following text in the file:
<VirtualHost *:80>
DocumentRoot /var/www/nextcloud
ServerName www.yourdomain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
Satisfy Any
</Directory>
</VirtualHost>
Then create a symbolic link to /etc/apache2/sites-enabled/:
sudo ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf
Enable the following Apache modules. You will find several that are already turned on, this is to make sure they are on.
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod env
sudo a2enmod dir
sudo a2enmod mime
sudo a2enmod setenvif
sudo a2enmod ssl
sudo a2ensite default-ssl
Set the âServerNameâ directive globally, open file:
sudo nano /etc/apache2/conf-available/servername.conf
Put the following text in the file:
ServerName localhost
Save the file. Enable de server name:
sudo a2enconf servername.conf
Restart Apache so the Apache and PHP modules are reloaded:
sudo systemctl restart apache2
Check configuration:
sudo apache2ctl -t
The output should be: âSyntax OKâ
Save the file and start the configuration of NextCloud in your browser with:
yourserverip/nextcloud
Do the rest of the configuration in the web browser. Enter the username and password for the administrator. Enter the username and password for the database user. Put the data directory: /media/d1/nextcloud
And move on: Set the trusted domains for NextCloud
sudo nano /var/www/nextcloud/config/config.php
Adjust the file:
'trusted_domains' =>
array (
0 => '10.220.1.100',
1 => 'www.yourdomain.com',
),
Replace 10.220.1.100 with the local yourserverip, and also adjust the domain name.
Install Redis memory cache
sudo apt install redis-server
Now letâs configure Redis as a cache for NextCloud. Install the PHP extension for connection to Redis.
sudo apt install php-redis
Next, adjust the NextCloud configuration file:
sudo nano /var/www/nextcloud/config/config.php
Add the following lines above the ); line:
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
'host' => 'localhost',
'port' => 6379,
),
The restart Apache webserver:
sudo systemctl restart apache2
Nextcloud security:
In the configuration of your domain, at your provider, you must have your domain passed on to your local IP address. Hopefully your ip from your provider is stable. Usually the ip you get from your Internet Provider is linked to the MAC address of your modem and is stable as long as the equipment is stable.
On your router you have to pass the ports 80 and 443 to yourserverip.
Then install Certbot:
sudo apt update
sudo apt install software-properties-common
sudo apt update
sudo apt install python3-certbot-apache
Be sure your router is pointed at your server!
Start the request for a certificate:
sudo certbot --apache
Enter an email address and your domain. Answer the questions. Please note: reroute the non-secured entrance www.yourdomain.com:80 to www.yourdomain.com:443. If this is not done it is not safe and will issue a warning after installation.
The certificate gets installed. What also happens is the automatic update of the certificate as it is required. This is done by extra files and a cron job to call so the update of the certificates is completely automatic. Very nice!
For extra hardening of the site edit the Apache configuration file for Nextcloud:
sudo nano /etc/apache2/sites-available/nextcloud-le-ssl.conf
Add the following lines after Servername:
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
and save the changes.
After this the server can be found through www.yourdomain.com.
Replace the standard Apache2 web page:
sudo nano /var/www/html/index.html
Replace the contants of the file by:
<META HTTP-EQUIV="Refresh" CONTENT="2;URL=https://www.yourdomain.com/">
Save de file. If someone tries to start the default Apache file he will be redirected to the login screen.
Delete the php information page:
sudo rm /var/www/html/info.php
Update background processes
On the settings page, basic settings tab, it is recommended to use a cron job to update background processes. After the following settings you can indicate that this is done by a cron job.
Make a cronjob by:
sudo crontab -u www-data -e
Choose for the nano editor en paste the following line in the file:
*/5 * * * * php -f /var/www/nextcloud/cron.php
Save the file. Within NextCloud on the settings page choose basic settings. At Background Tasks choose Cron.
And you are done!!!
You can login to your cloud with the username and password you have chosen during the web configuration of NextCloud. I am so happy with it!
Edit 09/04/2021: Upgraded to Version 21.0.1.1 with just two small adjustments which are publicised elsewhere on this forum. Also improved the formatting of the text.
Edit 12/04/2021: Modified the Apache2 configuration file that had a small error. Now the site has an A+ rating thanks to support of NextCloud people!
Edit 13/04/2021: Small changes.
Edit 02/05/2021: Formatting updated.
Edit 27/07/2021: Added imagemagick package to âExtra packages for Nextcloudâ. (Dependency)
Edit 30/09/2021: Fixed the position where the Nextcloud config file is edited.
Edit 21-12-2021: Spin-down fix. (1) Adjusted grub package instructions. (2) Used hd-idle for spindown. (3) Added some suggestions from MichaIng, much appreciated!