Cài đặt LEMP để chạy Wordpress sử dụng Docker
1. NGINX
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- './app:/var/www/html'
- './config/nginx:/etc/nginx/conf.d'
2. MySQL (MariaDB)
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- './app:/var/www/html'
- './config/nginx:/etc/nginx/conf.d'
mariadb:
image: mariadb:10.3.9
container_name: mariadb
restart: 'on-failure'
environment:
MYSQL_ROOT_PASSWORD: lab-skywirex
volumes:
- ${PWD}
Luc nay co the truy cap vao container mariadb de thuc thi cau lenh SQL
docker-compose exec mariadb bash
mysql_secure_installation ##Tuy chon
mysql -u root -p
TYPE MYSQL PASSWORD: lab-skywirex
3. PHPFPM
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- './app:/var/www/html'
- './config/nginx:/etc/nginx/conf.d'
links:
- 'phpfpm'
mariadb:
image: mariadb:10.3.9
container_name: mariadb
restart: 'on-failure'
environment:
MYSQL_ROOT_PASSWORD: lab-skywirex
volumes:
- ${PWD}
phpfpm:
image: php:7.3-fpm
container_name: phpfpm
volumes:
- './app:/var/www/html'
Nhưng do phiên bản PHP mặc định không hỗ trợ các extension như zip hoặc curl nên cần phải build docker image hỗ trợ các extension này
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- './app:/var/www/html'
- './config/nginx:/etc/nginx/conf.d'
links:
- 'phpfpm'
mariadb:
image: mariadb:10.3.9
container_name: mariadb
restart: 'on-failure'
environment:
MYSQL_ROOT_PASSWORD: lab-skywirex
volumes:
- ${PWD}
phpfpm:
# image: php:7.3-fpm-alpine
build:
context: ./docker
dockerfile: php.Dockerfile
container_name: phpfpm
volumes:
- './app:/var/www/html'
sudo nano ./config/nginx/nginx.conf
Nội dung file nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
sudo nano $HOME/LEMP/app/test.php
Kiem tra su lam viec
http://SERVER-IP/test.php
docker-compose exec mariadb bash
mysql -u root -p
TYPE MYSQL PASSWORD: lab-skywirex
Thu thi cac cau lenh MySQL
create database skywirex charset utf8;
create user 'skywire'@'localhost' identified by 'passcuaban';
grant all privileges on skywirex.* to 'skywire'@'localhost' with grant option;
flush privileges;
exit
Tùy chỉnh:
Tham khao
https://linoxide.com/containers/setup-lemp-stack-docker/
https://computingforgeeks.com/how-to-install-latest-docker-compose-on-linux/