使用mod_fcgid执行php脚本实例教程。
安装依赖
yum -y install gcc gcc-c++ libtool-libs autoconf freetype-devel gd libjpeg-devel libpng-devel libxml2-devel ncurses-devel zlib-devel curl-devel cmake patch automake make readline-devel openssl-devel glibc-devel glib2-devel bzip2-devel libcap-devel pcre-devel libmcrypt-devel
安装apache 2.2
cd /tmp
wget http://www.fayea.com/apache-mirror//httpd/httpd-2.2.22.tar.gz
tar xzf httpd-2.2.22.tar.gz
cd httpd-2.2.22
./configure –prefix=/usr/local/apache –with-included-apr –enable-so –enable-deflate=shared –enable-expires=shared –enable-ssl=shared –enable-headers=shared –enable-rewrite=shared –enable-static-support
make
make install
安装mod_fcgid
cd /tmp
wget http://www.fayea.com/apache-mirror//httpd/mod_fcgid/mod_fcgid-2.3.7.tar.gz
tar xzf mod_fcgid-2.3.7.tar.gz
cd mod_fcgid-2.3.7
APXS=/usr/local/apache/bin/apxs ./configure.apxs
make && make install
安装mysql
yum -y install mysql mysql-server mysql-devel
安装php
#安装libmcrypt(只在centos 6进行)
rpm -i http://centos.googlecode.com/files/libmcrypt-2.5.8-9.el6.i686.rpm
rpm -i http://centos.googlecode.com/files/libmcrypt-devel-2.5.8-9.el6.i686.rpm
cd /tmp
wget http://cn.php.net/distributions/php-5.2.17.tar.gz
tar xzf php-5.2.17.tar.gz
cd php-5.2.17
./configure –prefix=/usr/local/php –enable-fastcgi –enable-force-cgi-redirect –enable-discard-path –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-openssl –with-zlib –with-curl –enable-ftp –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –enable-gd-native-ttf –enable-mbstring –with-mcrypt –enable-zip –with-mysql –without-pear
make && make install
cp php.ini-recommended /etc/php.ini
配置apache
1、在/usr/local/apache/conf/httpd.conf增加如下内容:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.centos.bz
ServerAlias www.centos.bz centos.bz
DocumentRoot /var/www/html/
<IfModule mod_fcgid.c>
<Directory /var/www/html/>
Options +ExecCGI
AllowOverride All
AddHandler fcgid-script .php
FCGIWrapper /usr/local/php/bin/php-wrapper .php
Order allow,deny
Allow from all
</Directory>
</IfModule>
ServerSignature Off
</VirtualHost>
2、/usr/local/php/bin/php-wrapper内容如下:
#!/bin/sh
# Set desired PHP_FCGI_* environment variables.
# Example:
# PHP FastCGI processes exit after 500 requests by default.
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS
# Replace with the path to your FastCGI-enabled PHP executable
exec /usr/local/php/bin/php-cgi
启动服务
#启动mysql
service mysqld start
mysqladmin -uroot password root
#启动apache
/usr/local/apache/bin/apachectl -k start