Dokcer容器分布式搭建LNMP+wordpress论坛
以下是使用Docker搭建LNMP环境并部署WordPress论坛的基本步骤:
- 安装Docker:确保你的系统上安装了Docker。
- 编写
docker-compose.yml
文件:
version: '3'
services:
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx:/etc/nginx/conf.d
- ./html:/usr/share/nginx/html
depends_on:
- php
- mysql
networks:
- lnmp-network
php:
image: php:7.4-fpm
volumes:
- ./html:/usr/share/nginx/html
networks:
- lnmp-network
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- dbdata:/var/lib/mysql
networks:
- lnmp-network
volumes:
dbdata:
networks:
lnmp-network:
driver: bridge
- 创建
nginx
目录并编写配置文件default.conf
:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
error_page 404 /404.html;
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
- 在
html
目录中创建index.php
文件,用于连接MySQL和处理WordPress安装:
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'mysql');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique key here');
define('SECURE_AUTH_KEY', 'put your unique key here');
define('LOGGED_IN_KEY', 'put your unique key here');
define('NONCE_KEY', 'put your unique key here');
define('AUTH_SALT', 'put your unique key here');
define('SECURE_AUTH_SALT', 'put your unique key here');
define('LOGGED_IN_SALT', 'put your unique key here');
define('NONCE_SALT', 'put your unique key here');
$table_prefix = 'wp_';
define('WPLANG', '');
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/wordpress/');
require_once(ABSPATH . 'wp-settings.php');
?>
- 在终端中运行以下命令来启动Docker容器:
docker-compose up -d
评论已关闭