LoginSignup
10
6

More than 5 years have passed since last update.

phpMyAdmin に ip によるアクセス制限をかける

Last updated at Posted at 2018-01-10

CentOS 7.4 で確認しました。

phpMyAdmin のインストール

sudo yum install phpmyadmin -y

アクセス制限は
/etc/httpd/conf.d/phpMyAdmin.conf
で行ないます。

インストール直後は、localhost だけがアクセス可能です。
確認

curl http://localhost/phpMyAdmin/

ある特定の アドレスを許可したい時、
例えば 153.203.107.102 を許可する例

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip 153.203.107.102
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from 153.203.107.102
     Allow from ::1
   </IfModule>
</Directory>

総てのIPからのアクセスを許可する例

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
       Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
     Allow from All
   </IfModule>
</Directory>

DHCP で IP アドレスが変動する場合の設定
153.203.. からのアクセスを許可する例

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip 153.203.
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from 153.203.
     Allow from ::1
   </IfModule>
</Directory>
10
6
1

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
10
6