ackintosh

https://ackintosh.github.io/about/ に引っ越しました ☺

MAMPにPHPUnitをインストール

$ cd /Applications/MAMP/bin/php/php5.3.6/bin

# チャンネル追加
$ sudo ./pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

# チャンネル追加
$ sudo ./pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded


# 依存関係があるパッケージもまとめてインストール
$sudo ./pear install --alldeps phpunit/PHPUnit

# パージョン確認
$ ./phpunit --version
PHPUnit 3.6.10 by Sebastian Bergmann.

# pathを通す
$ export PATH=$PATH:/Applications/MAMP/bin/php/php5.3.6/bin
# 確認
$ which phpunit
/Applications/MAMP/bin/php/php5.3.6/bin/phpunit

MAMPでpearコマンドが使えない

pearコマンドを使おうとすると下記エラーが出てしまう。

---------------------------------------------------------------------------------------
Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050

Notice: unserialize(): Error at offset 267 of 1133 bytes in /Applications/MAMP/bin/php/php5.3.6/lib/php/PEAR/Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.
---------------------------------------------------------------------------------------

■解決方法
/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
を削除またはリネームして再度実行。

WebアプリケーションからのSET NAMESは危険

yohgaki's blog「SET NAMESは禁止」
http://blog.ohgaki.net/set_namesa_mcb_asc

引用---
APIを利用したデータベース接続は現在の文字エンコーディング設定を各接続情報としてメモリ内に保存しています。APIのエスケープ関数はこの情報をエスケープの際に利用します。
SET NAMESによって文字エンコーディングを変更するとC言語などで書かれたエスケープAPI (libmysql, libpqなど)が想定しているエンコーディングと実際のエンコーディングが異なる状況が発生します。この違いにより、環境によっては文字エンコーディングを利用したSQLインジェクション攻撃が可能になります。
---

SET NAMESを使わない方法。
PHP

mysql_set_charset('utf8');


■Ruby

mysql = Mysql.init
mysql.options(Mysql::SET_CHARSET_NAME, 'utf8')
mysql.real_connect('host', 'user', 'password', 'database')
mysql.query('SET NAMES utf8')

nginxをベンチマークしてapacheと比べてみました。

静的HTMLファイルで試しました。

# ab -n 1000 -c 10 http://apacheサーバー/bench.html

Requests per second:    128.68 [#/sec] (mean)
Time per request:       77.715 [ms] (mean)

# ab -n 1000 -c 10 http://nginxサーバー/bench.html

Requests per second:    245.15 [#/sec] (mean)
Time per request:       40.792 [ms] (mean)


nginx速いですね ^o^

nginxでphpを動かす(php-fpmをyumでインストール)

CentOS+nginxの環境でPHPを動かす設定をしてみました。
※下記のようにyumでインストールするにはPHP5.3以上が必須です。

リポジトリを登録
※versionは最新を確認して使用する。

epel

# rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

remi

# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm


・yumでインストール

# yum -y install php-cli php-fpm php-mbstring --enablerepo=remi

設定ファイル
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf

・php-fpm起動

# /etc/init.d/php-fpm start

・自動起動設定

# chkconfig php-fpm on
# chkconfig --list php-fpm
php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off

・nginx設定

# vi /etc/nginx/nginx.conf
htttp {
    server {
        listen 80;
        server_name test.com;
        index index.html index.php index.htm;
        root /usr/share/nginx/html;
        charset utf-8;
        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
    }
}

・nginx再起動

# /etc/init.d/nginx restart

nginxをインストール

CentOS 6.2にnginx.org提供のリポジトリからnginxのパッケージをインストールしてみました。

■公式ダウンロードサイトの"Pre-Build Linux Packages"からリポジトリ用のRPMファイルをダウンロード

$ wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

■リポジトリの登録

# rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

/etc/yum.repos.d/nginx.repoというファイルがインストールされる。

# nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

■yumでnginxをインストール

# yum install nginx
-----------------------------
Installed:
  nginx.i386 0:1.0.14-1.el6.ngx                                                                                                                                 

Complete!
-----------------------------

■nginxを起動(他のWebサーバーは停止しておく)

# service nginx start

サーバーにアクセスして、"Welcome to nginx!"と表示されれば完了。


・ドキュメントルート
 nginx.orgパッケージの場合は /usr/share/nginx/html
・設定ファイル
 /etc/nginx/nginx.conf