apache php suphp,使用suphp来执行php

安装环境

apache php 都是用Yum安装

# yum install httpd php php-cli

保证php有php-cgi,因为suphp需要php的执行模式为cgi/fastcgi

[vnp.unscnb.com:/root]#php -v

PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)

Copyright (c) 1997-2008 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

[vnp.unscnb.com:/root]#php-cgi -v

PHP 5.2.6 (cgi-fcgi) (built: May  5 2008 10:29:53)

Copyright (c) 1997-2008 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Suphp安装

#tar zvxf suphp-0.7.1.tar.gz

#cd suphp-0.7.1

Suphp的编译参数有2种 主要是setid-mode的区别

1、测试模式,没有任何安全所言

#./configure --prefix=/usr/local/suphp \

--sysconfdir=/usr/local/suphp/etc \

--with-apache-user=apache \

--with-setid-mode=owner \

--with-apxs=/usr/sbin/apxs \

--with-apr=/usr/bin/apr-1-config

2、生产模式使用下面的配置

#./configure --prefix=/usr/local/suphp \

--sysconfdir=/usr/local/suphp/etc \

--with-apache-user=apache \

--with-setid-mode=paranoid\

--with-apxs=/usr/sbin/apxs \

--with-apr=/usr/bin/apr-1-config

具体2者的区别 将在后面apache配置那里说明

# make

# make install

# mkdir/usr/local/suphp/etc

#cp doc/suphp.conf-example /usr/local/suphp/etc/suphp.conf

编辑suphp.conf

# vi/usr/local/suphp/etc/suphp.conf

###########----------------------------------

[global]

;日志文件的产生路径

logfile=/var/log/httpd/suphp.log

;日志级别"info", "warn", "error", "none".

loglevel=info

;User Apache is running as

webserver_user=apache

;Path all scripts have to be in

docroot=/

;Path to chroot() to before executing script

;chroot=/mychroot

;安全选项,根据自己需要开启

;allow_file_group_writeable=false

allow_file_group_writeable=true

allow_file_others_writeable=false

;allow_directory_group_writeable=false

allow_directory_group_writeable=true

allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT

check_vhost_docroot=true

;check_vhost_docroot=false

;Send minor error messages to browser

errors_to_browser=false

;PATH environment variable

env_path=/bin:/usr/bin

;Umask to set, specify in octal notation

umask=0077

;最小uid和最下gid是指web运行的用户和组必须大于等于这个数,否则由于安全员应无法运行,这个设置根据自己来设置,一般uid=500 gid=100

min_uid=1000

min_gid=1000

[handlers]

;必须执行cgi模式的php,这个很重要

;x-httpd-php="php:/usr/bin/php"

x-httpd-php="php:/usr/bin/php-cgi"

;Handler for CGI-scripts

x-suphp-cgi="execute:!self"

##################---------------------------------------

整合apache

注销所有原先php和apache的配置选项,包括模块

# vi /etc/httpd/conf.d/suphp.conf

####--------------

LoadModule suphp_module modules/mod_suphp.so

NameVirtualHost *:80

ServerName 127.0.0.1

DocumentRoot /var/www/svnadmin

DirectoryIndex index.php

#开启suphp引擎

suPHP_Engine on

#指定/var/www/svnadmin的运行用户和组

suPHP_UserGroup webtest1 suphp

#指定执行的扩展名

AddHandler x-httpd-php .php .php3 .php4 .php5

suPHP_AddHandler x-httpd-php

#指定php的配置文件

suPHP_ConfigPath /etc/php.ini

###########-------------

需要注意的事项

1、假设apache设置的DocumentRoot "/var/www/html",那么/var/www的目录的所有者和组必须是root:root权限一般设置755

2、所有的虚拟主机web目录,必须放置在/var/www下,不能放置在apache设置的DocumentRoot目录下

3、假设我有一个/webserver/www/test的虚拟主机,此时/webserver/www的宿主和组必须是root:root

测试是否成功

编写index.php

Phpinfo();

?>

打开web浏览发现

Server API

CGI/FastCGI

就表示成功

2、源码安装

suphp比(就是原来)要快一点;比suphp更快的还有;再快一些的是,不过安装配置的麻烦程度也随之递增。

相比而言,suPHP速度还算可以接受(对于负载不是很大的站),配置方便,不用修改每个virtualhost的参数(就是$HOME/conf/vhost.conf),直接改apache的总conf就ok了,当然也比上面fastcgi方式下用event触发脚本来实现更加简洁。

ApacheSuexec

1、yum安装

... and set gpgcheck to 0 and enabled to 1 in the [kbs-CentOS-Testing] section:

[...]

[kbs-CentOS-Testing]

name=CentOS.Karan.Org-EL$releasever - Testing

gpgcheck=0

gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt

enabled=1

baseurl=http://centos.karan.org/el$releasever/extras/testing/$basearch/RPMS/

# yum install httpd mod_fcgid php-cli

整合apache

注销所有原先php和apache的配置选项,包括模块

在php.ini的最后加上下面的语句

cgi.fix_pathinfo = 1

# groupadd web1

# useradd -s /bin/false -d /var/www/web1 -m -g web1 web1

# chmod 755 /var/www/web1

# mkdir -p /var/www/web1/web

# chown web1:web1 /var/www/web1/web

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

# /usr/sbin/suexec -V

-D AP_DOC_ROOT="/var/www"

-D AP_GID_MIN=100

-D AP_HTTPD_USER="apache"

-D AP_LOG_EXEC="/var/log/httpd/suexec.log"

-D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"

-D AP_UID_MIN=500

-D AP_USERDIR_SUFFIX="public_html"

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, e.g. /var/www/php-fcgi-scripts/web1

# mkdir -p /var/www/php-fcgi-scripts/web1

# vi /var/www/php-fcgi-scripts/web1/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

# chmod 755 /var/www/php-fcgi-scripts/web1/php-fcgi-starter

# chown -R web1:web1 /var/www/php-fcgi-scripts/web1

# vi /etc/httpd/conf.d/fcgid.conf

#######################--------------------------------

# This is the Apache server configuration file for providing FastCGI support

# through mod_fcgid

#

# Documentation is available at http://fastcgi.coremail.cn/doc.htm

LoadModule fcgid_module modules/mod_fcgid.so

# Use FastCGI to process .fcg .fcgi & .fpl scripts

# Don't do this if mod_fastcgi is present, as it will try to do the same thing

#

#    AddHandler fcgid-script fcg fcgi fpl

#

# Sane place to put sockets and shared memory file

SocketPath run/mod_fcgid

SharememPath run/mod_fcgid/fcgid_shm

IPCConnectTimeout 10

IPCCommTimeout 20

OutputBufferSize 0

MaxRequestsPerProcess 500

#AddHandler fcgid-script .fcgi .php

NameVirtualHost *:80

ServerName fcgi.test.com

DocumentRoot /var/www/fcgi

SuexecUserGroup webcgi fcgi

PHP_Fix_Pathinfo_Enable 1

AddHandler fcgid-script .php

Options +ExecCGI

AllowOverride All

FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php

Order allow,deny

Allow from all

ServerSignature Off

Q:Apache reports "SuexecUserGroup directive requires SUEXEC wrapper." warning during startup.A:warning, 原因是错误的suEXEC权限设置。

查看 :    # ls -la /usr/sbin/suexec

应该为: -rwsr-xr-x 1 root root 12064 2008-04-17 01:15 /usr/sbin/suexec

主要是s权限即UID。如果权限和上面的不一样,修改:

# sudo chown root:root /usr/sbin/suexec

# sudo chmod 4755 /usr/sbin/suexec

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值