iT邦幫忙

2021 iThome 鐵人賽

DAY 13
0
DevOps

AWS Solution Architect Associate的鐵人不只三項證照之路系列 第 13

Day 13 AWS雲端實作起手式第三彈 開始拼拼圖吧

今天接著來看看如何搞定架設的設定檔吧!

步驟 7 建立網站
在先前開啟EC2時,我們透過user data下載的內容,可以在EC2內確認架站內容。

User data的內容如下:

#!/bin/bash
yum update -y
yum install httpd php php-mysql -y
cd /var/www/html
echo "healthy" > healthy.html
wget https://wordpress.org/wordpress-5.1.1.tar.gz
tar -xzf wordpress-5.1.1.tar.gz
cp -r wordpress/* /var/www/html/
rm -rf wordpress
rm -rf wordpress-5.1.1.tar.gz
chmod -R 755 wp-content
chown -R apache:apache wp-content
wget https://s3.amazonaws.com/bucketforwordpresslab-donotdelete/htaccess.txt
mv htaccess.txt .htaccess
chkconfig httpd on
service httpd start

首先透過SSH登入EC2機器。pem檔是建置EC2時,會取得的認證檔。後面網址則是EC2機器的IP位址。

ssh -i "xxx.pem" ec2-user@ecxxxx.ap-xxx-2.compute.amazonaws.com

進入EC2後,會先切換至root user模式,在特定路徑下,確認網站服務可以正常運作。

# 轉換至root user模式
sudo su
cd /var/www/html
# 確認htaccess是否已安裝
cat .htaccess
service httpd start
service httpd status
# 檢查系統的健康狀態
cat healthy.html

步驟 8 登入網址
接著我們可以進入WP網站的後台,進行操作
http://ip_address/wp-admin/setup-config.php

針對DB的帳密來設定

接著回到EC2的console內,針對wp-config檔案進行調整。

# 複製預設設定檔
cp wp-config-sample.php wp-config.php
# 開始設定檔編輯
nano wp-config.php

在wp-config.php內,編輯設定檔。

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** MySQL database username */
define( 'DB_USER', 'username_here' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         '>J6IJ8Mq <,ql}<o),n/v4<*aCv~Xt1a{@gk{ +ddcqE?yvf9UkXA2p7l!}fs');
define('SECURE_AUTH_KEY',  '+hsdvVA/(?Tj^_!FD.X zL$uIAZXy-vs1cjdNvL[Mhx$^aBZT,^h-Bg9$FFE');
define('LOGGED_IN_KEY',    'Dv1a.`AvU7Ux:|ZD~G!QXoQ:4_`=CVGT0h)1_ur.D[MyRpEl~A>wa90R5LYf');
define('NONCE_KEY',        '-rcw$Yx>|(C-6g[VG|CD_S<kU8*3iSvZV,po7;Az3K6,fp|BNr<$-BD{Yl?');
define('AUTH_SALT',        'iHu6QKG*5JwP:C>TZqz(0J|MJoxw4SfP{6c84,0>gK2|U{A.E8?.fp/pO/#ta');
define('SECURE_AUTH_SALT', 'WC=+BtNKf+1;]%a)~+*:Cw&fq2(NAFk%SMST>p?JRn,8Cgx6-t<|;6 >h^Nt');
define('LOGGED_IN_SALT',   ';bJ|k;I$}Q?bMFv:ZXn-DOC.nGpRsA~6|.W?jZ=veaj?dew>K$CQibuwz4P');
define('NONCE_SALT',       'M3%Yntih[Rh/VU.!7xO&Jl0 |oN$yO- fw^yYFY=e>UkQ|f* <nlT<4|`B');

完成設定檔案之後,安裝缺漏的檔案,並查驗服務是否可正常運行。

sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
sudo service httpd restart

細節內容大家可以再參考官網的文件: https://aws.amazon.com/tw/getting-started/hands-on/deploy-wordpress-with-amazon-rds/5/


上一篇
Day 12 AWS雲端實作起手式第二彈 開始拼拼圖吧
下一篇
Day 14 AWS雲端實作起手式第四彈 圖文檔案與程式碼備份與URL重寫
系列文
AWS Solution Architect Associate的鐵人不只三項證照之路30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言