This instance of NextCloud will be installed on the server. If you wish to have it using Docker or Snap see the previous post [Link].

If you don’t have Apache + PHP + MySQL running follow these easy steps before starting with the NextCLoud it self:

sudo apt update && sudo apt upgrade -y
sudo apt install tasksel -y
sudo tasksel install lamp-server

Installing NextCloud

wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip
sudo apt install unzip
sudo rm -rf /var/www/html
sudo unzip nextcloud-23.0.0.zip -d /var/www/
sudo mv /var/www/nextcloud /var/www/html
sudo chown -R www-data:www-data /var/www/html/
sudo mysql

Get the latest at [Link].

MySQL Configuration

Create the database, create the user, give privileges, and flush MySQL privileges:

CREATE DATABASE nextcloud_db;
CREATE USER [email protected] IDENTIFIED BY 'nextcloud_password';
GRANT ALL PRIVILEGES ON nextcloud_db.* TO [email protected];
FLUSH PRIVILEGES;
EXIT;

Configure Apache to NextCloud:

sudo nano /etc/apache2/sites-available/nextcloud.conf

Paste this content and adjust the bolds accordingly:

ServerAdmin [email protected]
MDCertificateAgreement accepted
MDomain nextcloud.example.com
MDPrivateKeys RSA 4096

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html
        ServerName nextcloud.example.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        RewriteEngine On
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLHonorCipherOrder on
        SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"
        ServerAdmin [email protected]
        DocumentRoot /var/www/html
        ServerName nextcloud.example.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        Protocols h2 http/1.1
        Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>
<Location "/md-status">
        SetHandler md-status
</Location>

Note that HTTPS was configured on Apache, so configure the SSL/TLS encryption using the module MD, which uses Let’s Encrypt free service and is amazing!

sudo apt install libapache2-mod-md
sudo a2enmod md
sudo systemctl restart apache2
sudo a2enmod ssl
sudo systemctl reload apache2
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo a2enmod rewrite headers env dir mime setenvif ssl
sudo a2ensite nextcloud.conf
sudo apache2ctl configtest

If the test configuration goes well, restart Apache:

sudo systemctl restart apache2

If restarting fails check the log:

sudo tail -f /var/log/apache2/error.log

After restarting Apache successfully it will create the certificate for the HTTPS, and will necessary to be restarted once more after 1 or 2 minutes.

Access your new site on the browser https://nextcloud.example.com

You may be prompted with a page with many requirements that are missing in your server to allow NextCloud features, such as image manipulating, compress files…

sudo apt install imagemagick php-imagick libapache2-mod-php7.4 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
sudo systemctl reload apache2

Refresh the page and the message will not be prompted anymore, but the installation process will start.

Create user and password for the NextCloud administrator.

Inform the database name and credentials you set before on the MySQL configuration.

Done!


BONUS

OwnCloud is another opensource alternative to NextCloud, try it out and see what suits better to your needs:

sudo apt install docker.io -y
sudo docker run --name OwnCloud --restart=unless-stopped -v /opt/OwnCloudData:/mnt/data/ -d -e OWNCLOUD_DOMAIN=owncloud.example.com:8080 -p80:8080 owncloud/server

One Reply to “Private Cloud with NextCloud 23 on Ubuntu 20.04”

Comments are closed.