Nextcloud is an open-source file sync and sharing software that can be used as a replacement for Google Drive, Yandex Disk, and similar cloud-based storage. It is written in PHP and JavaScript and has support for MySQL, PostgreSQL, SQLite, and Oracle Database.

Install LAMP Stack

Install Apache2, MySql, and PHP.

apt install apache2 mysql-server php zip unzip libapache2-mod-php php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-mysql php-bcmath php-gmp


Secure MySql

Run the command to secure MySql.


mysql_secureSecure MySql

Create MySql User and Database

Login as a root user to MySQL console and create a new database for Nextcloud.

mysql -u root -p

Create a new database.


Create a new user.

CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'PASSWORD';

Give the new user the necessary permissions.

GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';

Flush the privileges and exit the console.


Download Nextcloud

Download the latest Nextcloud from its official website.

cd /tmp
cd /var/www
unzip /tmp/
chown -R www-data: /var/www/nextcloud/

Configure Apache

Create a configuration file with an Alias to Nextcloud directory.

nano /etc/apache2/sites-available/nextcloud.conf
Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off


Enable the site.

a2ensite nextcloud.conf

Enable the necessary Apache modules.

a2enmod rewrite headers env dir mime

Reload Apache.

systemctl reload apache2

Create a configuration file with a domain to Nextcloud directory.

nano /etc/apache2/sites-available/
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/nextcloud
<directory /var/www/nextcloud>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud

Enable the site.


Reload Apache.

systemctl reload apache2

Run Nexctloud Web Installer

Now open your website or Nextcloud directory according to your configuration.

Enter new admin credentials to create an admin account and input the database credentials and click on Finish Setup.


After completing the setup you will get the admin dashboard.

Now install Nextcloud Agent on your end device to start syncing files.