大网数据广告活动
服务器运维问答

How to allow just one site to use PHP's exec() function

· 52CE 我爱测

I have a simple Apache with mod_php server on CentOS 7. I've disabled the exec function in php.ini but I need to use it on one Vhost. Now obviously I know I can't use multiple php.ini files and I know I can't change the disable_f…

问题原文

原帖链接 · MyNameWouldGoHere · CC BY-SA 3.0

I have a simple Apache with mod_php server on CentOS 7. I've disabled the exec function in php.ini but I need to use it on one Vhost. Now obviously I know I can't use multiple php.ini files and I know I can't change the disable_functions setting outside of the php.ini file, so I tried toying with other ideas.

Obviously my first option was to use fastcgi, or suPHP, etc. but I couldn't get them to work without breaking the server, and whilst I probably could eventually make them work, I'd rather find a different solution and stick with the simple mod_php.

My second thought was to install Nginx and php-fpm and get it to listen on another port, but despite setting disable_functions to an empty value, it still read the php.ini file as well and thus disabled the php_exec function.

So is there a relatively simple way of achieving this without having to reset up Apache with fastcgi?

已采纳解答

原帖链接 · MyNameWouldGoHere · CC BY-SA 3.0

Well I have a pretty good answer, thanks to pointers from Aaron

Install Suhosin using this

yum install php-devel

wget http://download.suhosin.org/suhosin-0.9.33.tgz

tar -xvf suhosin-0.9.33.tgz

cd suhosin-0.9.33

phpize

./configure

make

make install

echo 'extension=suhosin.so' > /etc/php.d/suhosin.ini

service httpd restart

yum install php-devel

yum install php-suhosin

Add this to the bottom of php.ini file (a list of functions to blacklist):

suhosin.executor.func.blacklist = “exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source”

Finally, to the VirtualHost that should be allow to use the disabled functions, add this:

php_admin_value suhosin.executor.func.blacklist =

Suhosin forces a script to exit when it reaches a function that is blacklisted, rather than ignoring the function like the native disable functions setting.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。