CentOS 7上PHP默认是以apache或者nobody的身份运行的,这种方式下由于PHP运行需要的权限比较大,会有安全隐患,还可能会受到服务器其他用户影响。
通过phpinfo查看PHP信息如下:
apache运行php
可以看出来,PHP目前是作为Apache的一部分在运行,而不会为每个脚本运行一个独立进程。如果希望PHP脚本运行时是以当前用户的身份而不是Apache,可以通过部署suPHP来实现。接下来介绍如何在CentOS 7上安装suPHP。
先配置安装suphp所需的环境:
yum -y groupinstall 'Development Tools'
yum -y install apr-devel
yum -y install httpd-devel
下载suphp安装包:
mkdir temp
cd temp
wget http://suphp.org/download/suphp-0.7.2.tar.gz
tar zxvf suphp-0.7.2.tar.gz
下载并安装suphp补丁:
wget -O patchingsuphp.patch https://www.webhostinghero.com/downloads/php/suphp.patch
patch -Np1 -d suphp-0.7.2 < patchingsuphp.patch
cd suphp-0.7.2
autoreconf -if
运行./configure:
./configure --prefix=/usr/ --sysconfdir=/etc/ --with-apr=/usr
/bin/apr-1-config --with-apache-user=apache --with-setid-mode=owner
--with-logfile=/var/log/httpd/suphp_log
编译并安装:
make
make install
在Apache配置目录下创建suphp.conf
vi /etc/httpd/conf.d/suphp.conf
并写入:
LoadModule suphp_module modules/mod_suphp.so
/etc目录下创建suphp.conf配置文件:
vi /etc/suphp.conf
并写入配置文件内容如下:
[global]
;Path to logfile
logfile=/var/log/httpd/suphp.log
;Loglevel
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
; Security options
allow_file_group_writeable=true
allow_file_others_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false
;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true
;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
; Minimum UID
min_uid=100
; Minimum GID
min_gid=100[handlers]
;Handler for php-scripts
x-httpd-suphp="php:/usr/bin/php-cgi"
;Handler for CGI-scripts
x-suphp-cgi="execute:!self"
如果希望domainname这个目录以用户user身份运行,那么修改目录所有者属性为user,如下:
chown -R [user].[user] /var/www/html/[domainname]
最后在Apache配置文件中找到相应域名,并开启suphp:
<FilesMatch ".+\.ph(p[345]">
SetHandler None
</FilesMatch>
<IfModule mod_suphp.c>
suPHP_Engine on
<FilesMatch "\.php[345]">
SetHandler x-httpd-suphp
</FilesMatch>
suPHP_AddHandler x-httpd-suphp
</IfModule>
最后重启Apache文件。通过info.php测试可以发现运行该域名的Server API已经由Apache变成CGI/FastCGI了,如下图所示:
到这里我们即完成了CentOS为某个域名访问设置通过suphp的方式来运行,而不用默认的Apache Handler运行。其他域名需要设置,按照以上步骤操作一遍即可。
CentOS安装suPHP
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 群星《歌手2024 第4期》[FLAC/分轨][563.76MB]
- RiffKitten-ChaosParade(2024)[24-44,1]FLAC
- RuneKlakegg-Nattevandrer(2024)[24-96]\FLAC
- 赖冰霞.2006-金嗓典藏辑2IN1(南方金点系列)2CD【南方】【WAV+CUE】
- 群星.1988-国语金曲尽精英VOL.2【瑞成】【WAV+CUE】
- 张宇.1999-雨一直下【EMI百代】【WAV+CUE】
- 袁娅维.2021-月亮失眠了(DELUXE)【华纳】【FLAC分轨】
- AlanBroadbent-JazzFunk(2024)[24-44,1]
- 梅艳芳《绝代芳华》开盘母带[低速原抓WAV+CUE]
- ABC唱片-《外国精逊母带直刻神奇黑胶[APE+CUE].
- 群星《天赐的声音第五季 第6期》[320K/MP3][101.43MB]
- 群星《天赐的声音第五季 第6期》[FLAC/分轨][526.16MB]
- 群星《说唱梦工厂 第2期》[320K/MP3][96.37MB]
- 杨宗宪.1994-留你留袂着【有容唱片】【WAV+CUE】
- 李翊君.2005-勇敢的爱【创意唱片】【WAV+CUE】