How to Install Nextcloud on VPS for Secure Cloud Storage

Nextcloud is a popular open-source self-hosted cloud storage solution that allows you to store and manage your files, contacts, calendars, and more. Hosting Nextcloud on your VPS provides full control over your data and privacy, offering a secure alternative to commercial cloud storage providers like Google Drive, Dropbox, and others.

In this guide, we will walk you through the steps to install Nextcloud on your VPS for secure cloud storage.


Prerequisites

Before we begin, ensure you have the following:

  1. VPS with Ubuntu 20.04 LTS or later (Other distributions are supported, but this guide assumes Ubuntu).
  2. A domain name (Optional but recommended for easier access and SSL).
  3. Basic knowledge of Linux commands.
  4. Root or sudo user privileges.

Step 1: Set Up Your VPS

  1. Access Your VPS via SSH

    • Open a terminal on your local machine and SSH into your VPS:
       
      ssh username@your-vps-ip
  2. Update Your VPS

    • It’s always a good practice to update your system’s package lists and installed packages:
       
      sudo apt update && sudo apt upgrade -y

Step 2: Install LAMP Stack (Linux, Apache, MySQL, PHP)

Nextcloud requires a web server (Apache), a database server (MySQL or MariaDB), and PHP. Let's install these components.

  1. Install Apache Web Server

    • Install Apache:
       
      sudo apt install apache2 -y
    • Start Apache and enable it to start at boot:
       
      sudo systemctl start apache2 sudo systemctl enable apache2
  2. Install MySQL or MariaDB

    • Install MySQL server:
       
      sudo apt install mysql-server -y
    • Start MySQL and enable it at boot:
       
      sudo systemctl start mysql sudo systemctl enable mysql
  3. Install PHP and Required Extensions

    • Nextcloud requires PHP 7.4 or higher. Install PHP and the necessary extensions:
       
      sudo apt install php php-cli php-fpm php-mysql php-xml php-zip php-gd php-mbstring php-curl php-bz2 php-intl php-imagick -y
  4. Check PHP Version

    • Check the installed PHP version:
       
      php -v
    • Ensure you have PHP 7.4 or higher.

Step 3: Set Up the Database for Nextcloud

  1. Log into MySQL

    • Log into the MySQL root user:
       
      sudo mysql -u root -p
  2. Create a Database and User for Nextcloud

    • Create a Nextcloud database and user with full privileges:
      sql
       
      CREATE DATABASE nextcloud; CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'your-password'; GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost'; FLUSH PRIVILEGES; EXIT;

Step 4: Install Nextcloud

  1. Download Nextcloud

    • Download the latest stable release of Nextcloud from their official website:
       
      cd /var/www/ sudo wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip
  2. Extract Nextcloud

    • Extract the Nextcloud archive:
       
      sudo unzip nextcloud-23.0.0.zip sudo chown -R www-data:www-data nextcloud
  3. Configure Apache for Nextcloud

    • Create a new Apache configuration file for Nextcloud:
       
      sudo nano /etc/apache2/sites-available/nextcloud.conf
  4. Add the Following Apache Configuration

    • Replace your-domain.com with your domain or VPS IP if you're not using a domain:
      apache
       
      <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/nextcloud ServerName your-domain.com <Directory /var/www/nextcloud/> Options +FollowSymlinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
  5. Enable the Site and Rewrite Module

    • Enable the new site and the mod_rewrite module:
       
      sudo a2ensite nextcloud.conf sudo a2enmod rewrite
  6. Restart Apache

    • Restart Apache to apply the changes:
       
      sudo systemctl restart apache2

Step 5: Set Up SSL (Optional but Recommended)

For better security, it’s recommended to set up HTTPS using SSL certificates. You can use Let's Encrypt to get a free SSL certificate.

  1. Install Certbot

    • Install Certbot and the Apache plugin:
       
      sudo apt install certbot python3-certbot-apache -y
  2. Obtain an SSL Certificate

    • Run the following command to automatically obtain and install the SSL certificate:
       
      sudo certbot --apache -d your-domain.com
  3. Verify SSL Configuration

    • Check your SSL configuration:
       
      sudo apache2ctl configtest sudo systemctl reload apache2

Step 6: Configure Nextcloud

  1. Access Nextcloud in a Browser

    • Open your browser and go to http://your-domain.com or https://your-domain.com if you configured SSL.
  2. Complete the Setup Wizard

    • The Nextcloud setup page will appear. Fill out the information:
      • Data Folder: This is the location where Nextcloud stores files. Make sure it’s writable by Apache (www-data).
      • Database Settings: Choose MySQL, and enter the database details you set earlier:
        • Database Name: nextcloud
        • Database User: nextclouduser
        • Database Password: your-password
        • Database Host: localhost
    • After entering the database details, click Finish Setup.
  3. Create an Admin Account

    • Create an admin user account by entering the desired username and password.

Step 7: Configure Data Storage (Optional)

You can configure external storage options, such as connecting your Nextcloud instance to an external hard drive, FTP server, or cloud storage.

  1. Add External Storage
    • Navigate to the Nextcloud settings.
    • Under the Admin section, click on External storage.
    • Add your external storage options.

Step 8: Enable Additional Nextcloud Features

Nextcloud offers many features and apps for team collaboration, file sharing, and more. Some features you might want to enable include:

  1. Enable the Nextcloud App Store:

    • Install additional apps like calendar, contacts, and more for enhanced functionality.
  2. Enable Two-Factor Authentication (2FA):

    • For increased security, enable 2FA for user accounts.

Conclusion

Congratulations! You’ve successfully installed Nextcloud on your VPS for secure cloud storage. With Nextcloud, you now have full control over your data, enabling you to store, share, and collaborate with your team securely. You can also explore Nextcloud’s vast ecosystem of apps and integrations to extend its functionality and further customize your cloud storage solution.

By following this guide, you’ve created a powerful self-hosted cloud solution that provides all the benefits of major cloud storage providers while giving you complete control over your data privacy and security.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution