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 14 on Debian 9, with Apache web server, MariaDB and PHP 7.0.
Requirements:
- root access via SSH to your VPS;
- MySQL or MariaDB 5.5+ or PostgreSQL version 9 or 10;
- PHP version 7.0 or above;
- Apache version 2.4 with mod_php or Nginx (php-fpm) web server;
Table of Contents
Login via SSH and update your system
Log in to your Debian 9 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 update && apt upgrade -y
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
You can start Apache and also enable to start on server boot with these commands:
systemctl start apache2 systemctl enable apache2
Install PHP
Install PHP together with some PHP modules that are required by Nextcloud.
apt install php7.0 libapache2-mod-php7.0 php7.0-common php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php7.0-imagick php7.0-xml php7.0-zip
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.
Download and install Nextcloud
Go to Nextcloud’s official website and download Nextcloud 14 to your Debian 9 VPS. Currently, the latest stable version is 14.0.0
wget https://download.nextcloud.com/server/releases/nextcloud-14.0.0.zip
Extract the downloaded ZIP archive Nextcloud-14.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-14.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', ),
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 14 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.
You don’t need to Install NextCloud 14 on Debian 9 if you use one of our NextClould Hosting services, in which case you can simply ask our expert Linux admins to set up Nextcloud 14 on your Ubuntu 16.04 server for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on How To Install NextCloud 14 on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.