Painless Way of Setting Up Hostinger VPS with Ubuntu and HestiaCP

Painless Way of Setting Up Hostinger VPS with Ubuntu and HestiaCP

Setting up a Hostinger VPS with Ubuntu and HestiaCP can be a streamlined process with the right approach and attention to detail.

After much trial and error, this guide represents the definitive approach to setting up a Hostinger VPS with Ubuntu and HestiaCP. For users managing their own servers, the challenge often lies in balancing efficiency with accuracy while avoiding the common pitfalls of misconfigured DNS, SSL issues, or incomplete installations. This step-by-step guide is the culmination of refining the process to ensure that future installations are seamless and painless.

Whether you’re a seasoned administrator or a beginner stepping into the world of self-hosting, this guide covers everything you need to know—from setting up your server and domain to configuring DNS, securing SSL certificates, and ensuring reliable email functionality. The goal is simple: empower you to create a robust hosting environment with minimal headaches.


Table of Contents


1. Initial Setup

Buy a Domain and VPS: Purchase a domain name and a VPS plan from Hostinger with Ubuntu preinstalled.

Set Hostname:

Use Hostinger’s hPanel VPS interface to set the hostname to your domain (e.g., yourdomain.com). This simplifies mail configuration.

Hostinger VPS management panel

Check Hostname:

hostname 
hostname -f

Ping VPS:

    ping yourdomain.com

    2. Configuring SSL Certificates for the Server

    SSL Certificates

    1. Root Account: In HestiaCP, generate an SSL certificate for the default hostname (hostname.yourhostinger.com).
    2. Standard User: Create another SSL certificate for yourdomain.com.

    Caveat on DNS Management

    HestiaCP generates its own DNS records by default. Use dig to identify which DNS service is active (Hostinger or Hestia):

    Hestia DNS Zone Editor
    Hostinger HPanel Zone Editor
    dig yourdomain.com NS

    If you see Hostinger’s nameservers, all records should be configured in Hostinger’s DNS zone editor. Using Hostinger’s DNS ensures fewer conflicts and easier management.


    3. DNS Configuration

    Hostinger DNS Records

    Add the following to Hostinger’s DNS zone editor:

    1. A Records:
      • @ → VPS IP address
      • mail → VPS IP address
      • webmail → VPS IP address
    2. CNAME Record:
      • wwwyourdomain.com
    3. MX Record:
      • Priority: 10, Value: mail.yourdomain.com
    4. TXT Records:
      • SPF: v=spf1 a mx ip4:<VPS IP> ~all
      • DKIM: Add the value generated by Hestia for your domain.
      • DMARC: v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com

    4. Non-Root Account Setup

    1. Add Domain Configurations: In HestiaCP, under a standard user, add web, DNS, and mail configurations for yourdomain.com.
    2. Generate SSL Certificates: Issue SSL certificates for the website and mail server.
    3. Update Hostinger DNS: Copy Hestia-generated DNS records for SPF, DKIM, and MX into Hostinger’s DNS zone editor.
    4. Verify DNS Records:
      • Check NS Records: dig yourdomain.com NS
      • Check A Records: dig yourdomain.com A
      • Check MX Record: dig yourdomain.com MX
      • Check SPF Record: dig yourdomain.com TXT
      • Check DKIM Record:dig default._domainkey.yourdomain.com TXT
      • Check DMARC Record: dig _dmarc.yourdomain.com TXT
    dig yourdomain.com NS
    dig yourdomain.com A 
    dig mail.yourdomain.com A 
    dig webmail.yourdomain.com A
    dig yourdomain.com MX
    dig yourdomain.com TXT
    dig default._domainkey.yourdomain.com TXT
    dig _dmarc.yourdomain.com TXT

    5. Email Setup and Verification

    Create Email Accounts:

    • Set up email accounts in HestiaCP under mail.yourdomain.com.

    Generate Mail SSL Certificate:

    • Generate SSL certificates specifically for the mail server.

    Test Mail Functionality:

    SMTP with Telnet:

    telnet mail.yourdomain.com 587
    EHLO yourdomain.com
    MAIL FROM:<your-email@yourdomain.com>
    RCPT TO:<recipient-email@example.com>
    DATA
    Subject: Test Email
    This is a test email.
    .
    QUIT

    Check SMTP with OpenSSL:

    openssl s_client -connect mail.yourdomain.com:587 -starttls smtp

    Verify Authentication Records:

    Use online tools like MXToolbox to confirm SPF, DKIM, and DMARC.


    6. Installing Roundcube for Webmail

    Install Roundcube:

    apt install -y roundcube roundcube-core roundcube-mysql roundcube-plugins

    Follow the terminal prompts to configure Roundcube:

    • Select MySQL.
    • Provide the MySQL credentials generated during HestiaCP setup.

    Verify Roundcube Installation: Access it via https://webmail.yourdomain.com.


    7. Testing the Webmail Setup

    Access Roundcube:

    • Log in and send test emails.

    Debug Errors:

    • Check logs for SSL certificate errors.
    • Ensure TLS is active and port 587 is open.
    • Test Webmail with Scripts:

    Example test using CodeIgniter:

    $config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'mail.yourdomain.com',
        'smtp_port' => 587,
        'smtp_user' => 'your-email@yourdomain.com',
        'smtp_pass' => 'your-password',
        'smtp_crypto' => 'tls',
        'mailtype'  => 'html',
        'charset'   => 'utf-8'
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->to('recipient@example.com');
    $this->email->from('your-email@yourdomain.com', 'Your Name');
    $this->email->subject('Test Email');
    $this->email->message('<p>This is a test email.</p>');
    $this->email->send();
    

    Checklist for Future Installations

    Initial Setup

    • Purchase domain and VPS.
    • Set hostname to match the domain.

    SSL Certificates

    • Root: Generate SSL for the default Hostinger domain.
    • User: Generate SSL for yourdomain.com.

    DNS Configuration

    • Add A, MX, SPF, DKIM, CNAME, and DMARC records in Hostinger DNS.

    Email Setup

    • Create email accounts in HestiaCP.
    • Issue mail server SSL certificate.

    Verify Records

    • Use dig for A, MX, TXT (SPF, DKIM, DMARC) checks.
    • Test SMTP using telnet and openssl.

    Roundcube Installation

    • Install Roundcube using apt.
    • Configure MySQL during installation.
    • Test https://webmail.yourdomain.com.

    Conclusion

    By following this guide, setting up a Hostinger VPS with Ubuntu and HestiaCP can be an efficient process. From DNS management to email configuration and webmail testing, each step has been outlined for precision and reliability. With this workflow, future installations can be streamlined, ensuring robust hosting services tailored to your domain’s needs.

    Leave a Reply

    Your email address will not be published. Required fields are marked *