Skip to content

Instantly share code, notes, and snippets.

@mt-shihab26
Last active March 27, 2023 22:34
Show Gist options
  • Select an option

  • Save mt-shihab26/9f94413fea98deb1b536f2d545af8cf2 to your computer and use it in GitHub Desktop.

Select an option

Save mt-shihab26/9f94413fea98deb1b536f2d545af8cf2 to your computer and use it in GitHub Desktop.

PHP & MySQL Docker Development Enviroment

Commends

$ docker-compose up -d --remove-orphans

# To Tear Down
$ docker-compose down --volumes

When ever any permission error just run

sudo chmod 777 -R <the-wp-site>

Steps to create dev env

create there files docker-compose.yml, php.dockerfile, nginx.conf in root of the project

docker-compose.yml file content

version: '3'

services:
  mysql:
    image: mysql:8
    volumes:
      - ./mysql_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: ecommerce_db
    networks:
      - net
  phpmyadmin:
    depends_on:
      - mysql
    image: phpmyadmin/phpmyadmin:5
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORD: password
    networks:
      - net
  php:
    depends_on:
      - mysql
    build:
      context: .
      dockerfile: ./php.dockerfile
    restart: always
    volumes:
      - ./:/var/www/html
    command: bash -c "chmod -R 777 /var/www/html/media && docker-php-entrypoint php-fpm"
    networks:
      - net
  nginx:
    depends_on:
      - php
    image: nginx:1
    restart: always
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www/html
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    networks:
      - net
networks:
  net:

php.dockerfile file content

FROM php:8-fpm

RUN docker-php-ext-install pdo pdo_mysql

WORKDIR /var/www/html

EXPOSE 9000

nginx.conf file content

server {
    listen 80;
    index index.php index.html;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;

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

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment