How to install Nextcloud on Alpine Linux

Nextcloud is an open-source software suite for hosting and sharing files, calendars and contacts, and more. In this tutorial, we'll walk through how to install Nextcloud on Alpine Linux.

Prerequisites

Before you start, make sure you have the following:

Step 1: Update your system

First, update your system to ensure that you have the latest software packages and security updates.

apk update && apk upgrade

Step 2: Install LAMP stack

Next, you need to install LAMP stack for running Nextcloud. LAMP stands for "Linux, Apache, MySQL, and PHP"; these are all the components you need to run Nextcloud.

apk add apache2 mariadb mariadb-client php7-apache2 php7-pdo_mysql php7-gd php7-xml php7-zip php7-mbstring php7-json php7-session php7-ctype php7-posix php7-fileinfo php7-intl

Step 3: Install Nextcloud

After the LAMP stack is installed, you can now install Nextcloud. First, change to the root directory of your server:

cd /

Then, use wget to download the latest version of Nextcloud.

wget https://download.nextcloud.com/server/releases/latest.tar.bz2

Next, extract the downloaded tarball file:

tar -xjf latest.tar.bz2

Then, move the extracted files to the Apache document root directory:

mv nextcloud /var/www/htdocs/

Change the ownership of the Nextcloud directory to the Apache user:

chown -R apache:apache /var/www/htdocs/nextcloud/

Step 4: Configure Apache

After you have installed Nextcloud, you need to configure Apache to host the Nextcloud service. Start by editing the Apache configuration file with your favorite text editor:

vi /etc/apache2/httpd.conf

Add the following lines to the end of the file:

# Nextcloud configuration
Alias /nextcloud "/var/www/htdocs/nextcloud/"
<Directory "/var/www/htdocs/nextcloud">
    AllowOverride All
    Require all granted
    Options FollowSymLinks +ExecCGI
    SetEnv HOME /var/www/htdocs/nextcloud
    SetEnv HTTP_HOME /var/www/htdocs/nextcloud
</Directory>

Save and close the file. Then, restart the Apache service:

rc-service apache2 restart

Step 5: Configure MariaDB

Next, you need to create a database and a user account for Nextcloud to use. Start by logging into MariaDB as the root user:

mysql -u root -p

Create a new database for Nextcloud:

CREATE DATABASE nextclouddb;

Create a new user and set a password:

CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'secret';

Grant permissions to the new user to access the database:

GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'secret';

Flush the privileges and exit MariaDB:

FLUSH PRIVILEGES;
exit;

Step 6: Enable HTTPS for Nextcloud

For security reasons, it is recommended to use HTTPS when accessing Nextcloud over the network. To enable HTTPS, you need to install a TLS/SSL certificate.

You can obtain a TLS/SSL certificate from a trusted certificate authority or create a self-signed certificate.

Assuming you already have a TLS/SSL certificate, copy the certificate and private key to the server:

cp /path/to/cert.crt /etc/ssl/certs/
cp /path/to/cert.key /etc/ssl/private/

Then, edit the Apache configuration file again:

vi /etc/apache2/httpd.conf

Add the following lines to enable HTTPS:

# enable SSL
LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/cert.crt
    SSLCertificateKeyFile /etc/ssl/private/cert.key
    ServerName yourserverhostname.com
    DocumentRoot /var/www/htdocs/nextcloud/
    ErrorLog /var/log/apache2/nextcloud-error.log
    CustomLog /var/log/apache2/nextcloud-access.log combined
    Alias /nextcloud "/var/www/htdocs/nextcloud/"
    <Directory "/var/www/htdocs/nextcloud">
        AllowOverride All
        Require all granted
        Options FollowSymLinks +ExecCGI
        SetEnv HOME /var/www/htdocs/nextcloud
        SetEnv HTTP_HOME /var/www/htdocs/nextcloud
    </Directory>
</VirtualHost>

Save and close the file. Then, restart Apache again:

rc-service apache2 restart

Step 7: Set up Nextcloud

Finally, you can now access the Nextcloud web interface and set up your account.

Open your web browser and navigate to your server's hostname or IP address:

https://yourserverhostname.com/nextcloud

You will be prompted to create a new admin account and set a password. Follow the on-screen instructions to complete the setup.

That's it! You have successfully installed Nextcloud on Alpine Linux and can now start using this powerful file-hosting tool.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!