在Centos 6上设置Apache 2.2 + FastCGI + SuExec + PHP-FPM

我试图在这里遵循这个非常详细的说明 ,我只是从www-data用户更改为apache用户,并使用/ var / www / hosts / sitename / public_html而不是/ home / user / public_html

不过,我花了整整一天的时间,试图找出为什么php文件内容显示不正确的分析。 我似乎无法解决这个问题。 以下是我目前的configuration:

/etc/httpd/conf.d/fastcgi.conf

User apache Group apache LoadModule fastcgi_module modules/mod_fastcgi.so # dir for IPC socket files FastCgiIpcDir /var/run/mod_fastcgi # wrap all fastcgi script calls in suexec FastCgiWrapper On # global FastCgiConfig can be overridden by FastCgiServer options in vhost config FastCgiConfig -idle-timeout 20 -maxClassProcesses 1 # sample PHP config # see /usr/share/doc/mod_fastcgi-2.4.6 for php-wrapper script # don't forget to disable mod_php in /etc/httpd/conf.d/php.conf! # # to enable privilege separation, add a "SuexecUserGroup" directive # and chown the php-wrapper script and parent directory accordingly # see also http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/ # FastCgiServer /var/www/www-data/php5-fcgi #AddType application/x-httpd-php .php AddHandler php-fcgi .php Action php-fcgi /fcgi-bin/php5-fcgi Alias /fcgi-bin/ /var/www/www-data/ #FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization #DirectoryIndex index.php # <Location /fcgi-bin/> # Order Deny,Allow # Deny from All # Allow from env=REDIRECT_STATUS SetHandler fcgid-script Options +ExecCGI </Location> 

/etc/httpd/conf.d/vhost.conf

 <VirtualHost> DirectoryIndex index.php index.html index.shtml index.cgi SuexecUserGroup www.mysite.com mygroup Alias /fcgi-bin/ /var/www/www-data/www.mysite.com/ DocumentRoot /var/www/hosts/mysite.com/w/w/w/www/ <Directory /var/www/hosts/mysite.com/w/w/w/www/> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> 

PS:1.另外,用PHP5.5,我甚至需要FPM还是已经包含了? 2.我正在使用mod_fastcgi,不知道这是否是问题,我应该切换到mod_fcgid? 互联网上的logging似乎有冲突,考虑哪一个更好。 我有很多虚拟主机在机器上运行,并希望能够为每个用户提供自己的opcache

首先,你太过分了。

你不需要suphp + php-fpm,因为它们基本上是一样的。

如果你想要多用户多虚拟环境,你应该使用下面的堆栈:

阿帕奇+的mod_fastcgi + PHP-FPM

php-fpm允许你定义可以在不同的用户下使用完全不同的php设置运行的池。

对于这个configuration,你需要将apache恢复到它的基本configuration:

 user apache group apache 

我假设你将在用户的homedirs public_html文件夹中运行你的虚拟主机

您需要将chmod / home /%user%改为755,并将public_html的组改为apache

 chown %user%:apache /home/%user%/public_html chomod 755 /home/%user% 

然后,您将为用户定义php-fpm池

 [%user%] listen = /var/run/php-fpm/%user%.socket listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = web listen.group = www listen.mode = 0666 user = %user% group = %userg% #pm.status_path = /fpm-status pm = ondemand pm.max_children = 20 #pm.start_servers = 6 #pm.min_spare_servers = 5 #pm.max_spare_servers = 10 pm.max_requests = 500 request_terminate_timeout = 600s rlimit_files = 131072 rlimit_core = unlimited catch_workers_output = yes php_admin_value[error_log] = /home/%user%/fpm-error.log php_flag[display_errors] = on php_flag[display_startup_errors] = on php_admin_flag[log_errors] = on php_admin_value[memory_limit] = 128M php_value[session.save_handler] = files php_value[session.save_path] = /tmp 

注意这是一个示例文件,我build议在生产机器上使用它之前修改它

在你安装和configurationmod_fastcgi后,你将需要为每个用户添加一个特殊的php处理程序,就像这样

 nano /etc/httpd/conf.d/php-fpm.conf Action fcgi-php-fpm /fcgi-php-fpm virtual Alias /fcgi-php-fpm /fcgi-php-fpm FastCgiExternalServer /fcgi-php-fpm -socket /var/run/php-fpm/web.socket -pass-header Authorization -idle-timeout 180 

并在您的虚拟主机文件

 <VirtualHost *:80> ServerName beforeafter.local ServerAlias www.beforeafter.local DocumentRoot /home/web/public_html/before DirectoryIndex index.htm index.html index.php ErrorLog /home/web/ba.error.log CustomLog /home/web/ba.access.log combined UseCanonicalName Off Options FollowSymlinks +Indexes RewriteEngine On AddType text/html .php AddHandler fcgi-php-fpm .php <Directory /> AllowOverride All </Directory> </VirtualHost> 

您的操作名称和处理程序名称必须匹配才能工作。

之后,每个用户以自己的名字运行php。

我build议禁用所有不必要的apache模块,以加快速度,并closuresSELinux,如果你不擅长configuration它。