การติดตั้ง WordPress ใน Amazon Linux 2023 บน EC2

WordPress คือ โปรแกรมสำเร็จรูปที่ใช้เขียนบล็อกหรือจัดการเนื้อหาเว็บไซต์ต่างๆ ซึ่งเราสามารถนำมาติดตั้งใน Amazon Linux 2023 และกำหนดค่าต่างๆ ด้วย Command Line ได้ตามต้องการให้พร้อมใช้งานได้ทันทีครับ

สวัสดีครับ POP จากบริษัท Classmethod (Thailand) ครับ

ครั้งนี้จะมาแนะนำเกี่ยวกับการติดตั้ง WordPress ใน Amazon Linux 2023 บน EC2 โดยใช้ MariaDB Server เป็น Database server ให้กับ WordPress ครับ

WordPress คืออะไร

WordPress เป็นระบบจัดการเนื้อหา (Content Management System: CMS) ที่ใช้กันทั่วไปเพื่อสร้างและบริหารจัดการเว็บไซต์ โดยเฉพาะเว็บไซต์บล็อก (Blog) และเว็บไซต์ข่าว ซึ่งเป็นเรื่องสำคัญที่ทำให้ WordPress รู้จักมากที่สุด

นับตั้งแต่เวอร์ชันแรกที่ปล่อยออกมาในปี 2003 WordPress ได้รับความนิยมอย่างต่อเนื่องและกลายเป็นหนึ่งใน CMS ที่มีการใช้งานมากที่สุดในโลก ซึ่งสามารถให้บริการทั้งในลักษณะบล็อกส่วนตัวและเว็บไซต์ขนาดใหญ่ได้

คุณสมบัติที่โดดเด่นของ WordPress คือ

  1. ใช้งานง่าย: มีตัวติดตั้งและตัวอัปเกรดที่ใช้งานง่าย ทำให้ผู้ใช้ทุกระดับความเชี่ยวชาญสามารถสร้างและบริหารเว็บไซต์ได้
  2. ปรับแต่งได้: มีหลายธีม (Themes) และปลั๊กอิน (Plugins) ที่ช่วยให้ผู้ใช้สามารถปรับแต่งเว็บไซต์ของตนได้ตามต้องการ
  3. รองรับเนื้อหาหลายประเภท: นอกจากการใช้เป็นบล็อก WordPress ยังรองรับการจัดการเนื้อหาต่างๆ อื่นๆ อย่างเช่น หน้า (Pages) รูปภาพ วีดีโอ และอื่นๆ
  4. ชุมชนและการพัฒนา: มีชุมชนใหญ่ของผู้พัฒนาและผู้ใช้ที่เข้าร่วมพัฒนาและแบ่งปันประสบการณ์ ทำให้มีการพัฒนาต่อเนื่องและได้รับการปรับปรุงอย่างต่อเนื่อง
  5. เป็นโอเพนซอร์ส: WordPress เป็นโปรแกรมโอเพนซอร์ส, ทำให้ผู้ใช้งานสามารถดูแลและปรับแก้ปัญหาได้อย่างรวดเร็ว

WordPress ในปัจจุบันมีทั้งเวอร์ชันที่ให้บริการฟรีที่ติดตั้งบนเซิร์ฟเวอร์ของคุณเอง และเวอร์ชันที่ให้บริการในรูปแบบเว็บโฮสติ้ง (Hosted) ที่ให้บริการโดย WordPress.com

สิ่งที่ต้องมี

EC2 Instance (Amazon Linux 2023)

ติดตั้ง EC2 Instance โดยเลือก AMI เป็น Amazon Linux 2023

ดูตัวอย่างได้ที่ลิงก์ด้านล่างนี้

PHP 8.2

ติดตั้ง PHP 8.2 และ Apache ใน Amazon Linux 2023 บน EC2 เพื่อให้สามารถใช้งานเว็บไซต์ WordPress ได้

ดูตัวอย่างได้ที่ลิงก์ด้านล่างนี้

Database server

เราสามารถใช้ Database server เช่น MySQL Server, MariaDB Server และอื่นๆได้ แต่ผมจะแนะนำแค่ MySQL Server และ MariaDB Server เนื่องจากเป็นตัวที่ผมใช้บ่อยมากที่สุดและสามารถติดตั้งใน Amazon Linux 2023 ได้
สำหรับการสาธิตครั้งนี้ผมจะเลือกใช้ MariaDB Server เป็น Database server ให้กับ WordPress ครับ

※MariaDB Server เป็นตัวที่จะใช้สาธิตในครั้งนี้

MariaDB Server

ตัวอย่างการติดตั้ง MariaDB บน Amazon Linux 2023 เพื่อใช้เป็น Database server ให้กับ WordPress

MySQL Server

ตัวอย่างการติดตั้ง MySQL Server บน Amazon Linux 2023 เพื่อใช้เป็น Database server ให้กับ WordPress

*หากใช้ MySQL Server ให้สร้าง Database เตรียมไว้สำหรับ WordPress โดยรันคำสั่งนี้

CREATE DATABASE database_name;

ติดตั้ง MySQL Improved Extension

MySQLi (MySQL Improved) เป็นส่วนขยายของ PHP ที่ช่วยให้ PHP เชื่อมต่อและทำงานกับฐานข้อมูล MySQL ได้. ส่วนขยายนี้มีฟังก์ชันและความสามารถที่มากกว่า MySQL extension ที่ใช้กับ PHP 5.5.0 ขึ้นไป

เมื่อติดตั้ง MariaDB Server เสร็จแล้ว รันคำสั่งติดตั้ง MySQLi ตามนี้ (*หากรันใน root ไม่จำเป็นต้องมี sudo)

sudo yum install php-mysqli -y

ดูรายละเอียดเกี่ยวกับ MySQLi เพิ่มเติมได้ที่ลิงก์ด้านล่างนี้
MySQL Improved Extension

การติดตั้ง WordPress ใน Amazon Linux 2023

รันคำสั่งดาวน์โหลดไฟล์ WordPress

wget https://wordpress.org/latest.zip

root@ip-xx-xx-xx-xx:~

[root@ip-xx-xx-xx-xx ~]# wget https://wordpress.org/latest.zip
--2023-11-27 17:27:03--  https://wordpress.org/latest.zip
Resolving wordpress.org (wordpress.org)... 198.143.164.252
Connecting to wordpress.org (wordpress.org)|198.143.164.252|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25955109 (25M) [application/zip]
Saving to: ‘latest.zip’

latest.zip                        100%[===========================================================>]  24.75M   112KB/s    in 1m 56s

2023-11-27 17:29:01 (218 KB/s) - ‘latest.zip’ saved [25955109/25955109]

[root@ip-xx-xx-xx-xx ~]#


รันคำสั่งแตกไฟล์ latest.zip

unzip latest.zip


แล้วรันคำสั่งแสดงรายการไฟล์และไดเรกทอรี
จะเห็นว่าโฟลเดอร์ wordpress ถูกแตกไฟล์ออกมา

ll

root@ip-xx-xx-xx-xx:~

[root@ip-xx-xx-xx-xx ~]# ll
total 25364
-rw-r--r--. 1 root root 25955109 Nov  9 07:45 latest.zip
drwxr-xr-x. 5 root root    16384 Nov  9 07:45 wordpress
[root@ip-xx-xx-xx-xx ~]#


รันคำสั่งย้ายไฟล์ข้อมูลในโฟลเดอร์ wordpress ทั้งหมดไปที่โฟลเดอร์ html
* = ข้อมูลที่อยู่ในโฟลเดอร์ wordpress ทั้งหมด จะถูกย้ายไปที่โฟลเดอร์ html)

mv wordpress/* /var/www/html/


รันคำสั่งแสดงรายการไฟล์ของ wordpress ทั้งหมดในโฟลเดอร์ html นี้
จะเห็นว่าไฟล์ทั้งหมดถูกย้ายเข้ามาที่ html แล้ว

ll /var/www/html/

root@ip-xx-xx-xx-xx:~

[root@ip-xx-xx-xx-xx ~]# ll /var/www/html/
total 240
-rw-r--r--.  1 root root   405 Feb  6  2020 index.php
-rw-r--r--.  1 root root 19915 Jan  1  2023 license.txt
-rw-r--r--.  1 root root  7399 Jul  6 00:41 readme.html
-rw-r--r--.  1 root root  7211 May 13  2023 wp-activate.php
drwxr-xr-x.  9 root root 16384 Nov  9 07:45 wp-admin
-rw-r--r--.  1 root root   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--.  1 root root  2323 Jun 14 21:11 wp-comments-post.php
-rw-r--r--.  1 root root  3013 Feb 23  2023 wp-config-sample.php
drwxr-xr-x.  4 root root    52 Nov  9 07:45 wp-content
-rw-r--r--.  1 root root  5638 May 31 01:48 wp-cron.php
drwxr-xr-x. 27 root root 16384 Nov  9 07:45 wp-includes
-rw-r--r--.  1 root root  2502 Nov 27  2022 wp-links-opml.php
-rw-r--r--.  1 root root  3927 Jul 16 19:16 wp-load.php
-rw-r--r--.  1 root root 50924 Sep 30 05:01 wp-login.php
-rw-r--r--.  1 root root  8525 Sep 16 13:50 wp-mail.php
-rw-r--r--.  1 root root 26409 Oct 10 21:05 wp-settings.php
-rw-r--r--.  1 root root 34385 Jun 20 01:27 wp-signup.php
-rw-r--r--.  1 root root  4885 Jun 22 21:36 wp-trackback.php
-rw-r--r--.  1 root root  3154 Sep 30 14:39 xmlrpc.php
[root@ip-xx-xx-xx-xx ~]#


รันคำสั่งเปลี่ยนไดเรกทอรีหรือโฟลเดอร์ไปที่โฟลเดอร์ html

cd /var/www/html


รันคำสั่งสร้างโฟลเดอร์ uploads ในโฟลเดอร์ wp-content

mkdir wp-content/uploads


รันคำสั่งกำหนดสิทธิ์ 777 เพื่อให้ไดเรกทอรี uploads สามารถถูกเข้าถึงและแก้ไขได้จากทุกคนในโฟลเดอร์ wp-content (*โปรดใช้สิทธิ์นี้ด้วยความระมัดระวัง)

chmod 777 wp-content/uploads


รันคำสั่งสร้างโฟลเดอร์ upgrade ใน wp-content

mkdir wp-content/upgrade


รันคำสั่งกำหนดสิทธิ์ 777 เพื่อให้ไดเรกทอรี upgrade สามารถถูกเข้าถึงและแก้ไขได้จากทุกคนในโฟลเดอร์ wp-content (*โปรดใช้สิทธิ์นี้ด้วยความระมัดระวัง)

chmod 777 wp-content/upgrade


รันคำสั่งกำหนดสิทธิ์ 777 เพื่อให้ไดเรกทอรี plugins สามารถถูกเข้าถึงและแก้ไขได้จากทุกคนในโฟลเดอร์ wp-content (*โปรดใช้สิทธิ์นี้ด้วยความระมัดระวัง)

chmod 777 wp-content/plugins

ตั้งค่าไฟล์ wp-config.php

ต่อไปจะเปลี่ยนชื่อไฟล์ 「wp-config-sample.php」 ให้เป็น 「wp-config.php

รันคำสั่งแสดงรายการไฟล์และไดเรกทอรีและหาชื่อไฟล์ wp-config-sample.php

ll

root@ip-xx-xx-xx-xx:/var/www/html

[root@ip-xx-xx-xx-xx html]# ll
total 240
-rw-r--r--.  1 root root   405 Feb  6  2020 index.php
-rw-r--r--.  1 root root 19915 Jan  1  2023 license.txt
-rw-r--r--.  1 root root  7399 Jul  6 00:41 readme.html
-rw-r--r--.  1 root root  7211 May 13  2023 wp-activate.php
drwxr-xr-x.  9 root root 16384 Nov  9 07:45 wp-admin
-rw-r--r--.  1 root root   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--.  1 root root  2323 Jun 14 21:11 wp-comments-post.php
-rw-r--r--.  1 root root  3013 Feb 23  2023 wp-config-sample.php
drwxr-xr-x.  6 root root    82 Nov 27 18:06 wp-content
-rw-r--r--.  1 root root  5638 May 31 01:48 wp-cron.php
drwxr-xr-x. 27 root root 16384 Nov  9 07:45 wp-includes
-rw-r--r--.  1 root root  2502 Nov 27  2022 wp-links-opml.php
-rw-r--r--.  1 root root  3927 Jul 16 19:16 wp-load.php
-rw-r--r--.  1 root root 50924 Sep 30 05:01 wp-login.php
-rw-r--r--.  1 root root  8525 Sep 16 13:50 wp-mail.php
-rw-r--r--.  1 root root 26409 Oct 10 21:05 wp-settings.php
-rw-r--r--.  1 root root 34385 Jun 20 01:27 wp-signup.php
-rw-r--r--.  1 root root  4885 Jun 22 21:36 wp-trackback.php
-rw-r--r--.  1 root root  3154 Sep 30 14:39 xmlrpc.php
[root@ip-xx-xx-xx-xx html]#


แล้วรันคำสั่งเปลี่ยนชื่อไฟล์ 「wp-config-sample.php」 ให้เป็น 「wp-config.php

mv wp-config-sample.php wp-config.php


รันคำสั่งแสดงรายการไฟล์และไดเรกทอรี แล้วค้นหาชื่อไฟล์ wp-config.php
จะเห็นว่าชื่อไฟล์เปลี่ยนเป็น wp-config.php เรียบร้อยแล้ว

ll

root@ip-xx-xx-xx-xx:/var/www/html

[root@ip-xx-xx-xx-xx html]# ll
total 240
-rw-r--r--.  1 root root   405 Feb  6  2020 index.php
-rw-r--r--.  1 root root 19915 Jan  1  2023 license.txt
-rw-r--r--.  1 root root  7399 Jul  6 00:41 readme.html
-rw-r--r--.  1 root root  7211 May 13  2023 wp-activate.php
drwxr-xr-x.  9 root root 16384 Nov  9 07:45 wp-admin
-rw-r--r--.  1 root root   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--.  1 root root  2323 Jun 14 21:11 wp-comments-post.php
-rw-r--r--.  1 root root  3013 Feb 23  2023 wp-config.php
drwxr-xr-x.  6 root root    82 Nov 27 18:06 wp-content
-rw-r--r--.  1 root root  5638 May 31 01:48 wp-cron.php
drwxr-xr-x. 27 root root 16384 Nov  9 07:45 wp-includes
-rw-r--r--.  1 root root  2502 Nov 27  2022 wp-links-opml.php
-rw-r--r--.  1 root root  3927 Jul 16 19:16 wp-load.php
-rw-r--r--.  1 root root 50924 Sep 30 05:01 wp-login.php
-rw-r--r--.  1 root root  8525 Sep 16 13:50 wp-mail.php
-rw-r--r--.  1 root root 26409 Oct 10 21:05 wp-settings.php
-rw-r--r--.  1 root root 34385 Jun 20 01:27 wp-signup.php
-rw-r--r--.  1 root root  4885 Jun 22 21:36 wp-trackback.php
-rw-r--r--.  1 root root  3154 Sep 30 14:39 xmlrpc.php
[root@ip-xx-xx-xx-xx html]#


รันคำสั่งแก้ไขไฟล์ wp-config.php

vi wp-config.php

แล้วแก้ไขไฟล์ wp-config.php ตามนี้
» กดปุ่ม i ให้ขึ้น -- INSERT --
» เปลี่ยน 「'database_name_here'」 ให้เป็นชื่อ DB ที่เราสร้างไว้ เช่น 「'tinnakorn'
» เปลี่ยน 「'username_here'」 ให้เป็น 「root
» ลบ 「'password_here'」 ให้เป็น 「''」 (เท่ากับว่าง)

root@ip-xx-xx-xx-xx:/var/www/html

<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/documentation/article/editing-wp-config-php/
 *
 * @package WordPress
 */

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

/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', '' );

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

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
-- INSERT --                                                                                                                  29,25         Top


ต่อมาให้เลื่อนลงมาประมาณตรงกลาง และลบ code ตามนี้ออกให้หมด

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

เมื่อลบ Code ออกหมดแล้ว ให้เข้าไปที่เว็บไซต์ Secret Key นี้

แล้วคัดลอก Secret Key มาทั้งหมด และวางแทนในส่วนที่ลบไปเมื่อสักครู่นี้

root@ip-xx-xx-xx-xx:/var/www/html

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
 * 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',         'vX-!Ni|)5%j1,[lcH|nO?1q5(J9lEVBLp2=/9,q;zOYVGpE+9-@.I+|IG$%.o&Al');
define('SECURE_AUTH_KEY',  'Et7]ApSP~/`=`WOVX;|9hZ(g,ARJ&hH-[m= 8!,d-JHCc~XQX*O{Y-_5ZwPQRKUk');
define('LOGGED_IN_KEY',    '|Oqk#Y8=]aW`3fGdBHs7&vf95#a]%k}|=XuDO$Aw4by$)CBiSN7V(SqPQ$bB(N#u');
define('NONCE_KEY',        'XMJ4zw{AmZ*7nf+_Y-0BGi>W^<Bk2QUgeGe<w921mC,gl-*bMxG7~-v|3F;UBT%<');
define('AUTH_SALT',        '?7uGL33||LXTVUP`bX+`;-!6tVK{v]!fh|oP[JR*u=%(p93.CC{,)LZj&8moPBW0');
define('SECURE_AUTH_SALT', '|X62[2V-d5-IF|5/o>pxe+{N^{@Q^-BfJRrwQ@m|+*>XoK+L5[?^pe=VbyV7k:sM');
define('LOGGED_IN_SALT',   'IM1aH~3m03e&KtXn7K[ vUsFWjd@&%t*VVZwGLSBa1ly%=&#K#@i~`x&(yQ@1s+:');
define('NONCE_SALT',       'f3j[oIbLxSCb/<XuD%D;h=Rf3b7)KK4uQ;%)uHJ5f^?WX ,Ipg0)vP/c|lta{+sq');

/**#@-*/

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
-- INSERT --                                                                                                                  68,23         58%

แล้วเลื่อนลงมาด้านล่างสุดและหาคำว่า
/* Add any custom values between this line and the "stop editing" line. */
จากนั้นให้เพิ่ม Code ด้านล่างนี้ในบรรทัดถัดไป

define( 'FS_METHOD', 'direct' );

root@ip-xx-xx-xx-xx:/var/www/html

$table_prefix = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://wordpress.org/documentation/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */

define( 'FS_METHOD', 'direct' );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
-- INSERT --                                                                                                                  86,33         Bot

เมื่อแก้ไขไฟล์ wp-config.php เสร็จเรียบร้อยแล้วให้บันทึกการแก้ไขไฟล์ตามนี้
» กดปุ่ม Esc เพื่อให้ -- INSERT -- หายไป
» พิมพ์ :x หรือ :wq ได้เลย
» กดปุ่ม Enter

root@ip-xx-xx-xx-xx:/var/www/html

/* Add any custom values between this line and the "stop editing" line. */

define( 'FS_METHOD', 'direct' );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
:x

ทดสอบเข้าหน้าเว็บไซต์ WordPress

เมื่อตั้งค่าเสร็จแล้วให้ลองเข้าหน้าเว็บไซต์ WordPress ด้วย IP Instance

เปิดหน้าเว็บไซต์ WordPress ด้วย IP Instance

มาที่หน้า Instance ของเรา และคัดลอก IP Instance เตรียมไว้

แล้วนำไปเปิดในเว็บเบราว์เซอร์ที่เราใช้งานอยู่ ถ้าแสดงหน้าจอโดยมีข้อความ Error establishing a database connection แบบนี้ ให้ทำการแก้ไขในขั้นตอนถัดไป (หากไม่แสดง Error ดังกล่าว ให้ข้ามไปทำขั้นตอนตั้งค่า WordPress ในหน้าเว็บเบราว์เซอร์ได้เลย)

แก้ Error establishing a database connection

ให้ตรวจสอบความถูกต้องการตั้งค่า Database settings ในไฟล์ wp-config.php ตามนี้
» 'DB_NAME'
» 'DB_USER'
» 'DB_PASSWORD'
» 'DB_HOST'

root@ip-xx-xx-xx-xx:/var/www/html

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

/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', '' );

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

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );


หากตรวจสอบการป้อนข้อมูลในส่วนของ Database settings เรียบร้อยแล้ว ยังแสดง "Error establishing a database connection" นี้อยู่ ให้ตั้งค่ารหัสผ่าน MariaDB ตามลิงก์ด้านล่างนี้

เมื่อตั้งค่ารหัสผ่าน MariaDB เสร็จแล้ว ให้นำรหัสผ่านใหม่ไปป้อนที่ 'DB_PASSWORD' ในไฟล์ vi wp-config.php

root@ip-xx-xx-xx-xx:/var/www/html

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

/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', 'P@ssW0rd' );

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

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );


แล้วลอง Refresh หน้าจอ WordPress อีกครั้ง เมื่อแสดงหน้าจอ WordPress แบบนี้แล้ว แสดงว่า MariaDB และ WordPress สามารถเชื่อมต่อกันได้แล้ว ทีนี้ให้ตั้งค่า WordPress ในหน้าเว็บเบราว์เซอร์ในขั้นตอนถัดไปครับ

ตั้งค่า WordPress ในหน้าเว็บเบราว์เซอร์

เมื่อตั้งค่าเสร็จแล้วให้ลองเข้าหน้าเว็บไซต์ WordPress ด้วย IP Instance

มาที่หน้า Instance ของเรา และคัดลอก IP Instance เตรียมไว้

เมื่อแสดงหน้าจอ WordPress แบบนี้แล้ว แสดงว่า MySQL และ WordPress สามารถเชื่อมต่อกันได้แล้ว
ทีนี้ผมจะเริ่มตั้งค่า WordPress ดังนี้ (การตั้งค่านี้เป็นแค่ตัวอย่าง)
» เลือกภาษาที่ต้องการ ครั้งนี้ผมจะเลือกเป็น English (United States)
» คลิก Continue

แล้วตั้งค่า Information needed ตามต้องการ (การตั้งค่านี้เป็นตัวอย่าง)
» Site Title: tinnakorn-wp (ป้อนชื่อที่ต้องการ)
» Username: admin (ป้อน username ที่ต้องการ)
» Password: เราสามารถกำหนดเองได้ แต่ครั้งนี้ผมจะใช้ Password ที่ Generate นี้ (*ห้ามลืมคัดลอก Password เตรียมไว้!)
» Your Email: ป้อน Email ของเรา
» คลิก Install WordPress

คลิก Log In

ใส่ Username กับ Password ที่ตั้งค่าเมื่อสักครู่นี้

เมื่อเข้ามาที่หน้าจอนี้แล้ว ถือว่าการติดตั้ง WordPress ใน Amazon Linux 2023 สำเร็จแล้ว
แต่เพื่อความแน่ใจเราจะไปทดสอบเขียน Posts ในขั้นตอนถัดไปกันครับ

ทดสอบเขียน Posts

เลือก Posts แล้วคลิก Add New Post

ป้อนข้อมูล เช่น ข้อความ รูปภาพ ตามต้องการลงใน Posts แล้วคลิก Publish

คลิก Publish อีกครั้ง

คลิก View Post

จะเห็นว่าเราสามารถเขียน Post ในหน้า WordPress ของเราได้แล้ว

เพียงเท่านี้การติดตั้ง WordPress ใน Amazon Linux 2023 บน EC2 ก็เสร็จสมบูรณ์แล้วคร้บ

สรุป

การสาธิตนี้เป็นการติดตั้ง WordPress ใน Amazon Linux 2023 ด้วย Command Line และใช้ MariaDB Server เป็น Database server ให้กับ WordPress

หากต้องการใช้ Database Server ภายนอก เช่น RDS ก็สามารถทำได้โดยติดตั้ง MySQL Client หรือ MariaDB Client ลงใน Amazon Linux 2023 และเปลี่ยนข้อมูลในไฟล์ wp-config.php ให้เป็นของ RDS ก็จะทำให้สามารถใช้ RDS เป็น Database server ให้กับ WordPress ได้ครับ

ผมหวังว่าบทความนี้จะเป็นประโยชน์ให้กับผู้อ่านได้นะครับ

POP (Tinnakorn Maneewong) จากบริษัท Classmethod (Thailand) ครับ !

บทความที่เกี่ยวข้อง