How to host your own blog in 15 minutes ?

Again, this is another no bullshit tech tutorial for perfectionists with deadlines.

Pre-requistics

  • You need to have a server for hosting your blog.
  • You also need a domain name. ( you can apply for one <yourname>.aiot.link domain for free!)
  • You need Docker had already installed on your host.
  • You need Traefik already setup on your host.
  • A cup of coffee and a cat’s companionship is a plus.

Prepare the environmental variables

Putting important and secret information in the environment variable ( here we use .env ) is an industry standard.

Open a folder with your favorite IDE or editor. Then create a file named as .env with the following content, remember to replace the information with your own.

# traefik
SERVICE_NAME=wp-service
DOMAIN_NAME=YOUR_DOMAIN.com
TLS_RESOLVER=le
SERVICE_PORT=80

# versions 
NGINX_VERSION=1.25-alpine
WORDPRESS_VERSION=6.3-fpm
MARIADB_VERSION=11.1
REDIS_VERSION=7.0-alpine

# database
MYSQL_ROOT_PASSWORD=YOUR_SECRET_PASSWORD
MYSQL_USER=db_user
MYSQL_PASSWORD=wnRhJ7yTYYU985

# wordpress 
WP_DEBUG=0Code language: PHP (php)

Create the Nginx Configuration file

In the rood dir where you put your .env file, create a folder named as conf.d and create a new file in it with the name of nginx.conf. ( by the way, the name of the config file actually really dose not matter, you name it whatever you like, but, we CS people like it name it with something intuitive…)

server {
        listen 80;
        listen [::]:80;

        server_name azat.cc;

        index index.php index.html index.htm;

        root /var/www/html;


        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass wordpress:9000;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location ~ /\.ht {
                deny all;
        }

        location = /favicon.ico {
                log_not_found off; access_log off;
        }
        location = /robots.txt {
                log_not_found off; access_log off; allow all;
        }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }
}

Code language: Nginx (nginx)

The Compose file for docker compose

services:
  proxy:
    image: nginx:${NGINX_VERSION}
    restart: always
    depends_on:
      - wordpress
    volumes:
      - ./conf.d/nginx.conf:/etc/nginx/conf.d/default.conf
      - azat-cc-wp-wordpress:/var/www/html
    networks:
      - wp
      - traefik-public
    labels:
      # Enable Traefik for this container
      - traefik.enable=true
      # HTTPS (web-secure) router and service
      - traefik.http.routers.${SERVICE_NAME}.rule=Host(`${DOMAIN_NAME}`)
      - traefik.http.routers.${SERVICE_NAME}.entrypoints=websecure
      - traefik.http.routers.${SERVICE_NAME}.tls=true
      - traefik.http.routers.${SERVICE_NAME}.tls.certresolver=${TLS_RESOLVER}
      - traefik.http.services.${SERVICE_NAME}.loadbalancer.server.port=${SERVICE_PORT}

  wordpress:
    image: wordpress:${WORDPRESS_VERSION}
    restart: unless-stopped
    environment:
      - WP_REDIS_HOST=redis
      - WP_DEBUG=${WP_DEBUG}
      - WORDPRESS_DB_HOST=database
      - WORDPRESS_DB_USER=${MYSQL_USER}
      - WORDPRESS_DB_PASSWORD=${MYSQL_PASSWORD}
      - WORDPRESS_DB_NAME=wordpress
    depends_on:
      - database
      - redis
    volumes:
      - azat-cc-wp-wordpress:/var/www/html
    networks:
      - wp

  database:
    image: mariadb:${MARIADB_VERSION}
    restart: unless-stopped
    command: '--default-authentication-plugin=mysql_native_password'
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=wordpress
    volumes:
      - azat-cc-wp-database:/var/lib/mysql
    networks:
      - wp

  redis:
    image: redis:${REDIS_VERSION}
    restart: unless-stopped
    entrypoint: redis-server --maxmemory 512mb --maxmemory-policy allkeys-lru
    volumes:
      - azat-cc-wp-redis:/data
    networks:
      - wp

networks:
  traefik-public:
    external: true
  wp:


volumes:
  azat-cc-wp-wordpress:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/azat/USB240/azat-cc-wp/wordpress
  azat-cc-wp-database:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/azat/USB240/azat-cc-wp/database
  azat-cc-wp-redis:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/azat/USB240/azat-cc-wp/redis
Code language: YAML (yaml)
Do you need help?

Contact for my professional consulting and technical support services. I also provide free consulting for students doing open source projects and NGOs.

Leave a Reply

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