linux_web_服务器_php_配置指南
Linux Web 服务器 (PHP) 配置指南
PHP 的运行方式
PHP 有 CGI, FastCGI, Spawn-FCGI 以及 FPM 几种不同的工作方式。目前推荐使用 FPM 工作方式。
PHP-FPM 的配置
安装好 PHP 之后,修改 php-fpm 配置文件。下面是一份基本的配置文件
[global] error_log = log/php-fpm.log log_level = notice emergency_restart_threshold = 1 emergency_restart_interval = 1 daemonize = yes [www] listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 listen.owner = www-data listen.group = www-data listen.mode = 0666 user = www-data group = www-data pm = static pm.max_children = 8
lighttpd 的配置
使用 lighttpd 配合 PHP-FPM 使用基本与使用 Spawn-FCGI 时一致,均调用 fastcgi 模块。下面是一份工作的配置文件。
- 10-fastcgi.conf
server.modules += ( "mod_fastcgi" ) ## Start an FastCGI server for php (needs the php5-cgi package) fastcgi.server = ( ".php" => ( "localhost" => ( "host" => "127.0.0.1", "port" => "9000", "allow-x-send-file" => "enable" ) # ("socket" => "/dev/shm/php.socket", # "max-procs" => 40, # "allow-x-send-file" => "enable" # ) # 上面是使用 socket 方式连接 PHP 时使用的 ) )
nginx 的配置
nginx 配合 PHP-FPM 与以前配置类似。
- fastcgi.conf
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;
在 site 配置文件中,加入下面的内容即可。
location ~ \.php { fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi.conf; fastcgi_pass @php; }
linux_web_服务器_php_配置指南.txt · 最后更改: 2011/11/02 19:26 由 alex