软件版本:
Debian | 11.3 |
Docker | 20.10.16 |
MySQL | 8.0.27 |
Nginx | 1.21.5 |
PHP | 7.4.27 |
WordPress | 6.0 |
一、安装Docker(https://www.runoob.com/docker/debian-docker-install.html)
二、新建docker网桥
sudo docker network create world
三、安装MySQL
(1)拉取镜像
sudo docker pull mysql
(2)创建MySQL数据存储文件夹
sudo mkdir -p /data/mysql/data
(3)运行MySQL容器
sudo docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=root -v /data/mysql/data:/var/lib/mysql --network world mysql
四、安装wordpress
(1)拉取镜像
sudo docker pull wordpress
(2)创建wordpress文件夹
sudo mkdir -p /var/www/html/wordpress
(3)运行wordpress容器
sudo docker run -d --name wordpress --network world -v /var/www/html/wordpress:/var/www/html wordpress
(4)编辑wordpress配置,修改以下内容:
define( ‘DB_NAME’, ‘wordpressdb’ );
define( ‘DB_USER’, ‘root’ );
define( ‘DB_PASSWORD’, ‘root’ );
define( ‘DB_HOST’, ‘mysql’ );
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
sudo vi /var/www/html/wordpress/wp-config.php
五、安装nginx
(1)拉取镜像
sudo docker pull nginx
(2)创建nginx配置文件及html文件夹
sudo mkdir -p /etc/nginx/conf.d /var/www/html
(3)运行nginx容器
sudo docker run -d --name nginx -v /etc/nginx/conf.d:/etc/nginx/conf.d /
-v /var/www/html:/usr/share/nginx/html --network world -p 80:80 nginx
(4)创建wordpress.conf文件,配置nginx反向代理wordpress
sudo vi /etc/nginx/conf.d/wordpress.conf
wordpress.conf
upstream wordpress
{
server wordpress; ### wordpress容器的ip地址
}
server
{
listen 80;
listen [::]:80;
server_name localhost;
client_max_body_size 1024m;
location / {
proxy_pass http://wordpress;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
(5)重启nginx容器
sudo docker restart nginx
六、配置wordpress
(1)为wordpress创建数据库
(a)登入MySQL容器
sudo docker exec -it mysql /bin/bash
(b)登入MySQL
mysql -uroot -proot
(c)创建wordpress数据库
create database wordpressdb character set utf8mb4 collate utf8mb4_bin;
(d)退出数据库(exit),退出容器(exit)
(2)修改php文件上传大小限制
(a)登入wordpress容器
sudo docker exec -it wordpress /bin/bash
(b)复制 php.ini-development 到 /var/www/html/php-config
cp /usr/local/etc/php/php.ini-development /var/www/html
(c)为php.ini创建软链接
ln -s /var/www/html/php.ini-development /usr/local/etc/php/php.ini
(d)退出容器(exit)
(e)编辑php.ini-development,依次修改 upload_max_filesize(文件体积限制)、post_max_size(post大小限制)、memory_limit(内存占用限制)
sudo vi /var/www/html/wordpress/php.ini-development
(3)修改wordpress媒体文件上传类型限制
(a)追加希望被允许上传的文件类型(https://www.cnblogs.com/kedarui/p/3627307.html)
(b)允许所有的文件类型( 在wp-config.php 配置文件末尾追加以下内容 )
define( ‘ALLOW_UNFILTERED_UPLOADS’, ‘true’ );
sudo vi /var/www/html/wordpress/wp-config.php
经测试,只有在 左侧菜单 媒体子项下 添加新文件不受类型限制,直接在媒体界面添加文件 类型还是会受限
(4)最后重启wordpress容器,令修改生效
sudo docker restart wordpress
原创文章,作者:dweifng,如若转载,请注明出处:https://blog.ytso.com/272833.html