How to set up a VPS for the first time: A beginner’s tutorial. 

Setting up a VPS for the first time can seem daunting, but it’s a rewarding experience that gives you much more control over your web presence. This tutorial will guide you through the basic steps. We’ll focus on a common scenario: a Linux-based VPS (Ubuntu or CentOS are popular choices) for hosting a website.

Prerequisites:

  1. Purchased a VPS: You’ll need to have already chosen a VPS provider (e.g., DigitalOcean, Linode, Vultr, AWS Lightsail, Google Cloud, Contabo, etc.) and completed the purchase process.
  2. SSH Client:
    • Windows: PuTTY, MobaXterm, or Windows Terminal (with OpenSSH client installed).
    • macOS/Linux: Terminal (OpenSSH client is usually pre-installed).
  3. Basic Command Line Knowledge (Optional but helpful): Knowing how to navigate directories and run basic commands will be beneficial, but we’ll cover the essentials.

Step 1: Access Your VPS via SSH

After purchasing your VPS, your provider will typically give you:

  • IP Address: The unique address of your server (e.g., 192.0.2.1).
  • Root Username: Usually root.
  • Password: A temporary password or instructions to set one.

Using an SSH Client:

  • Windows (PuTTY):
    1. Open PuTTY.
    2. In the “Host Name (or IP address)” field, enter your VPS’s IP address.
    3. Click “Open.”
    4. If prompted with a security alert about the host key, click “Accept” or “Yes” to trust the server.
    5. A terminal window will open. Type root for the username and press Enter.
    6. Enter the password (it won’t show characters as you type) and press Enter.
  • macOS/Linux (Terminal):
    1. Open your Terminal application.
    2. Type the following command, replacing your_vps_ip with your actual IP address:
      Bash

      ssh root@your_vps_ip
      
    3. If prompted about authenticity, type yes and press Enter.
    4. Enter your password when requested.

You are now logged into your VPS! You’ll see a command prompt, usually ending with # (e.g., root@yourhostname:~#).


Step 2: Initial Server Setup and Security Best Practices

This is crucial for securing your server right from the start.

  1. Change the Root Password (If not done during setup):

    • Type: passwd
    • Enter a strong new password twice. Use a mix of uppercase, lowercase, numbers, and symbols.
    • Self-note: Store this password securely!
  2. Update Your Server’s Software: It’s vital to ensure all your server’s packages are up to date to patch security vulnerabilities and get the latest features.

    • For Ubuntu/Debian:
      Bash

      sudo apt update
      sudo apt upgrade -y
      
    • For CentOS/RHEL:
      Bash

      sudo yum update -y
      

    (Note: sudo allows you to run commands with superuser privileges. You’ll be prompted for your password.)

  3. Create a New Sudo User (Highly Recommended): Logging in as root is powerful but risky. It’s better to create a standard user for daily tasks and use sudo for administrative commands.

    • For Ubuntu/Debian:
      Bash

      adduser your_username
      usermod -aG sudo your_username
      

      (Replace your_username with your desired username. You’ll be prompted to set a password and fill in some optional information.)

    • For CentOS/RHEL:
      Bash

      adduser your_username
      passwd your_username # Set password for the new user
      usermod -aG wheel your_username # 'wheel' group grants sudo access on CentOS
      
  4. Configure a Firewall (UFW for Ubuntu, firewalld for CentOS): A firewall blocks unwanted traffic and allows only necessary connections (like SSH, HTTP, HTTPS).

    • For Ubuntu (using UFW – Uncomplicated Firewall):

      Bash

      sudo apt install ufw # Install UFW if not already installed
      sudo ufw allow OpenSSH # Allow SSH connections (so you don't lock yourself out)
      sudo ufw enable # Enable the firewall
      sudo ufw status # Check status
      

      (You’ll later open ports for HTTP/HTTPS once you install a web server.)

    • For CentOS (using firewalld):

      Bash

      sudo systemctl start firewalld
      sudo systemctl enable firewalld
      sudo firewall-cmd --permanent --add-service=ssh # Allow SSH
      sudo firewall-cmd --reload # Apply changes
      sudo firewall-cmd --list-all # Check status
      
  5. Disable Root Login via SSH (Strongly Recommended): This prevents direct login attempts as the root user, forcing access through your new sudo user.

    • Login as your new sudo user first! Open a new SSH session and log in with your your_username and its password.
    • Then, from your new user’s session:
      Bash

      sudo nano /etc/ssh/sshd_config
      
    • Find the line PermitRootLogin yes and change it to PermitRootLogin no.
    • Save and exit (Ctrl+X, Y, Enter for nano).
    • Restart the SSH service:
      • Ubuntu: sudo systemctl restart sshd
      • CentOS: sudo systemctl restart sshd

    Now, you can no longer log in directly as root via SSH. Always use your new sudo user.


Step 3: Install a Web Server (e.g., Apache or Nginx)

This software delivers your website content to visitors.

  • Option A: Apache (Very common for beginners)

    • Ubuntu/Debian:
      Bash

      sudo apt install apache2 -y
      sudo ufw allow 'Apache' # Allow Apache traffic through firewall
      sudo systemctl status apache2 # Check if it's running
      
    • CentOS/RHEL:
      Bash

      sudo yum install httpd -y
      sudo systemctl start httpd
      sudo systemctl enable httpd
      sudo firewall-cmd --permanent --add-service=http # Allow HTTP
      sudo firewall-cmd --permanent --add-service=https # Allow HTTPS (for later SSL)
      sudo firewall-cmd --reload
      sudo systemctl status httpd
      
    • Test: Open your web browser and navigate to your VPS’s IP address. You should see the default Apache welcome page.
  • Option B: Nginx (Known for high performance, often used with static sites or as a reverse proxy)

    • Ubuntu/Debian:
      Bash

      sudo apt install nginx -y
      sudo ufw allow 'Nginx HTTP' # Allow HTTP traffic
      sudo systemctl status nginx
      
    • CentOS/RHEL:
      Bash

      sudo yum install nginx -y
      sudo systemctl start nginx
      sudo systemctl enable nginx
      sudo firewall-cmd --permanent --add-service=http
      sudo firewall-cmd --permanent --add-service=https
      sudo firewall-cmd --reload
      sudo systemctl status nginx
      
    • Test: Open your web browser and navigate to your VPS’s IP address. You should see the default Nginx welcome page.

Step 4: Install a Database Server (e.g., MySQL/MariaDB)

If your website uses a database (like WordPress), you’ll need one.

  • For MySQL (Ubuntu/Debian):

    Bash

    sudo apt install mysql-server -y
    sudo mysql_secure_installation # Run security script
    

    (Follow the prompts. Choose “Y” for most questions, set a strong root password, remove anonymous users, disallow remote root login, and remove test database.)

  • For MariaDB (CentOS/RHEL):

    Bash

    sudo yum install mariadb-server mariadb -y
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    sudo mysql_secure_installation # Run security script (similar prompts to MySQL)
    

Step 5: Install PHP (If Your Website Uses It, e.g., WordPress)

Most dynamic websites (like WordPress, Joomla, Drupal) are built with PHP.

  • For Apache (Ubuntu/Debian):

    Bash

    sudo apt install php libapache2-mod-php php-mysql -y
    sudo systemctl restart apache2
    
  • For Nginx (Ubuntu/Debian – requires PHP-FPM):

    Bash

    sudo apt install php-fpm php-mysql -y
    sudo systemctl start php-fpm
    sudo systemctl enable php-fpm
    

    (You’ll also need to configure Nginx to process PHP files – this is more advanced and involves editing Nginx’s site configuration files to pass .php requests to php-fpm. For a beginner, Apache is often simpler to start with for PHP sites.)

  • For CentOS/RHEL (Apache or Nginx – using EPEL and Remi repositories for recent PHP versions):

    Bash

    sudo yum install epel-release -y
    sudo yum install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y # For CentOS 8+
    # For CentOS 7: sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
    sudo yum module enable php:remi-8.1 # Or whatever PHP version you want (e.g., 8.2, 8.3)
    sudo yum install php php-mysqlnd php-fpm -y # php-fpm for Nginx, php for Apache
    
    • If using Apache: sudo systemctl restart httpd
    • If using Nginx: sudo systemctl start php-fpm && sudo systemctl enable php-fpm && sudo systemctl restart nginx

Step 6: Deploy Your Website

Now, put your website files onto the server.

  1. Locate the Web Root Directory:

    • Apache (Ubuntu/Debian): /var/www/html/
    • Apache (CentOS/RHEL): /var/www/html/
    • Nginx (Ubuntu/Debian): /var/www/html/ (or often /usr/share/nginx/html/ by default, but /var/www/html/ is common for custom sites)
    • Nginx (CentOS/RHEL): /usr/share/nginx/html/
  2. Transfer Files: You can use:

    • SCP (Secure Copy Protocol): Built into Linux/macOS terminals, or available via tools like WinSCP on Windows.
      Bash

      # From your local machine to VPS:
      scp -r /path/to/your/local/website/files your_username@your_vps_ip:/var/www/html/
      
    • SFTP (SSH File Transfer Protocol): A more user-friendly graphical interface (e.g., FileZilla, WinSCP). Connect using your VPS IP, your_username, and password, then drag and drop files to the web root.
  3. Set File Permissions (Crucial for Security):

    • The web server (e.g., www-data user for Apache/Nginx on Ubuntu, apache user for Apache on CentOS, nginx user for Nginx on CentOS) needs read access to your files and write access to specific directories (like wp-content for WordPress).
    • A common starting point (adjust as needed for specific applications):
      Bash

      sudo chown -R your_username:www-data /var/www/html/your_website_folder # Or the web root
      sudo chmod -R 755 /var/www/html/your_website_folder
      sudo find /var/www/html/your_website_folder -type d -exec chmod g+s {} \; # For directory permissions
      # For writeable folders (e.g., WordPress uploads):
      sudo chmod -R 775 /var/www/html/your_website_folder/wp-content/uploads
      
  4. Configure Your Web Server (Virtual Hosts): If you’re hosting multiple websites or using a domain name, you’ll need to set up a virtual host (Apache) or server block (Nginx).

    • Apache Example (Ubuntu):
      Bash

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

      Add content like this:

      Apache

      <VirtualHost *:80>
          ServerAdmin webmaster@your_domain.com
          ServerName your_domain.com
          ServerAlias www.your_domain.com
          DocumentRoot /var/www/html/your_website_folder
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      
          <Directory /var/www/html/your_website_folder>
              Options Indexes FollowSymLinks
              AllowOverride All
              Require all granted
          </Directory>
      </VirtualHost>
      

      Enable the site and restart Apache:

      Bash

      sudo a2ensite your_domain.conf
      sudo systemctl restart apache2
      
    • Nginx Example (Ubuntu):
      Bash

      sudo nano /etc/nginx/sites-available/your_domain.conf
      

      Add content like this (for static HTML, add index.html to index directive; for PHP, add index.php and uncomment the location ~ \.php$ block):

      Nginx

      server {
          listen 80;
          listen [::]:80;
      
          root /var/www/html/your_website_folder;
          index index.html index.htm index.nginx-debian.html;
      
          server_name your_domain.com www.your_domain.com;
      
          location / {
              try_files $uri $uri/ =404;
          }
      
          # For PHP websites (uncomment and configure php-fpm socket path)
          # location ~ \.php$ {
          #    include snippets/fastcgi-php.conf;
          #    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Adjust PHP version
          # }
      }
      

      Link to sites-enabled and restart Nginx:

      Bash

      sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/
      sudo nginx -t # Test configuration
      sudo systemctl restart nginx
      

Step 7: Point Your Domain Name to Your VPS

  1. Go to your domain registrar’s DNS management page.
  2. Find your DNS records.
  3. Edit or add an A record:
    • Host/Name: @ (for the main domain)
    • Value/IP Address: Your VPS’s IP address
    • TTL (Time To Live): Often 3600 (1 hour) or less for faster propagation.
  4. Add a CNAME record for www (optional but recommended):
    • Host/Name: www
    • Value: your_domain.com (or @)
  5. Save the changes. DNS propagation can take a few minutes to up to 48 hours, but usually much faster.

Step 8: Install SSL (HTTPS) – Highly Recommended

Once your domain is pointing to your VPS, secure your website with an SSL certificate using Let’s Encrypt and Certbot. This is free and essential for security and SEO.

  • For Apache (Ubuntu):

    Bash

    sudo snap install core
    sudo snap refresh core
    sudo snap install --classic certbot
    sudo ln -s /snap/bin/certbot /usr/bin/certbot
    sudo certbot --apache
    

    Follow the prompts.

  • For Nginx (Ubuntu):

    Bash

    sudo snap install core
    sudo snap refresh core
    sudo snap install --classic certbot
    sudo ln -s /snap/bin/certbot /usr/bin/certbot
    sudo certbot --nginx
    

    Follow the prompts.

  • For CentOS (Apache/Nginx):

    Bash

    sudo yum install epel-release -y
    sudo yum install certbot python3-certbot-apache -y # For Apache
    # Or: sudo yum install certbot python3-certbot-nginx -y # For Nginx
    sudo certbot --apache # Or --nginx
    

    Follow the prompts.

After this, your site should be accessible via https://your_domain.com.


Step 9: Ongoing Maintenance

  • Regular Updates: Log in periodically and run sudo apt update && sudo apt upgrade -y (Ubuntu) or sudo yum update -y (CentOS).
  • Backups: Set up an automated backup solution. Your VPS provider might offer this, or you can use tools like rsync or cloud storage solutions.
  • Monitoring: Keep an eye on server resource usage (CPU, RAM, disk space). Tools like htop (install with sudo apt install htop or sudo yum install htop) are useful.
  • Security: Stay informed about common vulnerabilities and best practices.

This tutorial covers the absolute basics. A VPS offers immense power, but with that comes responsibility. Don’t be afraid to search online for specific issues or configurations you encounter. Good luck!

Hot this week

What People Are Saying About Justin Bieber’s New Album, Swag

Justin Bieber’s surprise album, Swag, has set social media...

Justin Bieber’s “Swag”: 5 Reasons His Surprise Album Is His Most Personal and Powerful Yet

Justin Bieber has shocked and delighted fans with the...

Justin Bieber Drops Surprise Album “Swag”—Here’s Everything You Need to Know

Pop superstar Justin Bieber is back—and he’s brought the...

Why Is My Check Engine Light Flashing?

First things first: If your check engine light is flashing...

How to Get Rid of Fruit Flies in the Kitchen—Fast

1. Find the Source First, channel your inner detective. Fruit...

Topics

What People Are Saying About Justin Bieber’s New Album, Swag

Justin Bieber’s surprise album, Swag, has set social media...

Justin Bieber Drops Surprise Album “Swag”—Here’s Everything You Need to Know

Pop superstar Justin Bieber is back—and he’s brought the...

Why Is My Check Engine Light Flashing?

First things first: If your check engine light is flashing...

How to Get Rid of Fruit Flies in the Kitchen—Fast

1. Find the Source First, channel your inner detective. Fruit...

How to Recover a Deleted Instagram Account

First, Let’s Clear Up: Deleted vs. Deactivated Deactivated (Temporarily...

How to Fix “Payment Not Processing” on PayPal

1. Double-Check Your Payment Information Make sure your card...

Why Can’t I Add My Debit Card to Apple Pay?

Trying to add your debit card to Apple Pay...
spot_img

Related Articles

Popular Categories

spot_imgspot_img