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
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
文件内容:
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文件名,对应的用户和组,对应的主目录
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是两种不同的方式。
安装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是两种不同的方式。
相关文章推荐
- 太乱了的apache,我自己都无语了
- PHP环境搭建:Windows7系统配置PHP+Apache+MySQL环境教程
- ubuntu安装mysql+php+apache
- apache(OS 10013)以一种访问权限不允许的方式做了一个访问套接字的尝试 ...
- Azure上Linux VM防DDOS攻击:使用Apache mod_evasive
- Apache配置——监听多个端口 对应多个不同的网站目录
- Cannot load php5apache2_4.dll into server解决办法;
- 国家商用密码(八)在Apache MINA上实现文本流的SM4编解码器
- 国家商用密码(七)在Apache MINA上实现二进制流的SM4编解码器
- 怎么修改Xampp中Apache服务器的端口号
- apache-cxf 使用整理
- apache-hama-kcore
- Apache Mahout的KMeans算法测试
- Ubuntu Apache2开启mod_rewrite解决laravel路由失效问题
- cloud not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:release from any
- MAC 搭建腾讯云(centOS) apache+php+mysql 持续更新...
- LAMP环境(linux+apache+mysql+php)配置
- 64位Win7系统中配置Apache+Mysql+PHP环境
- Linux中如何安装Apache服务器
- apache的rewrite_module模块加载