apache+mod_php VS nginx+php-fpm(環境構築)

せっかく比較するので検証環境の構築も残しておきます。

検証環境

configオプション

php
'./configure' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--enable-mbstring' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-sockets' \
'--with-mysql=/usr/local/mysql/' \
'--with-curl' \
'--with-gmp' \
'--enable-bcmath' \
php-fpm
'./configure' \
'--prefix=/usr/local/php-fpm' \
'--enable-mbstring' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-sockets' \
'--with-mysql=/usr/local/mysql/' \
'--with-curl' \
'--with-gmp' \
'--enable-bcmath' \
'--enable-fpm' \
'--with-fpm-user=nginx' \
'--with-fpm-group=nginx'
apache
"./configure" \
"--prefix=/usr/local/apache2" \
"--with-apr=/usr/local/apache2" \
"--with-apr-util=/usr/local/apache2" \
"--enable-mods-shared=most" \
"--enable-ssl" \
"--with-ssl=/usr/local/ssl/" \
"--enable-so" \
nignx
"./configure" \
"--with-http_stub_status_module" \

とはいえ怒られたので、怒られたので、yumでpcre-develを入れる

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

yum install pcre-devel
mysql
"./configure" \
"--prefix=/usr/local/mysql" \
"--with-charset=utf8" \
"--with-mysqld-user=mysql" \
"--with-readline" \

conf

apache
--- conf/httpd.conf     2012-01-26 18:12:00.000000000 +0900
+++ conf/httpd.conf.20091227    2009-12-27 21:27:14.000000000 +0900
@@ -98,7 +98,6 @@
 LoadModule alias_module modules/mod_alias.so
 LoadModule rewrite_module modules/mod_rewrite.so
 LoadModule php5_module modules/libphp5.so
-LoadModule encoding_module modules/mod_encoding.so

 <IfModule !mpm_netware_module>
 <IfModule !mpm_winnt_module>
@@ -211,7 +210,7 @@
 # is requested.
 #
 <IfModule dir_module>
-    DirectoryIndex index.html index.php
+    DirectoryIndex index.html
 </IfModule>

 #
@@ -246,7 +245,7 @@
     # a CustomLog directive (see below).
     #
     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
-    LogFormat "%h %l %u %t \"%r\" \"%q\" %>s %b" common
+    LogFormat "%h %l %u %t \"%r\" %>s %b" common

     <IfModule logio_module>
       # You need to enable mod_logio.c to use %I and %O
@@ -308,10 +307,6 @@
     #Scriptsock logs/cgisock
 </IfModule>

-<IfModule php5_module>
-    AddType application/x-httpd-php .php
-</IfModule>
-
 #
 # "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased
 # CGI directory exists, if you have that configured.
@@ -437,7 +432,7 @@
 #Include conf/extra/httpd-info.conf

 # Virtual hosts
-Include conf/extra/httpd-vhosts.conf
+#Include conf/extra/httpd-vhosts.conf

 # Local access to the Apache HTTP Server Manual
 #Include conf/extra/httpd-manual.conf
@@ -446,10 +441,10 @@
 #Include conf/extra/httpd-dav.conf

 # Various default settings
-Include conf/extra/httpd-default.conf
+#Include conf/extra/httpd-default.conf

 # Secure (SSL/TLS) connections
-Include conf/extra/httpd-ssl.conf
+#Include conf/extra/httpd-ssl.conf
 #
 # Note: The following must must be present to support
 #       starting without SSL on platforms with no /dev/random equivalent
@@ -459,16 +454,3 @@
 SSLRandomSeed startup builtin
 SSLRandomSeed connect builtin
 </IfModule>
-
-<IfModule mod_headers>
-Header add MS-Author-Via "DAV"
-</IfModule>
-
-<IfModule mod_encoding>
-EncodingEngine    on
-NormalizeUsername on
-SetServerEncoding     UTF-8
-DefaultClientEncoding JA-AUTO-SJIS-MS SJIS
-AddClientEncoding "cadaver/" EUC-JP
-</IfModule>
nignx
[root@localhost nginx]# diff -ub conf/nginx.conf conf/nginx.conf.default
--- conf/nginx.conf     2012-02-07 14:20:11.000000000 +0900
+++ conf/nginx.conf.default     2012-02-07 02:23:41.000000000 +0900
@@ -1,8 +1,8 @@

-user  nobody;
-worker_processes  2;
+#user  nobody;
+worker_processes  1;

@@ -33,7 +33,7 @@
     #gzip  on;

     server {
-        listen       81;
+        listen       80;
         server_name  localhost;

         #charset koi8-r;
@@ -62,13 +62,13 @@

         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         #
-        location ~ \.php$ {
-            root           html;
-            fastcgi_pass   127.0.0.1:9000;
-            fastcgi_index  index.php;
-            fastcgi_param  SCRIPT_FILENAME  /data/www/test$fastcgi_script_name;
-            include        fastcgi_params;
-        }
+        #location ~ \.php$ {
+        #    root           html;
+        #    fastcgi_pass   127.0.0.1:9000;
+        #    fastcgi_index  index.php;
+        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
+        #    include        fastcgi_params;
+        #}

         # deny access to .htaccess files, if Apache's document root
         # concurs with nginx's one
@@ -76,21 +76,6 @@
         #location ~ /\.ht {
         #    deny  all;
         #}
-
-        location = /status {
-                include /usr/local/nginx/conf/fastcgi_params;
-                fastcgi_param SCRIPT_FILENAME /status;
-                fastcgi_pass 127.0.0.1:9000;
-                access_log off;
-                allow all;
-        }
-
-        location /nginx_status {
-                stub_status on;
-                access_log   off;
-                allow all;
-                #deny all;
-        }
     }
php-fpm
--- etc/php-fpm.conf    2012-02-07 18:25:56.000000000 +0900
+++ etc/php-fpm.conf.default    2012-02-07 02:19:03.000000000 +0900
@@ -22,7 +22,7 @@
 ; Pid file
 ; Note: the default prefix is /usr/local/php-fpm/var
 ; Default Value: none
-pid = run/php-fpm.pid
+;pid = run/php-fpm.pid

 ; Error log file
 ; If it's set to "syslog", log is sent to syslogd instead of being written
@@ -129,8 +129,8 @@
 ; Unix user/group of processes
 ; Note: The user is mandatory. If the group is not set, the default user's group
 ;       will be used.
-user = nobody
-group = nobody
+user = nginx
+group = nginx

 ; The address on which to accept FastCGI requests.
 ; Valid syntaxes are:
@@ -224,7 +224,7 @@
 ; This can be useful to work around memory leaks in 3rd party libraries. For
 ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
 ; Default Value: 0
-pm.max_requests = 500
+;pm.max_requests = 500

 ; The URI to view the FPM status page. If this value is not set, no URI will be
 ; recognized as a status page. It shows the following informations:
@@ -323,7 +323,7 @@
 ;       anything, but it may not be a good idea to use the .php extension or it
 ;       may conflict with a real PHP file.
 ; Default Value: not set
-pm.status_path = /status
+;pm.status_path = /status

ほとんでデフォからはいじってないです。
apacheは他にも使っているので、nginxをなるべくapacheの設定によせてます。

次回は、パフォーマンスの比較を行なっていきます。