创建 WordPress CodeDeploy 捆绑包 - AMS 高级应用程序开发者指南

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建 WordPress CodeDeploy 捆绑包

本节提供了创建应用程序部署包的示例。

  1. 下载 WordPress、解压缩文件并创建. /scripts 目录。

    Linux 命令:

    wget https://github.com/WordPress/WordPress/archive/master.zip

    Windows:粘贴https://github.com/WordPress/WordPress/archive/master.zip到浏览器窗口并下载 zip 文件。

    创建用于组装软件包的临时目录。

    Linux:

    mkdir /tmp/WordPress

    Windows:创建一个 “WordPress” 目录,稍后将使用该目录路径。

  2. 将 WordPress 源代码解压缩到 “WordPress” 目录并创建一个。 /scripts 目录。

    Linux:

    unzip master.zip -d /tmp/WordPress_Temp cp -paf /tmp/WordPress_Temp/WordPress-master/* /tmp/WordPress rm -rf /tmp/WordPress_Temp rm -f master cd /tmp/WordPress mkdir scripts

    Windows:转到你创建的 “WordPress” 目录并在那里创建一个 “脚本” 目录。

    如果您在 Windows 环境中,请务必将脚本文件的中断类型设置为 Unix (LF)。在 Notepad ++ 中,这是窗口右下角的一个选项。

  3. 在 WordPress 目录中创建 CodeDeploy appsec.yml 文件(如果复制示例,请检查缩进,每个空格都很重要)。重要:确保将 WordPress 文件(在本例中为 WordPress 目录中)复制到预期目标 (/var/www/html/WordPress) 的 “源” 路径是正确的。在示例中,appsec.yml 文件位于文件所在的目录中,因此只需要使用 “/”。 WordPress 另外,即使你在 Auto Scaling 组中使用了 RHEL AMI,也要保留 “操作系统:linux” 一行不变。appspec.yml 文件示例:

    version: 0.0 os: linux files: - source: / destination: /var/www/html/WordPress hooks: BeforeInstall: - location: scripts/install_dependencies.sh timeout: 300 runas: root AfterInstall: - location: scripts/config_wordpress.sh timeout: 300 runas: root ApplicationStart: - location: scripts/start_server.sh timeout: 300 runas: root ApplicationStop: - location: scripts/stop_server.sh timeout: 300 runas: root
  4. 在中创建 bash 文件脚本。 WordPress /scripts 目录。

    首先,config_wordpress.sh使用以下内容创建(如果您愿意,可以直接编辑 wp-config.php 文件)。

    注意

    DBName替换为 HA 堆栈 RFC 中给出的值(例如,wordpress)。

    DB_MasterUsername替换为 HA 堆栈 RFC 中给出的MasterUsername值(例如,admin)。

    DB_MasterUserPassword替换为 HA 堆栈 RFC 中给出的MasterUserPassword值(例如,p4ssw0rd)。

    在 HA 堆栈 RFC 的执行输出中替换DB_ENDPOINT为终端节点 DNS 名称(例如srt1cz23n45sfg.clgvd67uvydk.us-east-1.rds.amazonaws.com)。你可以通过GetRfc操作(CLI:get-rfc--rfc-id RFC_ID)或者在你之前提交的 HA Stack RFC 的 AMS 控制台 RFC 详情页面中找到它。

    #!/bin/bash chmod -R 755 /var/www/html/WordPress cp /var/www/html/WordPress/wp-config-sample.php /var/www/html/WordPress/wp-config.php cd /var/www/html/WordPress sed -i "s/database_name_here/DBName/g" wp-config.php sed -i "s/username_here/DB_MasterUsername/g" wp-config.php sed -i "s/password_here/DB_MasterUserPassword/g" wp-config.php sed -i "s/localhost/DB_ENDPOINT/g" wp-config.php
  5. 在同一个目录中创建install_dependencies.sh包含以下内容的内容:

    #!/bin/bash yum install -y php yum install -y php-mysql yum install -y mysql service httpd restart
    注意

    HTTPS 是在启动时作为用户数据的一部分安装的,以便运行状况检查从一开始就起作用。

  6. 在同一个目录中创建start_server.sh包含以下内容的内容:

    • 对于亚马逊 Linux 实例,请使用以下命令:

      #!/bin/bash service httpd start
    • 对于 RHEL 实例,请使用以下命令(额外的命令是允许 SELINUX 接受的策略): WordPress

      #!/bin/bash setsebool -P httpd_can_network_connect_db 1 setsebool -P httpd_can_network_connect 1 chcon -t httpd_sys_rw_content_t /var/www/html/WordPress/wp-content -R restorecon -Rv /var/www/html service httpd start
  7. 在同一个目录中创建stop_server.sh包含以下内容的内容:

    #!/bin/bash service httpd stop
  8. 创建 zip 捆绑包。

    Linux:

    $ cd /tmp/WordPress $ zip -r wordpress.zip .

    Windows:前往 “WordPress” 目录选择所有文件并创建一个 zip 文件,一定要将其命名为 wordpress.zip。