開発メモ

開発関係のメモをいろいろと。たぶん。

CentOSにPHPをインストール

VirtualBoxにインストールしたCentOSでいろいろ実験するシリーズ。

CentOSPHPの環境を構築したときのメモ。PHPのインストールから、phpMyAdminMySQLのDBを確認するところまで。

PHPのインストール

以下のコマンドで、PHP本体をインストール。

# yum install php

実は、PHPのインストールってこれだけ。楽だな。ついでに、使いそうなライブラリもインストールしておく。

# yum install php-mbstring php-gd php-mysql php-pear

phpMyAdminもインストール。

# yum install --enablerepo=epel phpMyAdmin

EPELを使えるようにする部分は、この辺で設定済み。

CentOSRubyをインストール - 開発メモ
http://seeku.hateblo.jp/entry/2013/05/29/081418

phpMyAdminの設定

PHPを使うのにphpMyAdminを使わないのはもったいないので、phpMyAdminの設定もしておく。

phpMyAdminの設定

「/etc/phpMyAdmin/config.inc.php」を編集して、以下の箇所を設定しておく。

・編集前(該当する箇所のみ抜粋)

$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg['Servers'][$i]['auth_type']     = 'http';      // Authentication method (config, http or cookie based)?

・編集後(該当する箇所のみ抜粋)

$cfg['blowfish_secret'] = '********'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg['Servers'][$i]['auth_type']     = 'cookie';      // Authentication method (config, http or cookie based)?

$cfg['DefaultLang'] = 'ja-utf-8';
$cfg['DefaultCharset'] = 'utf-8';

「********」の部分には、phpMyAdminで使用するパスワードを指定。cookieの情報をblowfishで暗号化するときに使われるパスワード? 結局、他で使うことは無さそう。

DefaultLangとDefaultCharsetは元のファイルに存在しないので、適当に追加しておく。

Apacheの設定

「/etc/httpd/conf.d/phpMyAdmin.conf」を編集。phpMyAdminは強力すぎて危険なので、アクセス制限をかけておくのが吉。・・・VirtualBoxCentOSで実行してる限りは、あまり意味がない話だが。

・編集前(該当する箇所のみ抜粋)

<Directory /usr/share/phpMyAdmin/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       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 ::1
   </IfModule>
</Directory>

・編集後(該当する箇所のみ抜粋)

<Directory /usr/share/phpMyAdmin/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       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 ::1
     Allow from 10.0.2.0/24
   </IfModule>
</Directory>

つまり、localhostだけじゃなくて、LAN内の他のPCからでも見られるように設定。

設定が終わったらApacheを再起動

# service httpd restart

phpMyAdminの動作を確認

PCから、以下のアドレスに接続して動作を確認。

http://localhost/phpmyadmin/

特に問題がなければ、phpMyAdminのログイン画面が表示されるはず。

f:id:see_ku:20130606075520p:plain

※ログインに使用するのはMySQLのユーザー&パスワード