<coded>


How to install Nextcloud 24 on Debian

May 15, 2022

Nextcloud is a self-hosted file sharing application that allows you to store your data, such as files, contacts, images, calendars, news and more. Using Nextcloud to store your documents can remove your need for using third-party hosting software like Dropbox, Google Drive, iCloud. In this article, we will install Nextcloud 24, with Apache web server, MariaDB and PHP.

Requirements

1. Login via SSH and update your system

Log in to your Debian VPS via SSH as user root

ssh root@Server_IP_Address -p Port_Number

Using the following command, all installed packages will be updated and upgraded:

apt-get update && apt-get upgrade -y

2. Install Apache web server

First, you need to install a web server to run Nextcloud. By executing the following command you will install the Apache web server on your VPS.

apt-get install apache2 libapache2-mod-php

You can start Apache and also enable to start on server boot with these commands:

systemctl start apache2
systemctl enable apache2

3. Install PHP

Install PHP together with some PHP modules that are required by Nextcloud.

apt-get install openssl php-imagick php-common php-curl php-gd php-imap php-intl php-json php-ldap php-mbstring php-mysql php-pgsql php-smbclient php-ssh2 php-sqlite3 php-xml php-zip php-redis php-apcu -y

4. Install MariaDB and create a database

As mentioned in the requirements, a database server is required to run NextCloud. We will install MariaDB server using the command:

apt-get -y install mariadb-server

Once installed, start the database server and enable it to start at server boot.

systemctl start mariadb
systemctl enable mariadb

You can run the mysql_secure_installation which is a post-installation script used to improve the security of your MariaDB server and set a ‘root’ password. You may use the options below

mysql_secure_installation

Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Next step is to log in to the MariaDB server as ‘root’ user and creates a database and user for Nextcloud.

mysql -u root -p

 

MariaDB [(none)]> CREATE DATABASE nextcloud;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud_user'@'localhost' IDENTIFIED BY 'Password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;

It is recommended to replace ‘Password’ with a strong password which will be a combination of letters and numbers and at least 10 characters long.

5. Download and install Nextcloud

Go to Nextcloud’s official website and download Nextcloud 24 to your Debian VPS. Currently, the latest stable version is 24.0.0

wget https://download.nextcloud.com/server/releases/nextcloud-24.0.0.zip

Extract the downloaded ZIP archive Nextcloud-24.0.0.zip in a directory that Apache has access to, and change the ownership of the Nextcloud directory to the web server user.

unzip nextcloud-24.0.0.zip -d /var/www/html/
chown -R www-data:www-data /var/www/html/nextcloud/

Once all of the Nextcloud prerequisites are met, we can complete the installation using two different ways: using the on-screen installation wizard or via the command line. In this case, we are going to use the installation via the command line. We will change the current working directory with this command:

cd /var/www/html/nextcloud

now run the following command as web server user (www-data):

sudo -u www-data php occ maintenance:install --database "mysql" --database-name "nextcloud" --database-user "nextcloud_user" --database-pass "Password" --admin-user "admin" --admin-pass "Password"

You should use the database information we created previously in this tutorial and replace the ‘Password’ with a strong password for the Nextcloud ‘admin’ user.

You will get the following output if the installation is successful:

Nextcloud was successfully installed

Add your_domain.com by editing the config/config.php file:

nano config/config.php

 

'trusted_domains' =>
array (
    0 => 'localhost',
    1 => 'your_domain.com',
),

6. Create Apache Virtual Host

To access the Nextcloud with a domain name you need to create a virtual host. Create the following file with this command:

nano /etc/apache2/sites-available/your_domain.com.conf

Don’t forget to modify the your_domain.com

<VirtualHost *:80>

ServerAdmin admin@your_domain.com
DocumentRoot /var/www/html/nextcloud
ServerName your_domain.com
ServerAlias www.your_domain.com

Alias /nextcloud “/var/www/html/nextcloud/”

<Directory /var/www/html/nextcloud>
Options +FollowSymlinks
AllowOverride All

<IfModule mod_dav.c>
Dav off
</IfModule>

SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>

ErrorLog /var/log/apache2/nextcloud-error_log
CustomLog /var/log/apache2/nextcloud-access_log common

</VirtualHost>

Save the file.

Enable the newly created virtual host:

a2ensite your_domain.com.conf

To finish and activate the newly created configuration, you need to reload the Apache web server.

systemctl reload apache2

Congratulations, the Nextcloud 24 installation is complete. Now you can choose your favorite browser and visit the http://your_domain.com and login to your Nextcloud instance by using the credentials you set in the installation command above.

Source

Did you find this useful? Please rate this post: