Amazon Linux 2023にWordPressを構築

## EC2を起動
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3184769/7fab7521-a488-b087-145c-eb2e94fd8add.png)
## EC2を接続
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3184769/1d34437b-d447-7acf-366c-031559989e5e.png)
```console
A newer release of "Amazon Linux" is available.
  Version 2023.4.20240528:
  Version 2023.4.20240611:
Run "/usr/bin/dnf check-release-update" for full release and version update info
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
   ~~       V~' '->
    ~~~         /
      ~~._.   _/
         _/ _/
       _/m/'
```
## パッケージ更新
```console
[ec2-user@ip-10-0-10-120 ~]$ sudo dnf update -y
Last metadata expiration check: 4:32:37 ago on Wed Jun 19 06:54:44 2024.
================================================================================
WARNING:
  A newer release of "Amazon Linux" is available.

  Available Versions:

  Version 2023.4.20240528:
    Run the following command to upgrade to 2023.4.20240528:

      dnf upgrade --releasever=2023.4.20240528

    Release notes:
     https://docs.aws.amazon.com/linux/al2023/release-notes/relnotes-2023.4.20240528.html

  Version 2023.4.20240611:
    Run the following command to upgrade to 2023.4.20240611:

      dnf upgrade --releasever=2023.4.20240611

    Release notes:
     https://docs.aws.amazon.com/linux/al2023/release-notes/relnotes-2023.4.20240611.html

================================================================================
Dependencies resolved.
Nothing to do.
Complete!
```
## Apacheのインストールと起動
```console
# sudo dnf install -y httpd
# sudo systemctl start httpd
```
```console
[ec2-user@ip-10-0-10-120 ~]$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: di>
     Active: active (running) since Wed 2024-06-19 06:54:37 UTC; 4h 33min ago
       Docs: man:httpd.service(8)
   Main PID: 1951 (httpd)
     Status: "Total requests: 36; Idle/Busy workers 100/0;Requests/sec: 0.00219>
      Tasks: 177 (limit: 1114)
     Memory: 19.9M
        CPU: 11.954s
     CGroup: /system.slice/httpd.service
             tq1951 /usr/sbin/httpd -DFOREGROUND
             tq1966 /usr/sbin/httpd -DFOREGROUND
             tq1967 /usr/sbin/httpd -DFOREGROUND
             tq1968 /usr/sbin/httpd -DFOREGROUND
             mq2041 /usr/sbin/httpd -DFOREGROUND
```
## PHPをインストール
```console
[ec2-user@ip-10-0-10-120 ~]$ sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
Last metadata expiration check: 4:35:34 ago on Wed Jun 19 06:54:44 2024.
Package httpd-2.4.59-2.amzn2023.x86_64 is already installed.
Package wget-1.21.3-1.amzn2023.0.3.x86_64 is already installed.
Dependencies resolved.
================================================================================
 Package              Arch    Version                        Repository    Size
================================================================================
Installing:
 php8.2               x86_64  8.2.15-1.amzn2023.0.2          amazonlinux   11 k
 php8.2-devel         x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  707 k
 php8.2-fpm           x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  1.9 M
 php8.2-mysqlnd       x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  148 k
Installing dependencies:
 annobin-docs         noarch  10.93-1.amzn2023.0.1           amazonlinux   92 k
 annobin-plugin-gcc   x86_64  10.93-1.amzn2023.0.1           amazonlinux  887 k
 autoconf             noarch  2.69-36.amzn2023.0.3           amazonlinux  666 k
 automake             noarch  1.16.5-9.amzn2023.0.3          amazonlinux  677 k
 cmake-filesystem     x86_64  3.22.2-1.amzn2023.0.4          amazonlinux   16 k
 cpp                  x86_64  11.4.1-2.amzn2023.0.2          amazonlinux   10 M
 emacs-filesystem     noarch  1:28.2-3.amzn2023.0.7          amazonlinux   10 k
 gc                   x86_64  8.0.4-5.amzn2023.0.2           amazonlinux  105 k
 gcc                  x86_64  11.4.1-2.amzn2023.0.2          amazonlinux   32 M
 gcc-c++              x86_64  11.4.1-2.amzn2023.0.2          amazonlinux   12 M
 glibc-devel          x86_64  2.34-52.amzn2023.0.10          amazonlinux   36 k
 glibc-headers-x86    noarch  2.34-52.amzn2023.0.10          amazonlinux  436 k
 guile22              x86_64  2.2.7-2.amzn2023.0.3           amazonlinux  6.4 M
 kernel-headers       x86_64  6.1.90-99.173.amzn2023         amazonlinux  1.4 M
 keyutils-libs-devel  x86_64  1.6.3-1.amzn2023.0.1           amazonlinux   55 k
 krb5-devel           x86_64  1.21-3.amzn2023.0.4            amazonlinux  135 k
 libcom_err-devel     x86_64  1.46.5-2.amzn2023.0.2          amazonlinux   17 k
 libkadm5             x86_64  1.21-3.amzn2023.0.4            amazonlinux   79 k
 libmpc               x86_64  1.2.1-2.amzn2023.0.2           amazonlinux   62 k
 libselinux-devel     x86_64  3.4-5.amzn2023.0.2             amazonlinux  115 k
 libsepol-devel       x86_64  3.4-3.amzn2023.0.3             amazonlinux   42 k
 libsodium            x86_64  1.0.19-4.amzn2023              amazonlinux  176 k
 libstdc++-devel      x86_64  11.4.1-2.amzn2023.0.2          amazonlinux  2.2 M
 libtool              x86_64  2.4.7-1.amzn2023.0.3           amazonlinux  596 k
 libtool-ltdl         x86_64  2.4.7-1.amzn2023.0.3           amazonlinux   38 k
 libverto-devel       x86_64  0.3.2-1.amzn2023.0.2           amazonlinux   15 k
 libxcrypt-devel      x86_64  4.4.33-7.amzn2023              amazonlinux   32 k
 libxml2-devel        x86_64  2.10.4-1.amzn2023.0.6          amazonlinux  500 k
 libxslt              x86_64  1.1.34-5.amzn2023.0.2          amazonlinux  241 k
 m4                   x86_64  1.4.19-2.amzn2023.0.2          amazonlinux  296 k
 make                 x86_64  1:4.3-5.amzn2023.0.2           amazonlinux  534 k
 nginx-filesystem     noarch  1:1.24.0-1.amzn2023.0.2        amazonlinux  9.1 k
 openssl-devel        x86_64  1:3.0.8-1.amzn2023.0.11        amazonlinux  3.0 M
 pcre2-devel          x86_64  10.40-1.amzn2023.0.3           amazonlinux  473 k
 pcre2-utf16          x86_64  10.40-1.amzn2023.0.3           amazonlinux  216 k
 pcre2-utf32          x86_64  10.40-1.amzn2023.0.3           amazonlinux  205 k
 perl-B               x86_64  1.80-477.amzn2023.0.6          amazonlinux  179 k
 perl-Data-Dumper     x86_64  2.174-460.amzn2023.0.2         amazonlinux   55 k
 perl-File-Compare    noarch  1.100.600-477.amzn2023.0.6     amazonlinux   14 k
 perl-File-Copy       noarch  2.34-477.amzn2023.0.6          amazonlinux   20 k
 perl-File-Find       noarch  1.37-477.amzn2023.0.6          amazonlinux   26 k
 perl-Thread-Queue    noarch  3.14-458.amzn2023.0.2          amazonlinux   22 k
 perl-threads         x86_64  1:2.25-458.amzn2023.0.3        amazonlinux   58 k
 perl-threads-shared  x86_64  1.61-458.amzn2023.0.2          amazonlinux   44 k
 php8.2-cli           x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  3.6 M
 php8.2-common        x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  703 k
 php8.2-pdo           x86_64  8.2.15-1.amzn2023.0.2          amazonlinux   89 k
 php8.2-process       x86_64  8.2.15-1.amzn2023.0.2          amazonlinux   44 k
 php8.2-xml           x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  148 k
 xz-devel             x86_64  5.2.5-9.amzn2023.0.2           amazonlinux   53 k
 zlib-devel           x86_64  1.2.11-33.amzn2023.0.5         amazonlinux   45 k
Installing weak dependencies:
 php8.2-mbstring      x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  524 k
 php8.2-opcache       x86_64  8.2.15-1.amzn2023.0.2          amazonlinux  379 k
 php8.2-sodium        x86_64  8.2.15-1.amzn2023.0.2          amazonlinux   42 k
・・・
```
```console
[ec2-user@ip-10-0-10-120 ~]$ php -v
PHP 8.2.15 (cli) (built: Jan 16 2024 12:19:32) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.15, Copyright (c), by Zend Technologies
```
## WordPressをインストール
WordPressをダウンロード
```console
[ec2-user@ip-10-0-10-120 ~]$ wget https://ja.wordpress.org/latest-ja.tar.gz
--2024-06-19 11:45:58--  https://ja.wordpress.org/latest-ja.tar.gz
Resolving ja.wordpress.org (ja.wordpress.org)... 198.143.164.252
Connecting to ja.wordpress.org (ja.wordpress.org)|198.143.164.252|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25844719 (25M) [application/octet-stream]
Saving to: ‘latest-ja.tar.gz’

latest-ja.tar.gz    100%[===================>]  24.65M  7.94MB/s    in 3.6s

2024-06-19 11:46:03 (6.92 MB/s) - ‘latest-ja.tar.gz’ saved [25844719/25844719]
```
ダウンロードファイルを解凍
```console
[ec2-user@ip-10-0-10-120 ~]$ tar -zxvf latest-ja.tar.gz
wordpress/
wordpress/wp-login.php
wordpress/wp-cron.php
wordpress/xmlrpc.php
wordpress/wp-load.php
wordpress/wp-admin/
wordpress/wp-admin/credits.php
wordpress/wp-admin/admin-functions.php
wordpress/wp-admin/options-reading.php
wordpress/wp-admin/edit-tags.php
wordpress/wp-admin/link-manager.php
・・・
```
ダウンロードファイルの削除
```console
[ec2-user@ip-10-0-10-120 ~]$ rm latest-ja.tar.gz
[ec2-user@ip-10-0-10-120 ~]$ ll
total 16
drwxr-xr-x. 5 ec2-user ec2-user 16384 Jun 13 13:00 wordpress
```
WordPressを配置
```console
[ec2-user@ip-10-0-10-120 ~]$ sudo mv wordpress/* /var/www/html/
[ec2-user@ip-10-0-10-120 ~]$ sudo chown apache:apache /var/www/html/ -R
[ec2-user@ip-10-0-10-120 ~]$ sudo systemctl restart httpd.service
```
パブリックIPにアクセス
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3184769/8cd83bb5-b77a-e514-fdcd-eda6edd97af7.png)