MySQLを管理するツールの中でも、phpMyAdmin は特に便利なので、利用する機会が多いと思います。
EC2でも、この phpMyAdmin をインストールして、管理する方法をまとめました。
下記のサイトの記事を参考にしましたので、
何かしらのエラーが発生した場合などは、こちらの記事も併せて読むと良いと思います。
Amazon Linux 2 (EC2)にphpMyAdminを導入
https://analytics-note.xyz/aws/ec2-phpmyadmin/
前提条件
EC2のインスタンス生成が完了し、SSHログインができる状態となっていること。
80番のポートが開いたセキュリティグループを設定していること。
EC2のアップデート
1 |
sudo yum update -y |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 3.7 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package amazon-ssm-agent.x86_64 0:3.0.1124.0-1.amzn2 will be updated ---> Package amazon-ssm-agent.x86_64 0:3.1.1188.0-1.amzn2 will be an update ---> Package ec2-net-utils.noarch 0:1.6-1.amzn2 will be obsoleted ---> Package ec2-net-utils.noarch 0:1.6.1-2.amzn2 will be obsoleting ---> Package glibc.x86_64 0:2.26-57.amzn2 will be updated ---> Package glibc.x86_64 0:2.26-58.amzn2 will be an update ---> Package glibc-all-langpacks.x86_64 0:2.26-57.amzn2 will be updated ---> Package glibc-all-langpacks.x86_64 0:2.26-58.amzn2 will be an update ---> Package glibc-common.x86_64 0:2.26-57.amzn2 will be updated ---> Package glibc-common.x86_64 0:2.26-58.amzn2 will be an update ---> Package glibc-locale-source.x86_64 0:2.26-57.amzn2 will be updated ---> Package glibc-locale-source.x86_64 0:2.26-58.amzn2 will be an update ---> Package glibc-minimal-langpack.x86_64 0:2.26-57.amzn2 will be updated ---> Package glibc-minimal-langpack.x86_64 0:2.26-58.amzn2 will be an update ---> Package kernel.x86_64 0:5.10.106-102.504.amzn2 will be installed ---> Package libcrypt.x86_64 0:2.26-57.amzn2 will be updated ---> Package libcrypt.x86_64 0:2.26-58.amzn2 will be an update ---> Package libgcrypt.x86_64 0:1.5.3-14.amzn2.0.2 will be updated ---> Package libgcrypt.x86_64 0:1.5.3-14.amzn2.0.3 will be an update ---> Package openldap.x86_64 0:2.4.44-23.amzn2.0.2 will be updated ---> Package openldap.x86_64 0:2.4.44-23.amzn2.0.3 will be an update ---> Package sysctl-defaults.noarch 0:1.0-2.amzn2 will be updated ---> Package sysctl-defaults.noarch 0:1.0-3.amzn2 will be an update ---> Package vim-common.x86_64 2:8.2.4314-1.amzn2.0.1 will be updated ---> Package vim-common.x86_64 2:8.2.4428-1.amzn2.0.3 will be an update ---> Package vim-data.noarch 2:8.2.4314-1.amzn2.0.1 will be updated ---> Package vim-data.noarch 2:8.2.4428-1.amzn2.0.3 will be an update ---> Package vim-enhanced.x86_64 2:8.2.4314-1.amzn2.0.1 will be updated ---> Package vim-enhanced.x86_64 2:8.2.4428-1.amzn2.0.3 will be an update ---> Package vim-filesystem.noarch 2:8.2.4314-1.amzn2.0.1 will be updated ---> Package vim-filesystem.noarch 2:8.2.4428-1.amzn2.0.3 will be an update ---> Package vim-minimal.x86_64 2:8.2.4314-1.amzn2.0.1 will be updated ---> Package vim-minimal.x86_64 2:8.2.4428-1.amzn2.0.3 will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================ Package Arch Version Repository Size ============================================================================================================================================================ Installing: ec2-net-utils noarch 1.6.1-2.amzn2 amzn2-core 20 k replacing ec2-net-utils.noarch 1.6-1.amzn2 kernel x86_64 5.10.106-102.504.amzn2 amzn2extra-kernel-5.10 27 M Updating: amazon-ssm-agent x86_64 3.1.1188.0-1.amzn2 amzn2-core 27 M glibc x86_64 2.26-58.amzn2 amzn2-core 3.4 M glibc-all-langpacks x86_64 2.26-58.amzn2 amzn2-core 7.0 M glibc-common x86_64 2.26-58.amzn2 amzn2-core 773 k glibc-locale-source x86_64 2.26-58.amzn2 amzn2-core 3.2 M glibc-minimal-langpack x86_64 2.26-58.amzn2 amzn2-core 32 k libcrypt x86_64 2.26-58.amzn2 amzn2-core 52 k libgcrypt x86_64 1.5.3-14.amzn2.0.3 amzn2-core 265 k openldap x86_64 2.4.44-23.amzn2.0.3 amzn2-core 351 k sysctl-defaults noarch 1.0-3.amzn2 amzn2-core 3.9 k vim-common x86_64 2:8.2.4428-1.amzn2.0.3 amzn2-core 7.3 M vim-data noarch 2:8.2.4428-1.amzn2.0.3 amzn2-core 74 k vim-enhanced x86_64 2:8.2.4428-1.amzn2.0.3 amzn2-core 1.6 M vim-filesystem noarch 2:8.2.4428-1.amzn2.0.3 amzn2-core 69 k vim-minimal x86_64 2:8.2.4428-1.amzn2.0.3 amzn2-core 678 k Transaction Summary ============================================================================================================================================================ Install 2 Packages Upgrade 15 Packages Total download size: 79 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/17): ec2-net-utils-1.6.1-2.amzn2.noarch.rpm | 20 kB 00:00:00 (2/17): glibc-2.26-58.amzn2.x86_64.rpm | 3.4 MB 00:00:00 (3/17): glibc-all-langpacks-2.26-58.amzn2.x86_64.rpm | 7.0 MB 00:00:00 (4/17): glibc-common-2.26-58.amzn2.x86_64.rpm | 773 kB 00:00:00 (5/17): glibc-locale-source-2.26-58.amzn2.x86_64.rpm | 3.2 MB 00:00:00 (6/17): amazon-ssm-agent-3.1.1188.0-1.amzn2.x86_64.rpm | 27 MB 00:00:00 (7/17): glibc-minimal-langpack-2.26-58.amzn2.x86_64.rpm | 32 kB 00:00:00 (8/17): libcrypt-2.26-58.amzn2.x86_64.rpm | 52 kB 00:00:00 (9/17): libgcrypt-1.5.3-14.amzn2.0.3.x86_64.rpm | 265 kB 00:00:00 (10/17): sysctl-defaults-1.0-3.amzn2.noarch.rpm | 3.9 kB 00:00:00 (11/17): openldap-2.4.44-23.amzn2.0.3.x86_64.rpm | 351 kB 00:00:00 (12/17): vim-data-8.2.4428-1.amzn2.0.3.noarch.rpm | 74 kB 00:00:00 (13/17): vim-enhanced-8.2.4428-1.amzn2.0.3.x86_64.rpm | 1.6 MB 00:00:00 (14/17): vim-filesystem-8.2.4428-1.amzn2.0.3.noarch.rpm | 69 kB 00:00:00 (15/17): vim-minimal-8.2.4428-1.amzn2.0.3.x86_64.rpm | 678 kB 00:00:00 (16/17): vim-common-8.2.4428-1.amzn2.0.3.x86_64.rpm | 7.3 MB 00:00:00 (17/17): kernel-5.10.106-102.504.amzn2.x86_64.rpm | 27 MB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 64 MB/s | 79 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : 2:vim-data-8.2.4428-1.amzn2.0.3.noarch 1/33 Updating : glibc-common-2.26-58.amzn2.x86_64 2/33 Updating : glibc-2.26-58.amzn2.x86_64 3/33 Updating : glibc-minimal-langpack-2.26-58.amzn2.x86_64 4/33 Updating : 2:vim-filesystem-8.2.4428-1.amzn2.0.3.noarch 5/33 Updating : 2:vim-common-8.2.4428-1.amzn2.0.3.x86_64 6/33 Updating : 2:vim-enhanced-8.2.4428-1.amzn2.0.3.x86_64 7/33 Updating : 2:vim-minimal-8.2.4428-1.amzn2.0.3.x86_64 8/33 Updating : openldap-2.4.44-23.amzn2.0.3.x86_64 9/33 Updating : glibc-locale-source-2.26-58.amzn2.x86_64 10/33 Updating : libgcrypt-1.5.3-14.amzn2.0.3.x86_64 11/33 Updating : glibc-all-langpacks-2.26-58.amzn2.x86_64 12/33 Updating : libcrypt-2.26-58.amzn2.x86_64 13/33 Installing : ec2-net-utils-1.6.1-2.amzn2.noarch 14/33 Updating : amazon-ssm-agent-3.1.1188.0-1.amzn2.x86_64 15/33 Installing : kernel-5.10.106-102.504.amzn2.x86_64 16/33 Updating : sysctl-defaults-1.0-3.amzn2.noarch 17/33 Cleanup : glibc-all-langpacks-2.26-57.amzn2.x86_64 18/33 Cleanup : glibc-locale-source-2.26-57.amzn2.x86_64 19/33 Cleanup : 2:vim-enhanced-8.2.4314-1.amzn2.0.1.x86_64 20/33 Cleanup : 2:vim-common-8.2.4314-1.amzn2.0.1.x86_64 21/33 Cleanup : 2:vim-minimal-8.2.4314-1.amzn2.0.1.x86_64 22/33 Cleanup : libcrypt-2.26-57.amzn2.x86_64 23/33 Cleanup : libgcrypt-1.5.3-14.amzn2.0.2.x86_64 24/33 Cleanup : openldap-2.4.44-23.amzn2.0.2.x86_64 25/33 Cleanup : 2:vim-data-8.2.4314-1.amzn2.0.1.noarch 26/33 Cleanup : 2:vim-filesystem-8.2.4314-1.amzn2.0.1.noarch 27/33 Cleanup : ec2-net-utils-1.6-1.amzn2.noarch 28/33 Cleanup : amazon-ssm-agent-3.0.1124.0-1.amzn2.x86_64 29/33 Cleanup : sysctl-defaults-1.0-2.amzn2.noarch 30/33 Cleanup : glibc-common-2.26-57.amzn2.x86_64 31/33 Cleanup : glibc-minimal-langpack-2.26-57.amzn2.x86_64 32/33 Cleanup : glibc-2.26-57.amzn2.x86_64 33/33 Verifying : 2:vim-minimal-8.2.4428-1.amzn2.0.3.x86_64 1/33 Verifying : 2:vim-data-8.2.4428-1.amzn2.0.3.noarch 2/33 Verifying : 2:vim-filesystem-8.2.4428-1.amzn2.0.3.noarch 3/33 Verifying : openldap-2.4.44-23.amzn2.0.3.x86_64 4/33 Verifying : sysctl-defaults-1.0-3.amzn2.noarch 5/33 Verifying : kernel-5.10.106-102.504.amzn2.x86_64 6/33 Verifying : glibc-locale-source-2.26-58.amzn2.x86_64 7/33 Verifying : glibc-minimal-langpack-2.26-58.amzn2.x86_64 8/33 Verifying : libgcrypt-1.5.3-14.amzn2.0.3.x86_64 9/33 Verifying : glibc-all-langpacks-2.26-58.amzn2.x86_64 10/33 Verifying : 2:vim-common-8.2.4428-1.amzn2.0.3.x86_64 11/33 Verifying : glibc-common-2.26-58.amzn2.x86_64 12/33 Verifying : amazon-ssm-agent-3.1.1188.0-1.amzn2.x86_64 13/33 Verifying : ec2-net-utils-1.6.1-2.amzn2.noarch 14/33 Verifying : 2:vim-enhanced-8.2.4428-1.amzn2.0.3.x86_64 15/33 Verifying : libcrypt-2.26-58.amzn2.x86_64 16/33 Verifying : glibc-2.26-58.amzn2.x86_64 17/33 Verifying : 2:vim-enhanced-8.2.4314-1.amzn2.0.1.x86_64 18/33 Verifying : 2:vim-minimal-8.2.4314-1.amzn2.0.1.x86_64 19/33 Verifying : libgcrypt-1.5.3-14.amzn2.0.2.x86_64 20/33 Verifying : ec2-net-utils-1.6-1.amzn2.noarch 21/33 Verifying : glibc-all-langpacks-2.26-57.amzn2.x86_64 22/33 Verifying : 2:vim-data-8.2.4314-1.amzn2.0.1.noarch 23/33 Verifying : 2:vim-common-8.2.4314-1.amzn2.0.1.x86_64 24/33 Verifying : glibc-locale-source-2.26-57.amzn2.x86_64 25/33 Verifying : amazon-ssm-agent-3.0.1124.0-1.amzn2.x86_64 26/33 Verifying : sysctl-defaults-1.0-2.amzn2.noarch 27/33 Verifying : 2:vim-filesystem-8.2.4314-1.amzn2.0.1.noarch 28/33 Verifying : libcrypt-2.26-57.amzn2.x86_64 29/33 Verifying : glibc-common-2.26-57.amzn2.x86_64 30/33 Verifying : openldap-2.4.44-23.amzn2.0.2.x86_64 31/33 Verifying : glibc-minimal-langpack-2.26-57.amzn2.x86_64 32/33 Verifying : glibc-2.26-57.amzn2.x86_64 33/33 Installed: ec2-net-utils.noarch 0:1.6.1-2.amzn2 kernel.x86_64 0:5.10.106-102.504.amzn2 Updated: amazon-ssm-agent.x86_64 0:3.1.1188.0-1.amzn2 glibc.x86_64 0:2.26-58.amzn2 glibc-all-langpacks.x86_64 0:2.26-58.amzn2 glibc-common.x86_64 0:2.26-58.amzn2 glibc-locale-source.x86_64 0:2.26-58.amzn2 glibc-minimal-langpack.x86_64 0:2.26-58.amzn2 libcrypt.x86_64 0:2.26-58.amzn2 libgcrypt.x86_64 0:1.5.3-14.amzn2.0.3 openldap.x86_64 0:2.4.44-23.amzn2.0.3 sysctl-defaults.noarch 0:1.0-3.amzn2 vim-common.x86_64 2:8.2.4428-1.amzn2.0.3 vim-data.noarch 2:8.2.4428-1.amzn2.0.3 vim-enhanced.x86_64 2:8.2.4428-1.amzn2.0.3 vim-filesystem.noarch 2:8.2.4428-1.amzn2.0.3 vim-minimal.x86_64 2:8.2.4428-1.amzn2.0.3 Replaced: ec2-net-utils.noarch 0:1.6-1.amzn2 Complete! |
phpのインストール
1 |
sudo amazon-linux-extras install -y php7.2 |
1 2 3 4 5 |
[ec2-uesr@ip-xxx-xxx-xxx-xxx ~]# php -v PHP 7.2.34 (cli) (built: Oct 21 2020 18:03:20) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies [ec2-uesr@ip-xxx-xxx-xxx-xxx ~]# |
Apacheのインストール
1 |
sudo yum install -y httpd |
Apacheを起動します。
1 |
sudo systemctl start httpd |
サーバー起動時に自動的に起動するように設定します。
1 |
sudo systemctl enable httpd |
1 |
sudo yum install php-mbstring -y |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 3.7 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package php-mbstring.x86_64 0:7.2.34-1.amzn2 will be installed --> Processing Dependency: libonig.so.2()(64bit) for package: php-mbstring-7.2.34-1.amzn2.x86_64 --> Running transaction check ---> Package oniguruma.x86_64 0:5.9.6-1.amzn2.0.4 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================ Package Arch Version Repository Size ============================================================================================================================================================ Installing: php-mbstring x86_64 7.2.34-1.amzn2 amzn2extra-php7.2 501 k Installing for dependencies: oniguruma x86_64 5.9.6-1.amzn2.0.4 amzn2-core 127 k Transaction Summary ============================================================================================================================================================ Install 1 Package (+1 Dependent package) Total download size: 628 k Installed size: 2.6 M Downloading packages: (1/2): oniguruma-5.9.6-1.amzn2.0.4.x86_64.rpm | 127 kB 00:00:00 (2/2): php-mbstring-7.2.34-1.amzn2.x86_64.rpm | 501 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 3.1 MB/s | 628 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : oniguruma-5.9.6-1.amzn2.0.4.x86_64 1/2 Installing : php-mbstring-7.2.34-1.amzn2.x86_64 2/2 Verifying : php-mbstring-7.2.34-1.amzn2.x86_64 1/2 Verifying : oniguruma-5.9.6-1.amzn2.0.4.x86_64 2/2 Installed: php-mbstring.x86_64 0:7.2.34-1.amzn2 Dependency Installed: oniguruma.x86_64 0:5.9.6-1.amzn2.0.4 Complete! |
各サービスを再起動
Apache を再起動します。
1 |
sudo systemctl restart httpd |
php-fpm を再起動します。
1 |
sudo systemctl restart php-fpm |
phpMyAdminのインストール
1 |
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
--2022-04-11 02:38:26-- https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz Resolving www.phpmyadmin.net (www.phpmyadmin.net)... 89.187.160.30, 89.187.160.57, 89.187.160.24, ... Connecting to www.phpmyadmin.net (www.phpmyadmin.net)|89.187.160.30|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://files.phpmyadmin.net/phpMyAdmin/5.1.3/phpMyAdmin-5.1.3-all-languages.tar.gz [following] --2022-04-11 02:38:27-- https://files.phpmyadmin.net/phpMyAdmin/5.1.3/phpMyAdmin-5.1.3-all-languages.tar.gz Resolving files.phpmyadmin.net (files.phpmyadmin.net)... 89.187.160.28, 89.187.160.30, 89.187.160.57, ... Connecting to files.phpmyadmin.net (files.phpmyadmin.net)|89.187.160.28|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 12399585 (12M) [application/octet-stream] Saving to: ‘phpMyAdmin-latest-all-languages.tar.gz’ 100%[==================================================================================================================>] 12,399,585 --.-K/s in 0.1s 2022-04-11 02:38:27 (90.2 MB/s) - ‘phpMyAdmin-latest-all-languages.tar.gz’ saved [12399585/12399585] |
ファイルを展開します。
1 |
mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1 |
不要ファイルを削除します。
1 |
rm phpMyAdmin-latest-all-languages.tar.gz |
動作確認
http://{IPアドレス}/phpMyAdmin/
にアクセスし、ログイン画面が表示されればインストールは正常にできています。
設定変更
デフォルトの設定ファイルをコピーして設定ファイルを作成します。
1 2 |
cd /var/www/html/phpMyAdmin cp config.sample.inc.php config.inc.php |
データベースを設定します。
1 2 3 4 |
# 元の記述 $cfg['Servers'][$i]['host'] = 'localhost'; # 修正後の記述 $cfg['Servers'][$i]['host'] = '{RDSのエンドポイント}'; |