2012年8月29日水曜日

CakePHP/SimpleTest

CakePHPでSimpleTestでテストを行っていたら、言われのないエラーを表示されて悩んでしまった。

SImpleTestで個別にテストケースを実行すると何も問題ないのだが、Test Groups の「All tests」を実行すると
Missing Database Table

Error: Database table テーブル名 for model モデル名 was not found.

表示されているテーブルとモデルは存在し、関連するテーブル(ここで表示されてテーブルを参照している)との関連も確認したが問題なかった。

SimpleTest の All Tests がおかしいのでは? との考えに至った。

実際に、ググるとSimpleTest の All Tests は挙動不審なので使わないほうが良いとの意見もあった。

2012年7月18日水曜日

CentOSでUPSの設定(apcupsd)

自宅のPCサーバー(Linux:CentOS)にUPSを付けることにした。

今までUPSをつけないでいたために、何台かPCのディスクを故障させてしまった。
一度の突然の電源断でもディスクが破壊される場合もあるが、何度も電源断があるとディスクのアクセスアームが磁気ディスク(円盤)を傷つけてしまう。

今年は、夏真っ盛りになる前にUPSを付けて停電・ブレーカー落ちに対応する。

購入したUPSは、APC RS550電源バックアップ(500VA) BR550G-JP です。
てっきり、Linux用のPowerChuteもCDに含まれていると思っていたら、なんとありませんでした。

APCのサイトでRPM版のPowerChuteが公開されていましたが、CentOSのリポジトリでapcupsd・apcupsd-gui・apcupsdーcgiがあるので、これをインストールする。

インストール後に早速アクセスしてみるが
Unable to communicate with the UPS on 127.0.0.1.
エラーで接続できない。SELinuxでエラーが吐き出されているので確認してみる。

アクセスを許可
httpd がネットワークポートに接続するように設定する場合、httpd_can_network_network_connect boolean をオンにする必要があります: "setsebool -P httpd_can_network_connect=1"

次のコマンドがこのアクセスを許可します:
setsebool -P httpd_can_network_connect=1

追加情報
ソースコンテキスト:  system_u:system_r:httpd_sys_script_t
ターゲットコンテキスト:  system_u:object_r:apcupsd_port_t
ターゲットオブジェクト:  None [ tcp_socket ]
Source:  upsstats.cgi
Source Path:  /var/www/apcupsd/upsstats.cgi
Port:  3551
Host:  hoge
Source RPM Packages:  apcupsd-cgi-3.14.10-1.el5
Target RPM Packages:  
ポリシー RPM:  selinux-policy-2.4.6-327.el5
Selinux 有効化:  True
ポリシータイプ:  targeted
MLS 有効化:  True
強制モード:  Enforcing
プラグイン名:  httpd_can_network_connect
      ・
      ・
      ・

生の監査メッセージ :

host=ora02 type=AVC msg=audit(1342584417.76:293): avc: denied { name_connect } for pid=7159 comm="upsstats.cgi" dest=3551 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:apcupsd_port_t:s0 tclass=tcp_socket

host=ora02 type=SYSCALL msg=audit(1342584417.76:293): arch=40000003 syscall=102 success=no exit=-13 a0=3 a1=bfba290 a2=3 a3=804eb20 items=0 ppid=3361 pid=7159 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="upsstats.cgi" exe="/var/www/apcupsd/upsstats.cgi" subj=system_u:system_r:httpd_sys_script_t:s0 key=(null)

早速、指示通りに # setsebool -P httpd_can_network_connect=1 を実行すると...

無事に表示されました。

2012年7月17日火曜日

SELinux覚書き(httpd_can_network_connect)

SELinuxのこまごまとした点についての覚書き

  • httpd_can_network_connect
    WEBサーバからDBサーバへアクセスするプログラムをPHPで作成したが、アクセスできない現象が発生
    • 原因
      WEBサーバのSELinuxのhttpd_can_network_connectが無効となっていた
    • 対処
      # setsebool -P httpd_can_network_connect 1
    • 確認
      # getsebool httpd_can_network_connect
      httpd_can_network_connect --> on

2012年7月15日日曜日

CentOS Firefox最新版のインストール

CentOSの自動更新では、firefoxの最新版はインストールされないので手動で最新版をインストールするための覚書き。
※CentOSの自動更新ではかなりふるいバージョンになってしまう。

一度最新版をインストールしたら、その後は firefox から(rootで)最新版に更新ができるが、12.0あたりになってから firefox の起動時に下記のエラー(kernel: 4gb seg fixup, process firefox)がでるようになったので、最新版のインストールを再度実行して確認することとした。

Jul 15 20:16:14 hoge kernel: 4gb seg fixup, process firefox (pid 8118), cs:ip 73:00401cef

■ firefoxの最新版をダウンロードする。(http://www.mozilla.jp/firefox/)

ダウンロードした tarボール を展開する。

# tar jxfv firefox-13.0.1.tar.bz2

展開された firefox をディレクトリごと移動します。

# mv firefox /usr/lib/firefox-13.0.1

/usr/bin にシンボリックリンクを貼ります。

# ln -s /usr/lib/firefox-13.0.1/firefox /usr/bin

2012年7月10日火曜日

SELinux ラベルの変更

httpd で公開フォルダを追加した時についつい忘れて手間取ってしまうのが、SELinuxのラベルの貼り替えです。

SELinuxで運用しているとフォルダや作成した時には、作成先に見合うラベルを設定する必要があります。
通常は、restorecon -R コマンドで親フォルダの情報が引き継がれると思っていたのですが、単純に引き継がれる訳でないようです。(詳細は未確認(未調査)です。)
よって、作成したフォルダに正しいラベルを設定するという事が必要になります。

# chcon system_u:object_r:httpd_sys_content_t /home/www -R
# chcon system_u:object_r:httpd_sys_script_exec_t /home/www/cgi-bin -R

2012年6月27日水曜日

xdebugでwarningがでる。

xdebugが有効かどうか確認すると下記のようなwarningがでる。

[root@hoge ~]# php -i | grep -i "xdebug support"
PHP Warning:  Xdebug MUST be loaded as a Zend extension in Unknown on line 0
xdebug support => enabled
[root@hoge ~]# 
■/etc/php.ini
extension=xdebug.so
   ↓ コメントアウト
;extension=xdebug.so

■/etc/php.d/xdebug.ini
zend_extension=/usr/lib/php/modules/xdebug.so
xdebug.remote_enable=On
xdebug.remote_connect_back=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.collect_params=On
xdebug.dump.GET=*
xdebug.dump.POST=*

extensionをzend_extensionに変更し、リモートの設定を追加した。(リモートデバッグを行うため) また、xdebug.remote_connect_back=On を設定して複数のクライアントからリモートデバッグが実行できるようにした。

「xdebug.remote_connect_back」は。xdebug 2.1以降で利用できる。

apacheを再起動して設定が有効になったか確認する
[root@hoge ~]# php -i | grep xdebug
/etc/php.d/xdebug.ini,
xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
 ・
 ・
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => On => On
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
 ・
 ・
 ・

2012年6月25日月曜日

CakePHP 複数アプリの実行

CakePHP で複数アプリを実行する。

1. virtual host を設定して複数アプリを別々ホスト名で起動する。

2. .htaccess を修正する。(忘れがちなので注意)
[root@hoge sample]# cat .htaccess

   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]

[root@hoge sample]# 
 
  ↓↓↓


   RewriteEngine on
   RewriteRule    ^$ webroot/    [L]
   RewriteRule    (.*) webroot/$1 [L]

サブディレクトリにcakePHPを構築する
もしサブドメインに構築する場合には、.htaccessの設定に追記が必要となる。
具体的には、RewriteBaseをきちんと設定にあるような

app/webroot/.htaccess にあるmod_rewriteの設定において RewriteBase /(サブディレクトリ名)を追加する必要がある。

もし、追加し忘れると、500 Internal Server Errorが表示され、Apacheのログには、

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

というメッセージが記録される。

今までDocumentRoot上にしか構築したことがなかったので、少しハマってしまった。