本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立 WordPress CodeDeploy 套件
本節提供建立應用程式部署套件的範例。
下載 WordPress、解壓縮檔案並建立 ./scripts 目錄。
Linux 命令:
wget https://github.com/WordPress/WordPress/archive/master.zipWindows:貼
https://github.com/WordPress/WordPress/archive/master.zip到瀏覽器視窗並下載 zip 檔案。建立要在其中組合套件的暫時目錄。
Linux︰
mkdir /tmp/WordPressWindows:建立「WordPress」目錄,稍後您將使用目錄路徑。
將 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 scriptsWindows:前往您建立的「WordPress」目錄,並在該處建立「scripts」目錄。
如果您在 Windows 環境中,請務必將指令碼檔案的中斷類型設定為 Unix (LF)。在記事本 ++ 中,這是視窗右下角的選項。
在 WordPress 目錄中建立 CodeDeploy apppec.yml 檔案 (如果複製範例,請檢查縮排,每個空格都會計算)。重要:確保「來源」路徑正確,可將 WordPress 檔案 (在本例中為 WordPress 目錄中) 複製到預期的目的地 (/var/www/html/WordPress)。在此範例中,appapppec.yml 檔案位於具有 WordPress 檔案的 目錄中,因此只需要 "/"。此外,即使您為 Auto Scaling 群組使用 RHEL AMI,也請保持原狀。Apppec.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-
在 WordPress ./scripts 目錄中建立 bash 檔案指令碼。
首先,
config_wordpress.sh使用下列內容建立 (如果您願意,可以直接編輯 wp-config.php 檔案)。注意
將
DBName取代為 HA 堆疊 RFC 中指定的值 (例如wordpress)。將
DB_MasterUsername取代為 HA 堆疊 RFC 中指定的MasterUsername值 (例如admin)。將
DB_MasterUserPassword取代為 HA 堆疊 RFC 中指定的MasterUserPassword值 (例如p4ssw0rd)。將
DB_ENDPOINT取代為 HA Stack RFC 執行輸出中的端點 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 在相同的目錄中
install_dependencies.sh,使用下列內容建立 :#!/bin/bash yum install -y php yum install -y php-mysql yum install -y mysql service httpd restart注意
HTTPS 會在啟動時安裝為使用者資料的一部分,以允許從頭開始運作的運作狀態檢查。
在相同的目錄中
start_server.sh,使用下列內容建立 :對於 Amazon 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
在相同的目錄中
stop_server.sh,使用下列內容建立 :#!/bin/bash service httpd stop建立 zip 套件。
Linux︰
$ cd /tmp/WordPress $ zip -r wordpress.zip .Windows:前往您的「WordPress」目錄,選取所有檔案並建立 zip 檔案,請務必將其命名為 wordpress.zip。