返回列表 回复 发帖

apache上面运行suexec+php-fastcgi

OS:FreeBSD 7.2

相关的依赖可以用pkg_add -r packages安装不再说述

apache以worker运行

国内应该是第一篇在FreeBSD上面的类似文档,其它的都以mod_fcgid方式运行的居多。mod_fastcgi与mod_fcgid在虚拟主机上的优缺点自己去体会,这里不再讲述.

另:本人水平有限,错误在所难免,如有问题请跟贴指出.

注:欢迎转贴,但要注明出处[开源邮件技术社区]


安装apache
  1. wget http://apache.freelamp.com/httpd/httpd-2.2.14.tar.bz2
  2. tar -zxf httpd-2.2.14.tar.bz2
  3. cd httpd-2.2.14
  4. ./configure --prefix=/usr/local/apache2 --enable-isapi --enable-file-cache --enable-cache --enable-disk-cache --enable-expires --enable-headers --enable-proxy --enable-ssl --enable-http --enable-info --enable-cgi --enable-rewrite --enable-module=so --enable-suexec --with-suexec-docroot=/var/www --with-suexec-uidmin=1000 --with-suexec-gidmin=1000 --with-mpm=worker
  5. make && make install
复制代码
安装mod_fcgid模块
  1. wget 'http://downloads.sourceforge.net/project/mod-fcgid/mod-fcgid/mod_fcgid.2.2.tar.gz/mod_fcgid.2.2.tgz?use_mirror=nchc'
  2. tar -zxf mod_fcgid.2.2.tgz
  3. cp -r mod_fcgid.2.2 /usr/ports/distfiles/httpd-2.2.14/modules/
  4. cd /usr/ports/distfiles/httpd-2.2.14/modules/
  5. make && make install
复制代码
安装mod_fastcgi
  1. wget http://www.fastcgi.com/dist/mod_fastcgi-SNAP-0910052141.tar.gz
  2. tar -zxf mod_fastcgi-SNAP-0910052141.tar.gz
  3. cd mod_fastcgi-SNAP-0910052141
  4. cp Makefile.AP2 Makefile
  5. make && make install
复制代码
安装mod_cband
  1. http://cband.linux.pl/download/mod-cband-0.9.7.5.tgz
  2. tar -zxf mod-cband-0.9.7.5.tgz
  3. cd mod-cband-0.9.7.5
  4. ./configure --with-apxs=/usr/local/apache/bin/apxs
  5. make && make install
复制代码
配置fastcgi fcgi

vi  /usr/local/apache/conf/httpd
  1. LoadModule fastcgi_module modules/mod_fastcgi.so
  2. LoadModule fcgid_module modules/mod_fcgid.so
复制代码
编译php
  1. wget http://cn.php.net/get/php-5.3.1.tar.bz2/from/cn2.php.net/mirror
  2. tar -zxf php-5.3.1.tar.bz2
  3. cd php-5.3.1
  4. ./configure --prefix=/usr/local/php53 --with-mysql --with-mysqli --enable-fastcgi --enable-sockets --enable-ftp --enable-zip --enable-mbstring --enable-mbregex --enable-calendar --with-curl --with-curlwrappers --disable-debug --enable-inline-optimization --with-zlib --with-gd --with-kerberos --with-gettext --enable-force-cgi-redirect --with-jpeg-dir=/usr/local/include --with-png-dir==/usr/local/include --with-bz2 --enable-pcntl --with-iconv --with-mcrypt --with-pdo-mysql --with-freetype-dir=/usr/local/ --enable-path-info-check --with-openssl --with-xsl --enable-exif --with-mhash --enable-soap
  5. make && make install
复制代码
配置

虚拟主机配置文件
  1. #FastCgiIpcDir /tmp/
  2. FastCgiSuexec /usr/local/apache2/bin/suexec
  3. #FastCgiServer /usr/local/php53/bin/php-cgi -processes 10
  4. FastCgiConfig -maxClassProcesses 1 -singleThreshold 100 -killInterval 300 -autoUpdate -idle-timeout 240 -pass-header HTTP_AUTHORIZATION


  5. <VirtualHost *:80>
  6.         <Location /server-status>
  7.                 SetHandler server-status
  8.         </Location>

  9.         #服务器信息
  10.         <Location /server-info>
  11.                 SetHandler server-info
  12.         </Location>

  13.         DocumentRoot    /usr/local/apache2/htdocs

  14.         ServerName      error.com

  15. </VirtualHost>

  16. <VirtualHost *:80>
  17.     <IfModule suexec_module>
  18.           SuexecUserGroup vhost1 vhost1
  19.     </IfModule>

  20.     ServerAdmin     test@test.com
  21.     DocumentRoot    /var/www/vhost1/html

  22.     ServerName        test.com
  23.     ServerAlias        www.test.com

  24.     DirectoryIndex index.html index.php index.pl index.cgi

  25.     ScriptAlias /cgi-bin/ /var/www/vhost1/html/cgi-bin/
  26.     <Directory /var/www/vhost1/html/cgi-bin>
  27.         AllowOverride AuthConfig
  28.         #Options ExecCGI
  29.         Order allow,deny
  30.         Allow from all
  31.     </Directory>

  32.     <Directory /var/www/vhost1/html>
  33.         Options -Indexes Includes FollowSymLinks MultiViews
  34.         AllowOverride All
  35.         Order allow,deny
  36.         Allow from all
  37.     </Directory>

  38. <ifmodule fastcgi_module>
  39.    ScriptAlias /fcgi-bin/ /var/www/vhost1/php/
  40.      <directory /var/www/vhost1/php>
  41.        SetHandler fastcgi-script
  42.        AllowOverride None
  43.        Order allow,deny
  44.        Allow from all
  45.      </directory>
  46.    AddHandler php-fastcgi .php
  47.    Action php-fastcgi /fcgi-bin/php5-fcgi-starter
  48. </ifmodule>

  49. <IfModule mod_rewrite.c>
  50.     RewriteEngine On
  51. RewriteLog "/usr/local/apache2/logs/rewrite.log"
  52.         RewriteLogLevel 3
  53. </IfModule>

  54. </VirtualHost>
复制代码
php-fastcgi脚本
  1. #!/bin/sh

  2. umask 022

  3. PHPRC="/var/www/vhost1/php"

  4. export PHPRC
  5. PHP_FCGI_CHILDREN=1
  6. export PHP_FCGI_CHILDREN
  7. PHP_FCGI_MAX_REQUESTS=5000
  8. export PHP_FCGI_MAX_REQUESTS

  9. exec /usr/local/php53/bin/php-cgi -d open_basedir="/var/www/vhost1:/var/www/vhost1/phptmp/" -d upload_tmp_dir="/var/www/vhost1/phptmp/" -d session.save_path="/var/www/vhost1/phptmp" -d sendmail_path="/usr/sbin/sendmail -f vhost1 -t -i"
复制代码
完美解决apache+php虚拟主机权限问题及PHP木马的问题
Postfix技术专业支持论坛
http://www.thismail.org/bbs
-----------------------------------
提供专业postfix技术支持,邮件系统开发定制
QQ:187159779 注明(Postfix技术支持)
返回列表
开源邮件服务器 开源邮件服务器 web 开源邮件 开源 mail 开源 邮件服务器 邮件技术 mail技术 反垃圾邮件 反垃圾mail mail投递
邮件服务器 mail服务器 开源软件 mail软件 mail服务新品牌 开源邮件服务新品牌
开源mail服务新网站 邮件服务新品牌 mail tmail mailserver 163邮件 sendmail |Linux维护|Linux代维|成都Linux维护|成都Linux代维