澳门威尼斯人注册网址【官网首页】
做最好的网站

在RHEL 5.3(Tikanga)上配置Apache + FastCGI(mod_fcgid) + PHP

来源:http://www.ogcoffee123.com 作者: 计算机网络 人气:107 发布时间:2019-11-04
摘要:一,使用软件的详细版本信息如下: FastCGI is a protocol for interfacing interactive programs with a webserver. FastCGI's main aim is to reduce the overhead associated withinterfacing the web server and CGI programs, allowing

一,使用软件的详细版本信息如下:

FastCGI is a protocol for interfacing interactive programs with a web server. FastCGI's main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.

Apache(apache 2.2.15)

Also, PHP is not recommended with multithreaded Apache2 (worker MPM) because of performance and some 3rd party PHP extensions are not not guaranteed thread-safe.

Apache FastCGI module(mod_fcgid 2.3.6)

nginx and lighttpd has inbuilt sup

PHP 5.3.3(php-cgi)

port for FastCGI. For Apache web server you need to use either mod_fastcgi or mod_fcgid.
Why use mod_fastcgi instead of mod_perl / mod_php?
From the wikipedia article:

相关阅读:

Instead of creating a new process for every request, FastCGI can use a single persistent process which handles many requests over its lifetime. Processing of multiple requests simultaneously is achieved either by using a single connection with internal multiplexing (ie. multiple requests over a single connection) and/or by using multiple connections. Many such processes can exist, something that can increase stability and scalability. FastCGI also allows programs to get the web server to do certain simple operations, like reading in a file, before the request is handed over. Environment information and page requests are sent from the web server to the process over a TCP connection (for remote processes) or Unix domain sockets (for local processes). Responses are returned from the process to the web server over the same connection. The connection may be closed at the end of a response, but the web server and the process are left standing.

在RHEL 5.4(Tikanga)下搭建PHP+Memcached http://www.linuxidc.com/Linux/2012-02/53421.htm

Many web site administrators and programmers are finding that the separation of web applications from the web server in FastCGI (and the simpler SCGI) has many desirable advantages over embedded interpreters (mod_perl, mod_php, etc.). This separation allows server and application processes to be restarted independently -- an important consideration for busy web sites. It also facilitates per-application security policies -- important for ISPs and web hosting companies.

在RHEL 5.3(Tikanga)搭建Git http://www.linuxidc.com/Linux/2012-02/53420.htm

In this quick tutorial, you will learn about Apache 2 + mod_fastcgi + PHP installation and configuration under Red Hat Enterprise Linux / CentOS Linux version 5.x+.

在RHEL 5.3(Tikanga)上配置Apache + FastCGI(mod_fastcgi) + PHP http://www.linuxidc.com/Linux/2012-02/53419.htm 

Install mod_fastcgi
Make sure required packages are installed (httpd-devel and apr-devel required to compile mod_fastcgi), enter:
# yum install libtool httpd-devel apr-devel apr
Next, grab the latest mod_fastcgi source code, enter:
# cd /opt# wget
Untar tar ball, type:
# tar -zxvf mod_fastcgi-current.tar.gz# cd mod_fastcgi-2.4.6/
Make a copy of Makefile.AP2, enter:
# cp Makefile.AP2 Makefile
Compile and install mod_fastcgi for 32 bit system, enter:
# make top_dir=/usr/lib/httpd# make install top_dir=/usr/lib/httpd
Compile and install mod_fastcgi for 64 bit system, enter:
# make top_dir=/usr/lib64/httpd# make install top_dir=/usr/lib64/httpd
Sample output:

二,详细的配置步骤:

make install top_dir=/usr/lib64/httpd
make[1]: Entering directory `/tmp/mod_fastcgi-2.4.6'
/usr/lib64/apr-1/build/libtool --silent --mode=install cp mod_fastcgi.la /usr/lib64/httpd/modules/
make[1]: Leaving directory `/tmp/mod_fastcgi-2.4.6'Configure mod_fastcgi
Open /etc/httpd/conf.d/mod_fastcgi.conf file
# vi /etc/httpd/conf.d/mod_fastcgi.conf
Add an entry to it like this:
LoadModule fastcgi_module modules/mod_fastcgi.so
Save and close the file. Restart httpd, enter:
# service httpd restart
Sample output:

(下面步骤的前提是Apache和PHP(php-cgi)均已经安装)

[Mon Dec 29 23:24:44 2008] [notice] caught SIGTERM, shutting down
[Mon Dec 29 23:24:44 2008] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Dec 29 23:24:44 2008] [notice] Digest: generating secret for digest authentication ...
[Mon Dec 29 23:24:44 2008] [notice] Digest: done
[Mon Dec 29 23:24:44 2008] [notice] FastCGI: process manager initialized (pid 4785)
[Mon Dec 29 23:24:44 2008] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operationsHow do I configure PHP as FastCGI process under RHEL / CentOS Linux?
First, you need to disable mod_php5, enter:

1,安装mod_fcgid模块

# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disable
Create a shell script in cgi-bin directory called php.fcgi
Create a script as follows in /var/www/cgi-bin/php.fcgi (or put in your virtual domain cgi-bin directory)

1)下载地址:

#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec$PHP_CGISet permission, type:
# chmod +x /var/www/cgi-bin/php.fcgi
Finally, modify documentroot directory permission as follows. You need to use AddHandler and Action directives for mod_fastcgi:

 <Directory "/var/www/html">
   Options -Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    AddHandler php5-fastcgi .php
    Action php5-fastcgi /cgi-bin/php.fcgi
    DirectoryIndex index.php index.html
    Order allow,deny
    Allow from all
</Directory>Where,

2)从源代码编译安装

?AddHandler php5-fastcgi .php : To configure Apache to handle php files (within the scope of the directive) with the specified extension(s) as FastCGI applications.
?Action php5-fastcgi /cgi-bin/php.fcgi : This directive adds an action, which will activate cgi-script when action-type is triggered by the request. The cgi-script is the URL-path to a resource that has been configured as a CGI script using ScriptAlias. In our case, requests for files with a .php file extension of are handled instead by the specified cgi script /cgi-bin/php.fcgi.
Save and close the file. Restart httpd:

[root@www.linuxidc.com mod_fcgid-2.3.6]# whereis apxs

# service httpd restart
mod_fastcgi virtual hosting configuration
?Domain name: nixcraft.com
?DocumentRoot: /websites/home/nixcraft.com/http
?cgi-bin directory: /websites/home/nixcraft.com/cgi-bin
?php.fcgi path: /websites/home/nixcraft.com/cgi-bin/php.fcgi
?Logs file directory: /websites/home/nixcraft.com/logs
Based upon above settings your virtualhosting configuration for nixcraft.com domain should look like as follows:

apxs: /opt/httpd/bin/apxs
[root@www.linuxidc.com mod_fcgid-2.3.6]# APXS=/opt/httpd/bin/apxs ./configure.apxs

<VirtualHost *:80>
        ServerAdmin webmaster@nixcraft.com
        DocumentRoot "/websites/home/nixcraft.com/http"
        ServerName nixcraft.com
        ServerAlias www.nixcraft.com
        ErrorLog "/websites/home/nixcraft.com/logs/error.log"
        CustomLog "/websites/home/nixcraft.com/logs/access.log" common
        ScriptAlias /cgi-bin/ "/websites/home/nixcraft.com/cgi-bin/"
 
 <Directory "/websites/home/nixcraft.com/http">
  Options -Indexes FollowSymLinks +ExecCGI
  AllowOverride AuthConfig FileInfo
  AddHandler php5-fastcgi .php
  Action php5-fastcgi /cgi-bin/php.fcgi
  Order allow,deny
  Allow from all
 </Directory>
 
 <Directory "/websites/home/nixcraft.com/cgi-bin">
  AllowOverride None
  Options None
  Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>Create a /websites/home/nixcraft.com/cgi-bin/php.fcgi as follows:

[root@www.linuxidc.com mod_fcgid-2.3.6]# make

#!/bin/bash
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec$PHP_CGISet permission and restart httpd:

[root@www.linuxidc.com mod_fcgid-2.3.6]# make install

# chmod +x /websites/home/nixcraft.com/cgi-bin/php.fcgi# service httpd restart

(使用updatedb手动刷新locate数据库,使用locate mod_fcgid.so检查mod_fcgid是否安装成功。)

图片 1

2,配置Apache

1)查找二进制文件php-cgi的路径(这里我使用从源代码编译安装PHP 5.3.3在/opt目录下,读者可以使用locate php-cgi来查找。)

/opt/bin/php-cgi

2)修改php-cgi使用的php.ini

cgi.fix_pathinfo=1

3)修改Apache的配置文件/opt/httpd/conf/httpd.conf

a, 分别在适当位置添加添加下面两行:

[xhtml]

  1. LoadModule fcgid_module modules/mod_fcgid.so  
  2. Include conf.d/php-fcgid.conf  

b, 在/opt/httpd/conf.d目录下建立php-fcgid.conf

[xhtml]

  1. <IfModule fcgid_module>  
  2.     # FcgidMaxRequestsPerProcess should be <= PHP_FCGI_MAX_REQUESTS  
  3.     # The example PHP wrapper script overrides the default PHP setting.  
  4.     FcgidMaxRequestsPerProcess 10000  
  5.     # Uncomment the following line if cgi.fix_pathinfo is set to 1 in  
  6.     # php.ini:  
  7.     FcgidFixPathinfo 1  
  8.     # Define a new handler "php-fcgi" for ".php" files, plus the action that must follow  
  9.     AddHandler php-fcgi .php  
  10.     Action php-fcgi /cgi-bin/php.fcgi  
  11. </IfModule>  

 

c, 在/opt/cgi-bin目录下建立php.fcgi(注意修改此文件的权限为755)

[xhtml]

  1. #!/bin/bash  
  2. # Path to php.ini  
  3. PHPRC=/usr/local/lib  
  4. ### Set PATH ###  
  5. PHP_CGI=/opt/bin/php-cgi  
  6. PHP_FCGI_CHILDREN=0  
  7. PHP_FCGI_MAX_REQUESTS=1000  
  8. ### no editing below ###  
  9. export PHPRC  
  10. export PHP_FCGI_CHILDREN  
  11. export PHP_FCGI_MAX_REQUESTS  
  12. exec $PHP_CGI  

 

d, 检查配置语法是否正确,然后使用apachectl重启Apache

[root@www.linuxidc.com www]# /opt/httpd/bin/apachectl configtest
Syntax OK
[root@www.linuxidc.com www]# /opt/httpd/bin/apachectl restart

 

e, 在/opt/httpd/www目录下建立config.inc.php,使用浏览器访问。(若配置正确,那么PHP Variables栏目下的_SERVER["SERVER_SOFTWARE"]一项的值为:Apache/2.2.15 (Unix) mod_fcgid/2.3.6)

[php]

  1. <?php phpinfo(); ?>  

图片 2

图片 3

本文由澳门威尼斯人注册网址发布于 计算机网络,转载请注明出处:在RHEL 5.3(Tikanga)上配置Apache + FastCGI(mod_fcgid) + PHP

关键词:

最火资讯