当前位置: 首页> 财经> 产业 > 程序员自学网站_企业文化管理咨询_如何制作个人网站_app开发软件

程序员自学网站_企业文化管理咨询_如何制作个人网站_app开发软件

时间:2025/7/10 7:33:39来源:https://blog.csdn.net/xx155802862xx/article/details/145488787 浏览次数:0次
程序员自学网站_企业文化管理咨询_如何制作个人网站_app开发软件

使用Docker Compose编排LNMP(Linux, Nginx, MySQL, PHP)环境并部署WordPress,是一个非常高效的解决方案。本文将详细介绍如何编写Dockerfile和docker-compose.yml文件来完成这一任务。

环境准备

确保已经安装了以下工具:

  • Docker
  • Docker Compose

创建项目目录结构

首先,创建一个项目目录,并在其中创建所需的文件和子目录。

lnmp-wordpress/
├── docker-compose.yml
├── nginx/
│   ├── Dockerfile
│   └── nginx.conf
├── php/
│   └── Dockerfile
└── wordpress/├── Dockerfile└── wp-config.php
​

编写Nginx的Dockerfile和配置文件

nginx/Dockerfile

FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
​

nginx/nginx.conf

server {listen 80;server_name localhost;root /var/www/html;index index.php index.html index.htm;location / {try_files $uri $uri/ /index.php?$args;}location ~ .php$ {include snippets/fastcgi-php.conf;fastcgi_pass php:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}location ~ /.ht {deny all;}
}
​

编写PHP的Dockerfile

php/Dockerfile

FROM php:7.4-fpm
RUN docker-php-ext-install mysqli
​

编写WordPress的Dockerfile和配置文件

wordpress/Dockerfile

FROM wordpress:latest
COPY wp-config.php /var/www/html/wp-config.php
​

wordpress/wp-config.php

<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'mysql');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');$table_prefix = 'wp_';define('WP_DEBUG', false);if ( !defined('ABSPATH') )define('ABSPATH', dirname(__FILE__) . '/');require_once(ABSPATH . 'wp-settings.php');
​

编写Docker Compose文件

docker-compose.yml

version: '3.8'services:nginx:build:context: ./nginxports:- "80:80"volumes:- ./wordpress:/var/www/htmldepends_on:- php- mysqlphp:build:context: ./phpvolumes:- ./wordpress:/var/www/htmlmysql:image: mysql:5.7volumes:- mysql_data:/var/lib/mysqlenvironment:MYSQL_ROOT_PASSWORD: rootMYSQL_DATABASE: wordpresswordpress:build:context: ./wordpressvolumes:- ./wordpress:/var/www/htmldepends_on:- mysqlvolumes:mysql_data:
​

启动服务

在项目根目录中运行以下命令启动服务:

docker-compose up -d
​

该命令将构建和启动Nginx、PHP、MySQL和WordPress容器。启动完成后,可以在浏览器中访问 http://localhost来设置和使用WordPress。

关键字:程序员自学网站_企业文化管理咨询_如何制作个人网站_app开发软件

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: