Comprehensive Guide to Setting Up and Optimizing Your DomainIndia.com KVM VPS for Development Print

  • 0

Setting up a KVM VPS for development is a critical step in ensuring a robust and efficient environment for your applications. DomainIndia.com KVM VPS offers unparalleled flexibility, performance, and control, making it an ideal choice for developers and businesses alike. Whether you're building modern web applications, scalable backends, or secure enterprise solutions, this guide provides a detailed roadmap tailored to your needs.

This guide covers everything you need to know about configuring your KVM VPS, from installing essential development tools and frameworks to securing your environment and optimizing performance. By focusing on stack-specific requirements, it helps you avoid unnecessary installations, ensuring a lean and efficient setup.

By the end of this guide, you’ll have a fully functional, secure, and optimized VPS ready for development, staging, or production. Let's dive into the steps to make the most of your DomainIndia.com KVM VPS.

Table of Contents

1. Introduction

  • Why Choose DomainIndia.com KVM VPS for Development?
  • Overview of Supported Development Stacks
  • Benefits of Stack-Specific Setup to Optimize Resources

2. Initial Setup

  • Required:
    • Logging into Your VPS via SSH
    • Updating the System (yum, apt)
    • Setting Up a Non-Root User for Secure Operations
    • Configuring Basic Network and Swap Settings
  • Optional:
    • Setting Up Hostname and Custom DNS

3. Installing Web Servers

  • Required:
    • Apache or Nginx (for stacks requiring LAMP, LEMP, or reverse proxy)
  • Optional (Stack-Specific):
    • Nginx or Apache for Node.js apps (if reverse proxy is needed)
    • Both Apache and Nginx (if hosting multiple apps with varying needs)

4. Database Setup

  • Required (Based on Stack):
    • MySQL/MariaDB (LAMP, LEMP, WordPress)
    • PostgreSQL (Django, Ruby on Rails)
    • MongoDB (MERN, MEAN)
  • Optional:
    • Redis for Caching (All stacks)
    • Cassandra for Highly Scalable Applications

5. Setting Up Popular Stacks

5.1. MERN Stack
  • Required:
    • Node.js and npm/yarn
    • MongoDB
    • React.js Frontend
    • Express.js Backend
  • Optional:
    • Nginx as a Reverse Proxy
    • PM2 or Forever for Process Management
5.2. MEAN Stack
  • Required:
    • MongoDB
    • Angular.js Frontend
    • Express.js Backend
    • Node.js
  • Optional:
    • Nginx or Apache as Reverse Proxy
5.3. LAMP Stack
  • Required:
    • Apache
    • MySQL/MariaDB
    • PHP
  • Optional:
    • phpMyAdmin for Database Management
5.4. LEMP Stack
  • Required:
    • Nginx
    • MySQL/MariaDB
    • PHP-FPM (FastCGI Process Manager)
  • Optional:
    • Redis for Caching
5.5. Django + Python
  • Required:
    • Python and Virtualenv
    • Django Framework
    • PostgreSQL or MySQL
    • Gunicorn (WSGI Server)
  • Optional:
    • Nginx as a Reverse Proxy
    • Redis for Caching
5.6. Ruby on Rails
  • Required:
    • Ruby
    • Rails Framework
    • PostgreSQL or MySQL
  • Optional:
    • Nginx for Serving Rails Apps
    • Puma or Unicorn for App Server
5.7. Java Development
  • Required:
    • OpenJDK
    • Apache Tomcat
  • Optional:
    • Maven for Build Management
5.8. Go Stack
  • Required:
    • Go Programming Language
    • Compiler and Tools
  • Optional:
    • Nginx or Apache for Static File Serving

6. Development Tools and Utilities

  • Required:
    • Git for Version Control
  • Optional:
    • Docker and Docker Compose for Containerized Development
    • Build Tools (Make, GCC, CMake, Maven, etc.)

7. Configuring Security

  • Required:
    • Enabling a Firewall (CSF or UFW)
    • Securing SSH (Key-Based Authentication, Changing Default Port)
    • Installing Fail2Ban for Brute-Force Prevention
    • Setting Up Automatic Updates
  • Optional:
    • Let’s Encrypt SSL Certificates
    • IDS/IPS Systems (e.g., Snort, Suricata)

8. Monitoring and Performance Optimization

  • Required:
    • Installing Basic Monitoring Tools (e.g., htop)
  • Optional:
    • Advanced Monitoring (Netdata, Grafana)
    • Caching Mechanisms (Memcached, Redis)
    • Performance Testing Tools (Apache Benchmark, Siege)

9. Backup and Disaster Recovery

  • Required:
    • Setting Up Regular Backups
  • Optional:
    • Using DomainIndia VPS Snapshot Feature

10. Advanced Configurations for Multi-Stack Environments

  • Required:
    • Managing Virtual Hosts (Apache/Nginx) for Hosting Multiple Apps
    • Setting Up Isolated Environments Using Docker or VMs
  • Optional:
    • Reverse Proxies for Multi-App Hosting

11. Best Practices for Staging and Production

  • Required:
    • Configuring Separate Staging and Production Environments
  • Optional:
    • Using CI/CD Pipelines (e.g., Jenkins, GitHub Actions)

12. FAQs and Troubleshooting

  • Common Installation Issues for Each Stack
  • Debugging Database and Web Server Errors
  • Resolving Performance Bottlenecks

1. Introduction

Why Choose DomainIndia.com KVM VPS for Development?

DomainIndia.com KVM VPS is an ideal platform for modern development with its high performance, scalability, and flexibility. With full root access and support for multiple stacks, it allows developers to set up an environment tailored to their needs.

Overview of Supported Development Stacks

  • LAMP/LEMP: For PHP-based websites and CMS.
  • MERN/MEAN: For dynamic web applications.
  • Django + Python: For scalable, secure apps.
  • Ruby on Rails: For fast development of robust apps.
  • Java Development: For enterprise-grade solutions.
  • Go Development: For efficient and scalable applications.

2. Initial Setup

Required Steps

  1. Logging into Your VPS via SSH

    • Use the SSH client to connect: ssh root@your-server-ip
  2. Updating the System

    • For CentOS or RHEL: yum update -y
    • For Ubuntu or Debian: apt update && apt upgrade -y
  3. Setting Up a Non-Root User

    • Add a new user: adduser username
    • Set a password for the user: passwd username
    • Grant sudo privileges: usermod -aG sudo username
  4. Configuring Basic Network and Swap Settings

    • Add swap space: fallocate -l 2G /swapfile
      chmod 600 /swapfile
      mkswap /swapfile
      swapon /swapfile
      echo '/swapfile none swap sw 0 0' >> /etc/fstab

Optional Steps

  1. Setting Up Hostname

    • Set a unique hostname: hostnamectl set-hostname your-new-hostname
  2. Configuring Custom DNS

    • Edit the file /etc/resolv.conf to add custom DNS servers.

3. Installing Web Servers

Required

  • Apache:
    Install Apache: yum install httpd -y (CentOS) or apt install apache2 -y (Ubuntu)
    Start service: systemctl start httpd (CentOS) or systemctl start apache2 (Ubuntu)
    Enable on boot: systemctl enable httpd (CentOS) or systemctl enable apache2 (Ubuntu)

  • Nginx:
    Install Nginx: yum install nginx -y (CentOS) or apt install nginx -y (Ubuntu)
    Start service: systemctl start nginx
    Enable on boot: systemctl enable nginx

Why Web Servers are Required for MERN, MEAN, and Other Stacks

While modern stacks like MERN (MongoDB, Express.js, React.js, Node.js) and MEAN (MongoDB, Express.js, Angular.js, Node.js) have Node.js for serving backend APIs and content, traditional web servers like Apache and Nginx are still required or highly beneficial in certain scenarios. Here's why:


1. Benefits of Using a Web Server (Apache or Nginx)

A. Reverse Proxy for Node.js

  • Why Required: Node.js apps typically run on ports like 3000, which are not directly accessible for production traffic. Web servers like Nginx or Apache can act as a reverse proxy, forwarding client requests to the appropriate Node.js port.
  • How It Helps:
    • Security: The web server handles public-facing requests, shielding the Node.js application from direct exposure.
    • SSL Termination: Manage HTTPS connections at the web server level, offloading encryption/decryption work from the Node.js app.
    • Performance: Reverse proxies can cache static content, reducing load on the Node.js backend.

B. Static File Serving

  • Why Required: React (MERN) or Angular (MEAN) frontend apps generate static assets like HTML, CSS, JavaScript, and images. Web servers like Apache or Nginx are optimized for serving these files efficiently.
  • How It Helps:
    • Efficiency: Web servers are faster than Node.js for static file delivery.
    • Resource Optimization: Node.js can focus on API and dynamic content, while the web server handles static files.

C. Load Balancing

  • Why Required: For high-traffic applications, multiple Node.js instances may be deployed to handle requests. A web server like Nginx can distribute traffic evenly across these instances.
  • How It Helps:
    • Prevents overloading a single Node.js instance.
    • Ensures high availability and scalability.

D. Multi-App Hosting

  • Why Required: When hosting multiple applications (e.g., a React frontend and Node.js backend), a web server can route requests based on the domain or subdomain.
  • How It Helps:
    • Simplifies management of multiple apps on a single server.
    • Allows you to run both frontend and backend apps simultaneously with clear separation.

Optional (Stack-Specific)

  • Nginx or Apache for Node.js Apps:
    Use Nginx or Apache as a reverse proxy to forward requests to Node.js (usually on port 3000).
    Configure /etc/nginx/conf.d/app.conf or equivalent Apache configuration.

  • Both Apache and Nginx:
    If hosting multiple apps, ensure one web server runs on an alternate port (e.g., Apache on port 8080, Nginx on port 80).

Understanding Reverse Proxy

A reverse proxy acts as an intermediary between the client (browser) and the backend server, such as a Node.js application. It forwards client requests to the appropriate server and sends the server's responses back to the client.

Why Use a Reverse Proxy?

  1. Load Balancing: Distribute traffic across multiple backend servers for better performance.
  2. SSL Termination: Manage HTTPS connections at the proxy level, offloading encryption/decryption from backend servers.
  3. Security: Hide the backend server's details and add an additional layer of protection.
  4. Static File Serving: Serve static assets like images or CSS files directly from the proxy.
  5. Multiple Apps Management: Route requests based on domains or subdomains to specific applications.

Use Nginx as a Reverse Proxy

  1. Install Nginx:

    • Ubuntu/Debian: apt install nginx -y
    • CentOS/RHEL: yum install nginx -y
  2. Configure Reverse Proxy:

Open /etc/nginx/conf.d/app.conf and add the following:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
​

Restart Nginx:

systemctl restart nginx


 

Use Apache as a Reverse Proxy

  1. Enable Proxy Modules:

    • Run the following commands:
      • a2enmod proxy
      • a2enmod proxy_http
  2. Configure Virtual Host:

    • Open /etc/apache2/sites-available/your-site.conf and add:
      <VirtualHost *:80>
          ServerName your-domain.com
          ProxyPreserveHost On
          ProxyPass / http://127.0.0.1:3000/
          ProxyPassReverse / http://127.0.0.1:3000/
      </VirtualHost>
      ​

      Enable Site and Restart Apache:

      • Enable site: a2ensite your-site

Restart Apache: systemctl restart apache2

 

Steps for Running Both Apache and Nginx

  1. Run Nginx on Port 80:

    • Configure Nginx as the primary web server for static files and frontend traffic.
  2. Run Apache on Port 8080:

    • Edit /etc/apache2/ports.conf and add:
      Listen 8080
      ​
  3. Update Apache Virtual Host:

    • Modify the <VirtualHost> section in your Apache configuration to:
      <VirtualHost *:8080>
          ServerName backend.your-domain.com
          DocumentRoot /var/www/backend
      </VirtualHost>
      ​
    • Restart Both Servers:

      • Nginx: systemctl restart nginx
      • Apache: systemctl restart apache2

4. Database Setup

Required (Based on Stack)

  • MySQL/MariaDB:
    Install: apt install mysql-server -y (Ubuntu) or yum install mysql-server -y (CentOS)
    Start service: systemctl start mysql
    Secure installation: mysql_secure_installation

  • PostgreSQL:
    Install: apt install postgresql postgresql-contrib -y (Ubuntu) or yum install postgresql-server postgresql-contrib -y (CentOS)
    Initialize database (CentOS): postgresql-setup initdb
    Start service: systemctl start postgresql
    Create user and database: Use psql command-line utility.

  • MongoDB:
    Add MongoDB repository and install the server package.
    Start service: systemctl start mongod
    Enable on boot: systemctl enable mongod

Optional

  • Redis for Caching:
    Install: apt install redis -y (Ubuntu) or yum install redis -y (CentOS)
    Start service: systemctl start redis
    Enable on boot: systemctl enable redis

  • Cassandra for Scalable Applications:
    Add the Apache Cassandra repository and install it.
    Start service: systemctl start cassandra
    Enable on boot: systemctl enable cassandra

5. Setting Up Popular Stacks

This section provides step-by-step instructions to set up various popular stacks, covering both required and optional components.


5.1. MERN Stack

Required
  1. Install Node.js and npm/yarn

    • Install Node.js:
      • CentOS/RHEL: yum install -y nodejs
      • Ubuntu/Debian: apt install -y nodejs
    • Install npm:
      • CentOS/RHEL: yum install -y npm
      • Ubuntu/Debian: apt install -y npm
    • Install Yarn (optional): npm install -g yarn
  2. Install MongoDB

    • Add MongoDB repository and install the package:
      • Ubuntu: Add MongoDB repository with wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
        Install MongoDB: apt install -y mongodb
      • CentOS: Follow MongoDB's official repository setup and install with yum install -y mongodb-org
    • Start MongoDB: systemctl start mongod
    • Enable MongoDB on boot: systemctl enable mongod
  3. Set Up React.js Frontend

    • Create a React app:
      • npx create-react-app my-app
      • Navigate to the app folder: cd my-app
      • Start the development server: npm start
  4. Set Up Express.js Backend

    • Initialize a Node.js project: mkdir backend && cd backend && npm init -y
    • Install Express: npm install express
    • Create an index.js file with a basic Express server:
      const express = require('express');
      const app = express();
      const PORT = 3000;
      app.get('/', (req, res) => res.send('Hello World'));
      app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
      ​
Optional
  • Nginx as a Reverse Proxy

    • Configure Nginx to forward traffic to the Node.js app running on port 3000.
  • PM2 or Forever for Process Management

    • Install PM2: npm install -g pm2
    • Start your app with PM2: pm2 start index.js

5.2. MEAN Stack

Required
  1. Install Node.js and npm
    Follow the instructions in the MERN stack section.

  2. Install MongoDB
    Follow the instructions in the MERN stack section.

  3. Set Up Angular.js Frontend

    • Install Angular CLI: npm install -g @angular/cli
    • Create an Angular project: ng new my-angular-app
    • Navigate to the project folder: cd my-angular-app
    • Start the development server: ng serve
  4. Set Up Express.js Backend

    • Same as in the MERN stack section.
Optional
  • Nginx or Apache as Reverse Proxy
    Configure Nginx or Apache to route traffic to the Angular and Node.js apps.

5.3. LAMP Stack

Required
  1. Install Apache

    • CentOS: yum install -y httpd && systemctl start httpd && systemctl enable httpd
    • Ubuntu: apt install -y apache2 && systemctl start apache2 && systemctl enable apache2
  2. Install MySQL/MariaDB

    • CentOS: yum install -y mariadb-server && systemctl start mariadb && systemctl enable mariadb
    • Ubuntu: apt install -y mysql-server && systemctl start mysql && systemctl enable mysql
    • Secure the installation: mysql_secure_installation
  3. Install PHP

    • CentOS: yum install -y php php-mysql
    • Ubuntu: apt install -y php php-mysql
Optional
  • Install phpMyAdmin for Database Management
    • Install phpMyAdmin: apt install -y phpmyadmin (Ubuntu)

5.4. LEMP Stack

Required
  1. Install Nginx

    • Same as in the MERN stack section.
  2. Install MySQL/MariaDB

    • Same as in the LAMP stack section.
  3. Install PHP-FPM

    • CentOS: yum install -y php-fpm
    • Ubuntu: apt install -y php-fpm
    • Configure Nginx to use PHP-FPM for dynamic content.
Optional
  • Install Redis for Caching
    • Install Redis: apt install -y redis (Ubuntu)

5.5. Django + Python

Required Steps

  1. Install Python and Virtualenv

    • For Ubuntu/Debian:
      apt install -y python3 python3-venv
    • For CentOS/RHEL:
      • Enable the EPEL repository:
        yum install -y epel-release
      • Install Python 3:
        yum install -y python3
  2. Install Django Framework

    • Create a virtual environment:
      python3 -m venv myenv
    • Activate the virtual environment:
      source myenv/bin/activate
    • Install Django:
      pip install django
  3. Set Up PostgreSQL or MySQL

    • Follow the database setup steps from the LAMP stack section:
      • Install PostgreSQL or MySQL.
      • Create a database and user for your Django application.
    • Configure your database settings in settings.py under the DATABASES section.
  4. Install Gunicorn (WSGI Server)

    • Install Gunicorn:
      pip install gunicorn
    • Test Gunicorn by running your application:
      gunicorn --bind 0.0.0.0:8000 your_project_name.wsgi

Optional Steps

  1. Nginx as a Reverse Proxy

    • Configure Nginx to route traffic to Gunicorn:
      • Create a new server block in /etc/nginx/sites-available/your-django-app:
        server {
            listen 80;
            server_name yourdomain.com;
        
            location / {
                proxy_pass http://127.0.0.1:8000;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
        }
        ​
        Enable the configuration:
        ln -s /etc/nginx/sites-available/your-django-app /etc/nginx/sites-enabled/Test and restart Nginx:
        nginx -t && systemctl restart nginx

        Install Redis for Caching

        • Install Redis:
          • For Ubuntu/Debian:
            apt install -y redis
          • For CentOS/RHEL:
            yum install -y redis
        • Start and enable the Redis service:
          • systemctl start redis && systemctl enable redis
        • Configure Django to use Redis in the CACHES section of settings.py
          CACHES = {
              'default': {
                  'BACKEND': 'django_redis.cache.RedisCache',
                  'LOCATION': 'redis://127.0.0.1:6379/1',
                  'OPTIONS': {
                      'CLIENT_CLASS': 'django_redis.client.DefaultClient',
                  }
              }
          }
          ​

5.6. Ruby on Rails

Required Steps

  1. Install Ruby and Rails Framework

    • Install Ruby:
      • For Ubuntu/Debian:
        apt install -y ruby-full
      • For CentOS/RHEL:
        • Enable EPEL and DevTools:
          yum install -y epel-release
          yum groupinstall "Development Tools" -y
          ​
          Install Ruby:
          yum install -y ruby
        • Install Rails:
          gem install rails

          Set Up PostgreSQL or MySQL

          • Follow the database setup steps from the LAMP stack section:
            • Install PostgreSQL or MySQL.
            • Create a database and user for your Rails application.
          • Configure the database settings in the config/database.yml file.

        • Optional Steps

          1. Install Puma or Unicorn for App Server

            • Install Puma:
              gem install puma
            • Install Unicorn:
              gem install unicorn
          2. Configure Nginx

            • Use Nginx to route traffic to your Rails app running on Puma or Unicorn:
              • Create a new server block in /etc/nginx/sites-available/your-rails-app:
                server {
                    listen 80;
                    server_name yourdomain.com;
                    root /path/to/your/rails/app/public;
                
                    location / {
                        proxy_pass http://127.0.0.1:3000;
                        proxy_set_header Host $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    }
                }
                ​
                Enable the configuration:
                ln -s /etc/nginx/sites-available/your-rails-app /etc/nginx/sites-enabled/
              • Test and restart Nginx:
                nginx -t && systemctl restart nginx

5.7. Java Development

Required Steps

  1. Install OpenJDK

    • For CentOS:
      yum install -y java-11-openjdk
    • For Ubuntu:
      apt install -y openjdk-11-jdk
    • Verify the installation:
      java -version
  2. Install Apache Tomcat

    • Download Tomcat from the official website:
      wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.7/bin/apache-tomcat-10.1.7.tar.gz
    • Extract the Tomcat package:
      tar -xzf apache-tomcat-10.1.7.tar.gz -C /opt/
    • Rename the folder for convenience:
      mv /opt/apache-tomcat-10.1.7 /opt/tomcat
    • Set execution permissions for the bin directory:
      chmod +x /opt/tomcat/bin/*.sh
    • Start Tomcat:
      /opt/tomcat/bin/startup.sh
    • Access Tomcat in a browser:
      Navigate to http://your-server-ip:8080.

Optional Steps

Install Maven for Build Management

  • For Ubuntu/Debian:
    apt install -y maven
  • For CentOS/RHEL:
    Add the EPEL repository and install Maven:
    yum install -y maven
  • Verify the installation:
    mvn -version

5.8. Go Stack

Required
  1. Install Go Programming Language

    • Download the Go binary package:
      wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
    • Extract the package:
      tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz
    • Set up the environment variables by adding the following lines to /etc/profile or ~/.profile:
      export PATH=$PATH:/usr/local/go/bin
    • Apply the changes:
      source ~/.profile
    • Verify the installation:
      go version
  2. Install Compiler and Tools

    • Install GCC and build tools:
      For Ubuntu/Debian:
      apt install build-essential -y
      For CentOS/RHEL:
      yum groupinstall "Development Tools" -y
Optional
  • Configure Nginx or Apache for Static File Serving
    • Use Nginx or Apache to serve static files generated by your Go application.
    • Configure Nginx or Apache for Static File Serving

      • For Nginx:

        • Create a new server block in /etc/nginx/sites-available/your-go-app
          server {
              listen 80;
              server_name yourdomain.com;
              root /path/to/your/static/files;
          
              location / {
                  try_files $uri $uri/ =404;
              }
          }
          ​
          • Enable the configuration:
            ln -s /etc/nginx/sites-available/your-go-app /etc/nginx/sites-enabled/
          • Test and restart Nginx:
            nginx -t && systemctl restart nginx
        • For Apache:

          • Enable the mod_rewrite and mod_proxy modules:
            a2enmod rewrite proxy
          • Add a VirtualHost configuration in /etc/apache2/sites-available/your-go-app.conf
            <VirtualHost *:80>
                ServerName yourdomain.com
                DocumentRoot /path/to/your/static/files
            
                <Directory /path/to/your/static/files>
                    Options Indexes FollowSymLinks
                    AllowOverride All
                    Require all granted
                </Directory>
            </VirtualHost>
            ​
          • Enable the site and restart Apache:
            a2ensite your-go-app.conf && systemctl restart apache2

6. Development Tools and Utilities

Required Steps

  1. Git for Version Control
    • Git is a critical tool for tracking changes in source code and collaborating on development projects.
    • Install Git:
      • For Ubuntu/Debian: apt install git -y
      • For CentOS/RHEL: yum install git -y
    • Verify Installation: Run git --version to ensure Git is installed.
    • Configure Git:
      • Set username: git config --global user.name "Your Name"
      • Set email: git config --global user.email "your-email@example.com"

Optional Steps

  1. Docker and Docker Compose for Containerized Development

    • Install Docker:
      • For Ubuntu/Debian: apt install docker.io -y
      • For CentOS/RHEL: yum install docker -y
    • Enable Docker on Boot:
      • systemctl enable docker
    • Install Docker Compose:
      • Use pip: pip install docker-compose
    • Verify Installation:
      • Docker: docker --version
      • Docker Compose: docker-compose --version
  2. Build Tools (Make, GCC, CMake, Maven, etc.)

    • Install essential build tools for compiling software:
      • Ubuntu/Debian: apt install build-essential cmake -y
      • CentOS/RHEL: yum groupinstall "Development Tools" -y
    • Install Maven for Java projects:
      • apt install maven -y (Ubuntu)
      • yum install maven -y (CentOS)

7. Configuring Security

Required Steps

  1. Enabling a Firewall (CSF or UFW)

    • Install and Enable UFW (Ubuntu/Debian):
      • apt install ufw -y
      • Allow common ports: ufw allow ssh, ufw allow http, ufw allow https
      • Enable UFW: ufw enable
    • Install and Configure CSF (CentOS):
      • Install: yum install csf -y
      • Test mode: Edit /etc/csf/csf.conf and set TESTING=0
      • Allow SSH: Add your SSH port to TCP_IN and TCP_OUT.
  2. Securing SSH (Key-Based Authentication, Changing Default Port)

    • Set Up Key-Based Authentication:
      • Generate a key pair on your local machine: ssh-keygen
      • Copy the public key to the server: ssh-copy-id user@your-server-ip
    • Change the Default SSH Port:
      • Edit /etc/ssh/sshd_config and change the Port setting (e.g., Port 2222).
      • Restart SSH: systemctl restart sshd
  3. Installing Fail2Ban for Brute-Force Prevention

    • Install Fail2Ban:
      • Ubuntu/Debian: apt install fail2ban -y
      • CentOS/RHEL: yum install epel-release -y && yum install fail2ban -y
    • Enable and start the service: systemctl enable fail2ban && systemctl start fail2ban
  4. Setting Up Automatic Updates

    • Ubuntu/Debian:
      • Install unattended-upgrades: apt install unattended-upgrades -y
      • Enable it: dpkg-reconfigure --priority=low unattended-upgrades
    • CentOS/RHEL:
      • Install dnf-automatic: yum install dnf-automatic -y
      • Enable automatic updates: systemctl enable dnf-automatic && systemctl start dnf-automatic

Optional Steps

  1. Let’s Encrypt SSL Certificates

    • Install Certbot: apt install certbot python3-certbot-nginx -y (Ubuntu/Debian) or yum install certbot python3-certbot-nginx -y (CentOS).
    • Obtain an SSL certificate: certbot --nginx
    • Renew certificates: certbot renew --dry-run
  2. IDS/IPS Systems (e.g., Snort, Suricata)

    • Install Snort:
      • Ubuntu/Debian: apt install snort -y
      • CentOS: Install using EPEL or source.
    • Configure rules to monitor traffic and detect threats.

8. Monitoring and Performance Optimization

Required Steps

  1. Installing Basic Monitoring Tools
    • Install htop for real-time system monitoring:
      • Ubuntu/Debian: apt install htop -y
      • CentOS/RHEL: yum install htop -y
    • Use htop to monitor CPU, memory, and processes.

Optional Steps

  1. Advanced Monitoring (Netdata, Grafana)

    • Install Netdata:
      • Run the official installer: bash <(curl -Ss https://my-netdata.io/kickstart.sh)
    • Install Grafana:
      • Add the repository and install Grafana based on your OS.
  2. Caching Mechanisms (Memcached, Redis)

    • Install Redis:
      • Ubuntu/Debian: apt install redis -y
      • CentOS/RHEL: yum install redis -y
    • Install Memcached:
      • Ubuntu/Debian: apt install memcached -y
      • CentOS/RHEL: yum install memcached -y
  3. Performance Testing Tools (Apache Benchmark, Siege)

    • Install Apache Benchmark (ab):
      • apt install apache2-utils -y (Ubuntu/Debian)
    • Install Siege:
      • apt install siege -y (Ubuntu/Debian)
      • yum install siege -y (CentOS/RHEL)

9. Backup and Disaster Recovery

Required Steps

  1. Setting Up Regular Backups
    • Use tools like rsync or tar for manual backups:
      • Example: rsync -av /source /backup/
    • Schedule automated backups using cron:
      • Open cron editor: crontab -e
      • Add a backup job: 0 2 * * * tar -czf /backup/backup.tar.gz /data

Optional Steps

  1. Using DomainIndia VPS Snapshot Feature
    • Log in to the DomainIndia client area.
    • Navigate to the VPS snapshot section.
    • Create, restore, or manage snapshots to ensure quick recovery in case of failure.

10. Advanced Configurations for Multi-Stack Environments

Required Steps

  1. Managing Virtual Hosts (Apache/Nginx) for Hosting Multiple Apps

    • Apache:
      • Create a separate virtual host configuration for each application in /etc/httpd/conf.d/ (CentOS) or /etc/apache2/sites-available/ (Ubuntu).
      • Enable sites (Ubuntu): a2ensite your-site.conf
      • Restart Apache: systemctl restart httpd or systemctl restart apache2
    • Nginx:
      • Create separate server blocks for each app in /etc/nginx/sites-available/.
      • Symlink the configuration to /etc/nginx/sites-enabled/: ln -s /etc/nginx/sites-available/your-site /etc/nginx/sites-enabled/
      • Test and restart Nginx: nginx -t && systemctl restart nginx
  2. Setting Up Isolated Environments Using Docker or VMs

    • Docker:
      • Install Docker: apt install docker.io (Ubuntu) or yum install docker (CentOS).
      • Use docker-compose.yml to manage multi-container applications.
      • Example: Set up one container for MongoDB and another for the Node.js backend.
    • Virtual Machines:
      • Use KVM, VirtualBox, or VMware to create isolated environments for each application.
      • Allocate resources (CPU, RAM, storage) as needed.

Optional Steps

  1. Reverse Proxies for Multi-App Hosting
    • Use Nginx or Apache to route traffic based on the domain or subdomain:
      • Example: Route app1.example.com to one app and app2.example.com to another.

11. Best Practices for Staging and Production

Required Steps

  1. Configuring Separate Staging and Production Environments
    • Use separate VPS instances or virtual hosts for staging and production.
    • Ensure the staging environment mirrors the production setup (same stack, versions, and configurations).
    • Example:
      • Staging URL: staging.yourdomain.com
      • Production URL: www.yourdomain.com
    • Sync databases and files to ensure testing reflects the live environment.

Optional Steps

  1. Using CI/CD Pipelines (e.g., Jenkins, GitHub Actions)
    • Jenkins:
      • Install Jenkins: apt install jenkins (Ubuntu).
      • Configure pipelines for building, testing, and deploying applications automatically.
    • GitHub Actions:
      • Create a .github/workflows/deploy.yml file in your repository.
      • Define jobs for build, test, and deploy steps, triggered on push or merge.

12. FAQs and Troubleshooting

Common Installation Issues for Each Stack

  • Node.js: Missing dependencies or incompatible versions. Use nvm to manage Node.js versions.
  • Python: Virtualenv not activating. Ensure you use the correct source command.
  • MySQL/PostgreSQL: Authentication errors. Verify the database user credentials and bind-address in the configuration files.

Debugging Database and Web Server Errors

  • Database Errors:
    • Check logs in /var/log/mysql/ (MySQL) or /var/log/postgresql/ (PostgreSQL).
    • Ensure services are running: systemctl status mysql or systemctl status postgresql.
  • Web Server Errors:
    • Check Apache logs: /var/log/httpd/ or /var/log/apache2/
    • Check Nginx logs: /var/log/nginx/

Resolving Performance Bottlenecks

  • Use monitoring tools like htop to identify resource-hungry processes.
  • Optimize database queries with indexes.
  • Configure caching with tools like Redis or Memcached.
  • Enable Gzip or Brotli compression for web servers to reduce load times.

 

 


Was this answer helpful?

« Back