Skip to content
Go back

Hosting wordpress website using just Docker and domain name with ssl in simple steps.

Published:

simple step-by-step guide to host WordPress website using Docker:


1. Install Docker & Docker Compose

If not already installed:

sudo apt install docker.io docker-compose -y
sudo systemctl enable docker
sudo systemctl start docker

output


2. Create a Project Directory

mkdir Docker-wordpress && cd Docker-wordpress

3. Create docker-compose.yml

Make a file called docker-compose.yml:

version: "3.9"

services:
  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: janak
      WORDPRESS_DB_PASSWORD: janak0ff
      WORDPRESS_DB_NAME: janak
    volumes:
      - ./wordpress_data:/var/www/html

  db:
    image: mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: janak0ff
      MYSQL_DATABASE: janak
      MYSQL_USER: janak
      MYSQL_PASSWORD: janak0ff
    volumes:
      - ./db_data:/var/lib/mysql

volumes:
  wordpress_data:
  db_data:

4. Start Containers

docker-compose up -d

output


5. Access WordPress

Open in browser:

http://192.168.63.132:8080

output output


Hosting it with Apache Web Server

Apache HTTP Server is one of the most widely used open-source web servers. It allows you to host websites and applications, handle multiple domains on a single server, and even act as a reverse proxy to route traffic to backend applications running on different ports.


When you install Apache on a server, it listens on specific ports (by default, port 80 for HTTP and 443 for HTTPS). Apache uses Virtual Hosts to serve different websites or applications depending on the domain name or port.

There are two main types of web hosting with Apache:

  1. Direct Hosting (Static/Dynamic Files)

    • Apache directly serves HTML, PHP, CSS, and JavaScript files from a directory.
    • Example: A WordPress site hosted in /var/www/html/.
  2. Reverse Proxy Hosting

    • Apache doesn’t serve the app directly. Instead, it forwards incoming requests to a backend service running on another port (e.g., Node.js on 3000, Python Flask on 5000, or WordPress on 8080).
    • This is useful when your application runs on its own port but you want users to access it via a domain name.

  1. Install Apache

    sudo apt update
    sudo apt install apache2 -y
  2. Enable Required Apache Modules For reverse proxy hosting:

    sudo a2enmod proxy
    sudo a2enmod proxy_http
    sudo a2enmod headers
    sudo systemctl restart apache2
  3. Create a VirtualHost Configuration Example: /etc/apache2/sites-available/wp.conf

    <VirtualHost *:80>
        ServerName wp.janakkumarshrestha0.com.np
    
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/
    
        ErrorLog ${APACHE_LOG_DIR}/wp-error.log
        CustomLog ${APACHE_LOG_DIR}/wp-access.log combined
    </VirtualHost>
  1. Enable the Site and Reload Apache

    sudo a2ensite wp.conf
    sudo systemctl reload apache2
  2. Point Your Domain to the Server In your DNS settings, create an A record for wp.janakkumarshrestha0.com.np pointing to your server’s public IP.

output

  1. Access Your Application Now your app running internally on http://127.0.0.1:8080/ will be accessible via:

    http://wp.janakkumarshrestha0.com.np/

Enabling HTTPS with Let’s Encrypt SSL in Apache

Let’s Encrypt is a free, automated, and open Certificate Authority (CA) that provides SSL/TLS certificates to enable HTTPS. Combined with Certbot, we can easily install and configure SSL for our Apache-hosted site.


Steps to Enable SSL on Apache

1. Install Certbot and Apache Plugin

On Debian/Ubuntu:

sudo apt update
sudo apt install certbot python3-certbot-apache -y

2. Run Certbot for Your Domain

Use Certbot to automatically fetch and configure an SSL certificate:

sudo certbot --apache -d wp.janakkumarshrestha0.com.np

During the process, Certbot will:

3. Test the SSL Setup

Once finished, open:

https://wp.janakkumarshrestha0.com.np/

4. Auto-Renewal (Important!)

Let’s Encrypt certificates are valid for 90 days. Certbot automatically creates a cron job for renewal. You can test it with:

sudo certbot renew --dry-run

What Happens Behind the Scenes

After running Certbot, Apache will have a new VirtualHost block for HTTPS in /etc/apache2/sites-enabled/wp-le-ssl.conf, similar to:

<VirtualHost *:443>
    ServerName wp.janakkumarshrestha0.com.np

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    ErrorLog ${APACHE_LOG_DIR}/wp-error.log
    CustomLog ${APACHE_LOG_DIR}/wp-access.log combined

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/wp.janakkumarshrestha0.com.np/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/wp.janakkumarshrestha0.com.np/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

✅ Conclusion

By setting up Let’s Encrypt SSL with Apache, we:

Now your web application is hosted professionally with HTTPS at: 👉 https://wp.janakkumarshrestha0.com.np/

output


Thank You



Suggest Changes

Previous Post
Guide to LVM on Ubuntu
Next Post
Step to install VMware Workstation on a Linux system.