27
27
03
- CentOSにfastcgiの導入&mod_phpとの比較
- 4月 3, 2011 0
//php the_content_rss('', FALSE, '', 68); ?>
今週の木曜日に、Sydphpに行ってきました。
今回のお題は、Aimee-Maree Forsstromがmod_phpとfastcgiの比較、Phil Taylorがセキュリティについて話す予定でしたが、急遽が参加できなくなったので、@predominantがオープンソースの活用&運営について話してくれました。
せっかくだったので、自宅にかえって早速fastcgiを導入してみました。
fastcgiの存在は知っていたのですが、導入の経験がないので自宅サーバに導入(CentOS5.5,Apache2.0)検証してみました。
fastcgiについて
@aimee_mareeのスライドはこちらで確認ができます。
mod_phpとfastcgiを比較して、いかにfastcgiがが素晴らしいかを説いてくれました。
@aimee_mareeのまわりでも、圧倒的にmod_phpが一般的で、そのことがかなり腹立たしいとのことです。
要因としては、Apacheの標準であること、ホスティングサーバがmod_phpを使用していること、fastcgiの情報がまだまだ少ないことが原因のようです。
僕の英語力では、70%ほどしか理解できなかったのですが、こちらのページに日本語で詳細が記載してあるのでこちらをご確認ください。
FastCGI環境を構築する – ぱせらんメモ
CentOSにインストール
ちなみに、fastcgiには、mod_fastcgi、mod_fcgidの2種類があるようです。
今回は、mod_fcgidが早いとのことなので、mod_fcgidを導入しました。
検討に参考にさせてもらったサイト
Apache2 – mod_fcgid vs mod_fastcgi
Apache/FastCGI
すこし手間取ったので、そのトラブルと解決方法も記載しておきます。
最新mod_fcgidをcheckout、APXSのエラー
$ svn checkout http://svn.apache.org/repos/asf/httpd/mod_fcgid/trunk mod_fcgid $ cd mod_fcgid $ ./configure.apxs .configure.apxs must be able to find apxs in your path, or the environment variable APXS must provide the full path of APXS, or you may specify it with:
httpd-develのインストール&APXSのパスを指定して再度インストール
$ yum install httpd-devel $ APXS=/usr/sbin/apxs ./configure.apxs $ make $ make install
mod_fcgidの設定
ちなみに、mod_phpで構築してあるのですが、mod_fcgidとの共存が可能です。
下記のfcgid.confの中で場所を指定出来るようです。
参考サイト
Apache Module mod_fcgid
$vi /etc/httpd/conf.d/fcgid.conf
<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
<Directory "/home/mizoshiri/work/www/test3.40">
# SetHandler fcgid-script
FCGIWrapper /usr/bin/php-cgi .php
# DirectoryIndex index.php
Options +ExecCGI
# AllowOverride None
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</IfModule>
$ /etc/rc.d/init.d/httpd restart
インストール後は、phpinfo()でmodの中にmod_fcgidが表示されるようになります。
ベンチマークしてみる
せっかくなので、mod_phpとの比較したいので、ベンチマークをやっておきました。
phpのベンチマーク
PHPのベンチマークはPearのBenchmark
下記のコマンドでインストール
#pear install Benchmark
ベンチマークは、下記の参考サイトにある、フィボナッチ数列のベンチマークを使用しました。
僕の認識では、php自体の処理に関しては、変わらないはず。間違ってるかな???結果的には、やはりほぼ変わらず。
コードの最適化に役立つPHPスクリプトのベンチマーク
PHPのベンチマーク結果
Apacheのベンチマーク
Apacheのベンチマークは、標準ではいっているabを使用しました。
apacheのベンチマークように、Wordpressをいれて、予め記事の中にいくつかの画像などを追加したものを準備しておきました。
下記のコマンドでベンチマークを取りました。
#ab -c 100 -n 1000 http://localhost/wp/?p=1
apacheのベンチマークは下記のサイトで詳細が確認できます。
@IT:Apacheパフォーマンス・チューニングのポイント(2/2)
Apacheのベンチマーク結果
導入前
$ab -c 100 -n 1000 http://localhost/wp/?p=1
Benchmarking test3.40 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests
Server Software: Apache
Server Hostname: localhost
Server Port: 80
Document Path: /?p=1
Document Length: 103 bytes
Concurrency Level: 100
Time taken for tests: 0.648395 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 336336 bytes
HTML transferred: 103103 bytes
Requests per second: 1542.27 [#/sec] (mean)
Time per request: 64.840 [ms] (mean)
Time per request: 0.648 [ms] (mean, across all concurrent requests)
Transfer rate: 505.86 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 4.0 1 20
Processing: 9 58 10.0 61 66
Waiting: 5 56 10.0 58 64
Total: 11 60 8.5 62 82
Percentage of the requests served within a certain time (ms)
50% 62
66% 63
75% 65
80% 65
90% 66
95% 67
98% 69
99% 76
100% 82 (longest request)
導入後
$ ab -c 100 -n 1000 http://localhost/wp/?p=1
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests
Server Software: Apache
Server Hostname: localhost
Server Port: 80
Document Path: /?p=1
Document Length: 103 bytes
Concurrency Level: 100
Time taken for tests: 0.665636 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 336000 bytes
HTML transferred: 103000 bytes
Requests per second: 1502.32 [#/sec] (mean)
Time per request: 66.564 [ms] (mean)
Time per request: 0.666 [ms] (mean, across all concurrent requests)
Transfer rate: 492.76 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 3.7 2 19
Processing: 9 59 10.1 62 66
Waiting: 3 56 10.2 59 65
Total: 10 62 9.2 64 85
Percentage of the requests served within a certain time (ms)
50% 64
66% 66
75% 67
80% 68
90% 70
95% 70
98% 71
99% 78
100% 85 (longest request)
最後に
実際に導入してみたけど、上記の設定であっているのか不安でもありますので、
なにか間違っているところがありましたら、ご指摘いただけましたら幸いです。
12
- WindowsのapacheのVirtualHost設定(テスト)
- 7月 12, 2010 0
//php the_content_rss('', FALSE, '', 68); ?>
WindowsのローカルのVirtualHostでのテスト環境の設定をメモしておきます。
あくまでもテスト環境です。
httpd.conf の設定
XAMPPあたりでapacheをインストールした場合はなどは、C:\xampp\apache\confにある
Apacheのhttpd.confを変更します。
ServerNameのコメントアウト
# If your host doesn't have a registered DNS name, enter its IP address here. # You will have to access it by its address anyway, and this will make # redirections work in a sensible way. # #ServerName localhost コメントアウトしてください。
Directoryの書き換え
これで、D、Eなどにもてテスト環境が構築できます。
<Directory />
Options All
AllowOverride All
Order deny,allow
</Directory>
NameVirtualHost *:80の追加
NameVirtualHost *:80
httpd.conf にVirtualHostの設定を追加します。
<virtualhost *:80>
DocumentRoot D:\work/JCS/wp ドメインのRoot
ServerName test.local指定したいドメイン
</virtualhost>
apacheの再起動
サイトが確認できたら終わりです。
20
- Meadowでhttpd.confの編集をやり易くするapache-mode.elの紹介
- 8月 20, 2008 0
//php the_content_rss('', FALSE, '', 68); ?>
Unix的なアレのサイトで紹介されていたapache-mode.elが便利なので紹介したいと思います。
emacswikiから apache-mode.elのダウンロード
apache-mode.elのページからダウンロード選択してapache-mode.elを落として下記のフォルダにいれてください。
C:\meadow\site-lisp (ぼくの環境なので参考に)
.emacsに下記に内容を記入する。
ちなみに、「;;」はコメントです。
;; httpd.conf用
(autoload 'apache-mode "apache-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.htaccess\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("httpd\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("srm\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("access\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("sites-\\(available\\|enabled\\)/" . apache-mode))
完了です。
ちなみに、.htaccessなども対象にできるようですね。
hogehogeでファイル名をしてしているのでほかにも対象にしたいファイルは追加してください。
(add-to-list 'auto-mode-alist '("hogehoeg\\.conf\\'" . apache-mode))
13
- VirtualHostの設定方法
- 8月 13, 2008 0
//php the_content_rss('', FALSE, '', 68); ?>
VirtualHostの設定方法を紹介します。
VirtualHostを設定すると、複数のドメインを一台サーバで運営することができます。
httpd.conf の設定
Apacheのhttpd.confを変更します。
デフォルトなら、/etc/httpd/conf/httpd.conf あたりにいます。
みつからない時は、
locate httpd.conf
で探してください。
1.ServerNameのコメントアウト
# If your host doesn't have a registered DNS name, enter its IP address here. # You will have to access it by its address anyway, and this will make # redirections work in a sensible way. # #ServerName localhost コメントアウトしてください。
2.NameVirtualHost *:80の追加
NameVirtualHost *:80
3.httpd.conf にVirtualHostの設定を追加します。
<virtualhost *:80>
DocumentRoot /home/text/www/ ドメインのRoot
ServerName www.test.com 指定したいドメイン
</virtualhost>
4.apacheの再起動
Apacheの再起動方法はいろいろあります。
/etc/rc.d/init.d/httpd restart
/usr/sbin/apachectl restart
上記の3つすれば、とりあずVirtualHostの設定は完了です。
http://httpd.apache.org/docs/2.2/ja/vhosts/examples.html
18
- Windows環境でのVirtualHostの設定
- 5月 18, 2007 0
//php the_content_rss('', FALSE, '', 68); ?>
apacheのhttpd.conf
/extra/
└httpd-vhosts.conf
NameVirtualHost *:80を有効にして
localhost:81
など、ポート別にディレクトリを交換したい。
httpd.confの中のListen 80のとこにポートを増やす。
Listen 80
Listen 81
<VirtualHost *:82>
DocumentRoot “C:\Program Files/xampp/htdocs/work/”
ServerName localhost:82
</VirtualHost>





