设为首页 收藏本站
查看: 912|回复: 0

[经验分享] 使用suphp来执行php

[复制链接]

尚未签到

发表于 2018-12-21 13:22:42 | 显示全部楼层 |阅读模式
  安装环境
  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安装
  # wget http://www.suphp.org/download/suphp-0.7.1.tar.gz
  # 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
  
  
  打开web浏览发现
  Server API
  CGI/FastCGI
  就表示成功
  
  
  2、 源码安装
  
  
  
  suphp比suexec(就是原来dv3.0升php5的方法)要快一点;比suphp更快的还有suphp_mod_php;再快一些的是mpm-peruser,不过安装配置的麻烦程度也随之递增。
  相比而言,suPHP速度还算可以接受(对于负载不是很大的站),配置方便,不用修改每个virtualhost的参数(就是$HOME/conf/vhost.conf),直接改apache的总conf就ok了,当然也比上面fastcgi方式下用event触发脚本来实现更加简洁。
  
  
  Apache Suexec
  1、yum安装
  # cd /etc/yum.repos.d/
  # wget http://centos.karan.org/kbsingh-CentOS-Extras.repo
  ... 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


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-654069-1-1.html 上篇帖子: PHP大马的简单解密 下篇帖子: PHP连接SQLServer2005
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表