使用Docker搭建LAMP环境,上线wordpress

1,环境
系统版本:CentOS Linux release 7.5.1804
docker版本:Docker version 1.13.1

主机IP地址:192.168.116.128
前提条件:
关闭selinux
已经安装好docker

2,拉取mysql和PHP镜像

[root@localhost ~] [root@localhost ~] 

3,创建网络

[root@localhost ~] 2126534bba917d449091c868584d71528b16f3c60d91088af8d82b3fc0c9ac6c 

查看网络

[root@localhost ~] NETWORK ID NAME DRIVER SCOPE dc97fa388a53 bridge bridge local 1e70fdb4b1ca host host local 2126534bba91 lamp bridge local c40bc4ba2760 none null local 

4,创建生产mysql和php容器的脚本

[root@localhost ~]  function mysql() { docker run --name mysql --net lamp -p 3306:3306 \ -v /data/docker/mysql/data:/var/lib/mysql \ -v /data/docker/mysql/conf:/etc/mysql/conf.d \ -v /data/docker/mysql/logs:/logs \ -e MYSQL_ROOT_PASSWORD=Test1234 \ -d mysql:latest --character-set-server=utf8 } function httpd_php() { docker run --name httpd-php --net lamp -p 80:80 \ -v /data/docker/httpd/conf:/etc/apache2/sites-enabled \ -v /data/docker/www:/var/www/html \ -v /data/docker/httpd/logs:/var/log/apache2 \ -d php:7.2-apache } $1 

5,启动mysql和PHP容器

[root@localhost ~] cd91996a5842a82a3368598f8d38f76e4a8879bb93c2ed77bfa8e7fd3085c377 [root@localhost ~] c456a5114903bd20cbc3484d4232ca58e57af4c92ea0464df01f2b49f869946c [root@localhost ~] 

查看容器

[root@localhost ~] CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6e459971afa0 php:7.2-apache "docker-php-entryp..." 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp httpd-php 7ba5e9464247 mysql:latest "docker-entrypoint..." About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp, 33060/tcp mysql 

6,写一个php的首页文件来进行测试

echo "<?php phpinfo(); ?>" > /data/docker/www/index.php 

通过浏览器访问http://192.168.116.128
在这里插入图片描述
7,修改mysql的密码加密方式为mysql_native_password

[root@localhost ~] [mysqld] default-authentication-plugin=mysql_native_password 

8,数据库的操作
登录数据库容器,创建、配置wordpress数据库

[root@localhost ~] root@7ba5e9464247:/ mysql> create database wordpress; mysql> create user wps@localhost identified by '123456'; mysql> grant all privileges on wordpress.* to wps@localhost; mysql> create user wps@172.18.0.1 identified by '123456'; mysql> grant all privileges on wordpress.* to wps@172.18.0.1; mysql> alter user wps@172.18.0.1 identified with mysql_native_password by '123456'; mysql> flush privileges; mysql> exit root@7ba5e9464247:/ 

9,下载wordpress博客

[root@localhost ~] [root@localhost ~] 

10,配置wordpress博客
1,修改wp-config-sample.php配置

[root@localhost ~] [root@localhost wordpress] [root@localhost wordpress] /** WordPress数据库的名称 */ define('DB_NAME', 'wordpress'); /** MySQL数据库用户名 */ define('DB_USER', 'wps'); /** MySQL数据库密码 */ define('DB_PASSWORD', '123456'); /** MySQL主机 */ define('DB_HOST', '172.18.0.1'); /** 创建数据表时默认的文字编码 */ define('DB_CHARSET', 'utf8'); /** 数据库整理类型。如不确定请勿更改 */ define('DB_COLLATE', ''); 

2,mysql容器里安装mysqli扩展

[root@localhost ~] root@6e459971afa0:/var/www/html root@6e459971afa0:/var/www/html root@6e459971afa0:/var/www/html root@6e459971afa0:/usr/local/bin root@6e459971afa0:/usr/local/bin root@6e459971afa0:/usr/local/bin [root@localhost ~] 

3,修改wp-db.php文件,将mysql_connect替换为mysqli_connect

[root@localhost ~] [root@localhost wordpress] 

11,网页配置wordpress
关闭防火墙
浏览器访问http://192.168.116.128/wordpress
按前面的步骤填写完连接mysql的配置信息后,看到如下页面,表示mysql连接成功。

需要手工创建wp-config.php文件,将以上信息贴入wp-config.php文件中
vim /data/docker/www/wordpress/wp-config.php

然后点击“现在安装”,出现以下页面

输入完以上信息后,点击“安装WordPress”

至此,docker搭建lamp上线wordpress博客系统就搭建完成了。

原文链接:https://blog.csdn.net/WEN_BK/article/details/106207506?ops_request_misc=&request_id=aab9818f16734c888218be7080757f1b&biz_id=&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~koosearch~default-4-106207506-null-null.268%5Ev1%5Econtrol&utm_term=docker%E3%80%81wordpress%E3%80%81wordpress%E5%BB%BA%E7%AB%99%E3%80%81wordpress%E4%B8%BB%E9%A2%98%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享