LoginSignup
0

More than 1 year has passed since last update.

Amazon Linux 2 に MySQL 8 / Apache / PHP 8 をインストール

Last updated at Posted at 2022-06-25

まず、最新状態へアップデート

sudo yum update -y
sudo yum update -y amazon-linux-extras

MySQL 8.0 のインストール

レポジトリ
sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
インストール
sudo yum install mysql-community-server -y

鍵に関する問題でインストールできなかったら下記を実行後、再度インストール

sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
インストールバージョン
mysql --version
結果) mysql v8 がインストールされていること
mysql  Ver 8.0.29 for Linux on x86_64 (MySQL Community Server - GPL)
サービスの有効化、起動、ステータス確認
sudo systemctl enable mysqld
sudo systemctl start mysqld
sudo systemctl status mysqld
結果) active になっていること
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled
)
   Active: active (running) since Sat 2022-06-25 07:45:59 UTC; 195ms ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3776 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3847 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─3847 /usr/sbin/mysqld
パスワード確認
sudo cat /var/log/mysqld.log | grep password
結果) 初期パスワードはログ内に記載されている
2022-06-25T07:45:55.529631Z 6 [Note] [MY-010454] [Server] A temporary password is generated
 for root@localhost: PASSWORD
セキュリティ設定
mysql_secure_installation
root でログインを確認
mysql -uroot -p
結果) ログインできること
mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Apache 2.4 のインストール

インストール
sudo yum install -y httpd
サービスの有効化、起動、ステータス確認
sudo systemctl enable httpd
sudo systemctl start httpd
sudo systemctl status httpd
結果
sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-06-25 08:00:06 UTC; 31s ago
     Docs: man:httpd.service(8)
 Main PID: 4541 (httpd)
   Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:  
 0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─4541 /usr/sbin/httpd -DFOREGROUND
           ├─4544 /usr/sbin/httpd -DFOREGROUND
           ├─4545 /usr/sbin/httpd -DFOREGROUND
           ├─4546 /usr/sbin/httpd -DFOREGROUND
           ├─4547 /usr/sbin/httpd -DFOREGROUND
           └─4558 /usr/sbin/httpd -DFOREGROUND

PHP 8 のインストール

有効なPHPのバージョンを確認
amazon-linux-extras | grep php
結果
 42  php7.4                   available    [ =stable ]
 51  php8.0                   available    [ =stable ]
7.4 を無効化、8.0 を有効化
sudo amazon-linux-extras disable php7.4
sudo amazon-linux-extras enable php8.0
再度、有効なPHPのバージョンを確認
amazon-linux-extras | grep php
結果) 8.0 が enable になっていること
  _  php7.4                   available    [ =stable ]
 51  php8.0=latest            enabled      [ =stable ]
インストール
sudo yum clean metadata
sudo amazon-linux-extras install php8.0 -y
バージョン確認
php -v
確認) PHP 8 がインストールされていること
PHP 8.0.18 (cli) (built: May 16 2022 19:07:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.18, Copyright (c) Zend Technologies

Let's Encrypt

/etc/httpd/conf/httpd.conf へ VirtualHost の設定を追加します

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/html
</VirtualHost>
certbot のインストール
sudo amazon-linux-extras install -y epel
sudo yum update -y
sudo yum install -y certbot python2-certbot-apache

certbot にて証明書を取得し、apache へ設定を行う

certbot
sudo certbot --apache

httpd.conf に設定されたので反映する

sudo systemctl reload httpd

設定変更

Apache

  • デフォルトの Document Root
    • /var/html/www
  • 設定ファイル
    • /etc/httpd/conf/httpd.conf など
  • 設定反映例
    • sudo systemctl stop httpd
    • sudo systemctl start httpd

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0