WordPress with SSL using NGINX proxy and autorenew LetsEncrypt certificates on Oracle Cloud (OCI) Free Tier
Tags: oci, oraclecloud, wordpress, docker
Published: 2022-11-20 17:27:27


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oip8f405i6gnprvk29n3.jpeg)
### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rcqzbms8ozfkudu9kzo3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/havclmmsstkwzi8h3u9c.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vawae9zsocjt5gsmwrwy.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad2xsf53snwgc5rfhb4a.png)
#### Step-2: Install Docker Engine on Ubuntu
[https://docs.docker.com/engine/install/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
```
#### Step 3: Manage Docker as a non-root user
```
root> sudo usermod -aG docker ubuntu
root> newgrp docker
ubuntu> docker ps
```
#### Step 4: Configure Docker to start on boot with systemd
```
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
```
#### Step 5: Get free domain name from freenom.com

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/foafaiegkribdiuz1nrc.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eyzdgwbm38g4iarpou6n.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ucfljp373rctmpxzt1nm.png)
> Target: Ubuntu compute instance Public IP address

#### Step 6: Create docker-compose.yml
```
mkdir -p ~/wordpress/ && cd ~/wordpress/
vi docker-compose.yml
```

```
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: {}
```
```
docker compose up -d
```
[https://melihsavdert.ml/](https://melihsavdert.ml/)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vq7ulrtyqeom2a8ao9sf.png)