再Docker中架设完整的WordPress站点全攻略
这篇文章主要介绍了再Docker中架设完整的WordPress站点全攻略,Docker是当下最火爆的虚拟机类技术,需要的朋友可以参考下
1. 安装 Docker
在我们真正开始之前,我们需要确保在我们的 Linux 机器上已经安装了 Docker。我们使用的主机是 CentOS 7,因此我们用下面的命令使用 yum 管理器安装 docker。
# yum install docker
# systemctl restart docker.service
2. 创建 WordPress 的 Dockerfile
我们需要创建用于自动安装 wordpress 以及其前置需求的 Dockerfile。这个 Dockerfile 将用于构建 WordPress 的安装镜像。这个 WordPress Dockerfile 会从 Docker Registry Hub 获取 CentOS 7 镜像并用最新的可用更新升级系统。然后它会安装必要的软件,例如 Nginx Web 服务器、PHP、MariaDB、Open SSH 服务器,,以及其它保证 Docker 容器正常运行不可缺少的组件。最后它会执行一个初始化 WordPress 安装的脚本。
# nano Dockerfile
然后,我们需要将下面的配置行添加到 Dockerfile中。
FROM centos:centos7
MAINTAINER The CentOS Project
3. 创建启动脚本
我们创建了 Dockerfile 之后,我们需要创建用于运行和配置 WordPress 安装的脚本,名称为 start.sh。它会为 WordPress 创建并配置数据库和密码。用我们喜欢的文本编辑器打开 start.sh。
# nano start.sh
打开 start.sh 之后,我们要添加下面的配置行到文件中。
#!/bin/bash __check() { if [ -f /usr/share/nginx/html/wp-config.php ]; then exit fi } __create_user() { # 创建用于 SSH 登录的用户 SSH_USERPASS=`pwgen -c -n -1 8` useradd -G wheel user echo user:$SSH_USERPASS | chpasswd echo ssh user password: $SSH_USERPASS } __mysql_config() { # 启用并运行 MySQL yum -y erase mariadb mariadb-server rm -rf /var/lib/mysql/ /etc/my.cnf yum -y install mariadb mariadb-server mysql_install_db chown -R mysql:mysql /var/lib/mysql /usr/bin/mysqld_safe & sleep 10 } __handle_passwords() { # 在这里我们生成随机密码(多亏了 pwgen)。前面两个用于 mysql 用户,最后一个用于 wp-config.php 的随机密钥。 WORDPRESS_DB="wordpress" MYSQL_PASSWORD=`pwgen -c -n -1 12` WORDPRESS_PASSWORD=`pwgen -c -n -1 12` # 这是在日志中显示的密码。 echo mysql root password: $MYSQL_PASSWORD echo wordpress password: $WORDPRESS_PASSWORD echo $MYSQL_PASSWORD > /mysql-root-pw.txt echo $WORDPRESS_PASSWORD > /wordpress-db-pw.txt # 这里原来是一个包括 sed、cat、pipe 和 stuff 的很长的行,但多亏了 # @djfiander 的 https://gist.github.com/djfiander/6141138 # 现在没有了 sed -e "s/database_name_here/$WORDPRESS_DB/ s/username_here/$WORDPRESS_DB/ s/password_here/$WORDPRESS_PASSWORD/ /'AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'SECURE_AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'LOGGED_IN_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'NONCE_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'SECURE_AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'LOGGED_IN_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'NONCE_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/" /usr/share/nginx/html/wp-config-sample.php > /usr/share/nginx/html/wp-config.php } __httpd_perms() { chown apache:apache /usr/share/nginx/html/wp-config.php } __start_mysql() { # systemctl 启动 mysqld 服务 mysqladmin -u root password $MYSQL_PASSWORD mysql -uroot -p$MYSQL_PASSWORD -e "CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '$WORDPRESS_PASSWORD'; FLUSH PRIVILEGES;" killall mysqld sleep 10 } __run_supervisor() { supervisord -n } # 调用所有函数 __check __create_user __mysql_config __handle_passwords __httpd_perms __start_mysql __run_supervisor
增加完上面的配置之后,保存并关闭文件。
4. 创建配置文件
现在,我们需要创建 Nginx Web 服务器的配置文件,命名为 nginx-site.conf。
# nano nginx-site.conf
然后,增加下面的配置信息到配置文件。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

Containerization technologies such as Docker enhance rather than replace Java's platform independence. 1) Ensure consistency across environments, 2) Manage dependencies, including specific JVM versions, 3) Simplify the deployment process to make Java applications more adaptable and manageable.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.
