How to Install Nextcloud 14 on Debian 9
- root access via SSH to your system;
- 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;
Login via SSH and update your system
Log in to your Debian 9 system 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 system.
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 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
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 system. Currently, the latest stable version is 14.0.0
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:
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
'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:
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:
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.