Hosting a Personal Cloud with Nextcloud on a VPS

Introduction

Nextcloud is a powerful open-source platform that allows you to self-host your own cloud storage. Running Nextcloud on a VPS provides a private and secure way to store and share your files, calendar, contacts, and more. This guide will walk you through setting up Nextcloud on a VPS step by step.

Step 1: Preparing Your VPS

  1. Update your system’s package list:

    sudo apt update && sudo apt upgrade -y

  2. Install necessary dependencies:

    sudo apt install -y apache2 mariadb-server php php-mysql libapache2-mod-php php-xml php-curl php-gd php-mbstring php-intl php-zip php-bz2 php-json php-simplexml

  3. Enable Apache modules:

    sudo a2enmod rewrite headers env dir mime

  4. Restart Apache:

    sudo systemctl restart apache2


Step 2: Setting Up the Database

  1. Secure your MariaDB installation:

    sudo mysql_secure_installation

  2. Log into MariaDB:

    sudo mysql -u root -p

  3. Create a database and user for Nextcloud:

    CREATE DATABASE nextcloud;

    CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';

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

    FLUSH PRIVILEGES;

    EXIT;


Step 3: Downloading and Installing Nextcloud

  1. Download the latest Nextcloud release:

    wget https://download.nextcloud.com/server/releases/latest.tar.bz2

  2. Extract the archive:

    tar -xjf latest.tar.bz2

  3. Move Nextcloud files to the web directory:

    sudo mv nextcloud /var/www/html

  4. Set correct permissions:

    sudo chown -R www-data:www-data /var/www/html/nextcloud


Step 4: Configuring Apache for Nextcloud

  1. Create a new Apache configuration file:

    sudo nano /etc/apache2/sites-available/nextcloud.conf

  2. Add the following content:

    <VirtualHost *:80>

    DocumentRoot /var/www/html/nextcloud

    ServerName yourdomain.com

    <Directory /var/www/html/nextcloud/>

    Require all granted

    AllowOverride All

    Options FollowSymLinks MultiViews

    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

  3. Enable the configuration:

    sudo a2ensite nextcloud.conf

  4. Restart Apache:

    sudo systemctl restart apache2


Step 5: Running the Nextcloud Installer

  1. Open your browser and visit http://yourdomain.com

  2. Complete the web-based setup by entering:

    Admin username and password

    Database user, password, and database name (nextcloud)

  3. Click “Finish Setup”

Conclusion

You have successfully installed Nextcloud on your VPS. This provides you with full control over your cloud storage, ensuring privacy and security. Consider setting up SSL encryption with Let’s Encrypt to secure your installation.