DEV Community

melih
melih

Posted on

WordPress with SSL using NGINX proxy and autorenew LetsEncrypt certificates on Oracle Cloud (OCI) Free Tier

Image description

Introduction

Oracle cloud provides free resources. You can follow the steps below to host your WordPress website on OCI for free.

Environment

  • Ubuntu Server
  • Docker and compose plugin
  • Domain name

Installation

Step-1: Create compute instance

I’ll continue with the manual installation to go through the steps in case you want to install it manually. In the web console, click the navigation menu on the upper left side and select Compute > Instances. Click on Create Instance. I’ll choose the name "wordpress" and Ubuntu 22.04 Minimal.

Image description

Image description

Image description

Image description

Step-2: Install Docker Engine on Ubuntu

https://docs.docker.com/engine/install/ubuntu/

sudo apt-get update

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
Enter fullscreen mode Exit fullscreen mode

Step 3: Manage Docker as a non-root user

root> sudo usermod -aG docker ubuntu
root> newgrp docker
ubuntu> docker ps
Enter fullscreen mode Exit fullscreen mode

Step 4: Configure Docker to start on boot with systemd

sudo systemctl enable docker.service
sudo systemctl enable containerd.service
Enter fullscreen mode Exit fullscreen mode

Step 5: Get free domain name from freenom.com

Image description

Image description

Image description

Target: Ubuntu compute instance Public IP address

Step 6: Create docker-compose.yml

mkdir -p ~/wordpress/ && cd ~/wordpress/
vi docker-compose.yml
Enter fullscreen mode Exit fullscreen mode
version: '3.9'

services:

  nginx-proxy:
    image: nginxproxy/nginx-proxy
    container_name: nginx-proxy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro

  acme-companion:
    image: nginxproxy/acme-companion
    container_name: nginx-proxy-acme
    restart: always
    environment:
      - DEFAULT_EMAIL=mail@yourdomain.tld
    volumes_from:
      - nginx-proxy
    volumes:
      - certs:/etc/nginx/certs:rw
      - acme:/etc/acme.sh
      - /var/run/docker.sock:/var/run/docker.sock:ro

  mysql:
    image: mysql:latest
    container_name: mysql
    volumes:
      - db:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      -  db:/var/lib/mysql

  wordpress:
    depends_on:
      - mysql
    image: wordpress:latest
    container_name: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      VIRTUAL_HOST: melihsavdert.ml
      LETSENCRYPT_HOST: melihsavdert.ml
      LETSENCRYPT_EMAIL: yourname@email.com
    volumes:
      - wordpress:/var/www/html

volumes:
  conf: {}
  vhost: {}
  html: {}
  certs: {}
  acme: {}
  db: {}
  wordpress: {}
Enter fullscreen mode Exit fullscreen mode
docker compose up -d
Enter fullscreen mode Exit fullscreen mode

https://melihsavdert.ml/

Image description

Top comments (1)

Collapse
 
thx64tech profile image
thx64

I try the docker-compose.yml, but i get 500 Internal Server error