Server Administration

How We Deployed a wordpress website with Docker in 5 Mins

Get yourself organised and get more things done

Netpap was founded on the premise of collective success within the Internet service industry.To achieve this providers need to invest time,resources and knowledge in a highly competitive industry.

We have decided to document our tech skills,solutions to different challenges in the sector.A blog of how tos comes in handy.

How to deploy WordPress on a centos 7 VPS

ssh root@remoteserver

Create a directory and cd to the directory.

mkdir wordpress && cd wordpress

Create a docker compose file,config file

touch docker-compose.yml && touch uploads.ini

Copy and paste the code below in the docker-compose.yml

version: '3'
services:
  db:
    image: mariadb
    volumes:
      - db_data:/var/lib/mysql
    restart:  always
    environment:
      MYSQL_ROOT_PASSWORD:  rootpassword
      MYSQL_DATABASE:  databasename
      MYSQL_USER: database user
      MYSQL_PASSWORD:  database password


  wordpress:
    depends_on:
      - db
    image: wordpress:5.1.1-php7.3-apache
    ports:
      - "8020:80"
    restart:  always
    environment:
      WORDPRESS_DB_HOST:  db:3306
      WORDPRESS_DB_NAME: databasename
      WORDPRESS_DB_USER:  database user
      WORDPRESS_DB_PASSWORD:  database password
    working_dir: /var/www/html
    volumes:
      - ./wp-content:/var/www/html/wp-content
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

volumes:
  db_data:

Next Step:Update upload.ini settings with the following settings

file_uploads = on
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

Build project

docker-compose build .  && docker-compose up

Install NGINX

Install nginx to act as a reverse proxy between the internet and your wordpress container

yum install -y nginx  &&  systemctl start nginx && systemctl  enable nginx
touch /etc/nginx/conf.d/wordpress.conf 


server {
        listen 80;
      server_name example.co.ke;
location / {
       proxy_pass http://0.0.0.0:8020;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade';
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
    }
}


Restart nginx

systemctl start nginx

Visit the website example.co.ke to continue with blog customization.

docker ps -a to get a list containers

To access docker container use

docker exec -it container_name bash to enter the container bash terminal

Leave a Reply

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