您的位置:首页 > 运维架构 > Apache

Set Up Apache2 With mod_fcgid And PHP5 On CentOS

2015-11-01 19:16 393 查看
1、mod_fcgid is not available in the official CentOS repositories, but there's a package in the EPEL repository.

安装EPEL repository:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
2、install Apache2, mod_fcgid, and PHP5

yum install httpd mod_fcgid php

If Apache2 was already installed with PHP5 as an Apache module, disable the PHP5 module.

把你配置文件中对应的所有内容注释:/etc/httpd/conf.d/php.conf

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
#<IfModule prefork.c>
#  LoadModule php5_module modules/libphp5.so
#</IfModule>
#<IfModule worker.c>
#  LoadModule php5_module modules/libphp5-zts.so
#</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
#AddHandler php5-script .php
#AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
#DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps


3、uncomment the line cgi.fix_pathinfo=1 in php.ini

cgi.fix_pathinfo=1

4、在/etc/httpd/conf.d/fcgid.conf文件结尾添加

PHP_Fix_Pathinfo_Enable 1

5、restart apache

6、We will run PHP using suExec; suExec's document root is
/var/www, as the following command shows:

/usr/sbin/suexec -V

7、创建一个虚拟主机,并为该虚拟主机指定新的用户名和用户组,并指定documentroot目录

8、

Therefore we cannot call the PHP binary (/usr/bin/php-cgi) directly because it is located outside suExec's document root. As suExec does not allow symlinks, the only way to solve the problem is to create a wrapper script for each
web site in a subdirectory of /var/www; the wrapper script will then call the PHP binary/usr/bin/php-cgi. The wrapper script must be owned by the user and group of each web site, therefore we need one
wrapper script for each web site. I'm going to create the wrapper scripts in subdirectories of/var/www/php-fcgi-scripts.

wapper 文件名:php-fcgi-starter

文件内容:

#!/bin/sh
PHPRC=/etc/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/bin/php-cgi


The PHPRC line contains the directory where the
php.ini file is located (i.e., /etc/ translates to/etc/php.ini).PHP_FCGI_MAX_REQUESTS is the maximum number of requests before an fcgid process is stopped and a new one
is launched.PHP_FCGI_CHILDREN defines the number of PHP children that will be launched.

The php-fcgi-starter scripts must be executable, and they (and the directories they are in) must be owned by the web site's user and group,
根据上面说明的,将wapper文件设置成对应的用户组和用户名,并设置成有可执行权限

9、VirtualHost 示例,修改成你自己对应的wapper文件名,对应的用户和组,对应的主目录

<VirtualHost *:80>
ServerName www.example1.com
ServerAlias example1.com
ServerAdmin webmaster@example1.com
DocumentRoot /var/www/web1/web/
<IfModule mod_fcgid.c>
SuexecUserGroup web1 web1
<Directory /var/www/web1/web/>
Options +ExecCGI
AllowOverride All
AddHandler fcgid-script .php
FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php
Order allow,deny
Allow from all
</Directory>
</IfModule>
# ErrorLog /var/log/apache2/error.log
# CustomLog /var/log/apache2/access.log combined
ServerSignature Off
</VirtualHost>


10、最后重启apache,一切ok

最后得到的Server API 不在是Apache2handler 而是 CGI/FastCGI

参考文档:https://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-centos-6.2

其他参考文档:http://tltech.com/info/php-on-fcgid/

备注:mod_fcgid 和 mod_fastcgi是两种不同的方式。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: