RHEL 8.6下NGINX+PHP无法通过Web执行Bash脚本求助
PHP exec无法执行bash脚本求助
我是PHP编程新手,可能犯了低级错误。在RHEL 8.6系统上部署NGINX与PHP环境后,编写了一个基础PHP脚本,但exec函数始终无法执行目标bash脚本。以下是相关文件内容与排查信息:
相关文件内容
test.php(路径:/usr/share/nginx/test.php)
<!DOCTYPE html> <html> <?php exec('/usr/share/nginx/html/ip.sh 2>&1'); $myFile = "/tmp/ip.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo nl2br($theData); ?> </body> </html>
ip.sh(路径:/usr/share/nginx/html/ip.sh)
#!/bin/sh ip a > /tmp/ip.txt chown nginx:nginx /tmp/ip.txt
排查信息
- 文件权限:
-rwxr-xr-x. 1 nginx nginx 60 Aug 26 08:36 ip.sh -rwxr-xr-x. 1 nginx nginx 920 Aug 26 10:59 test.php
- 进程运行身份:NGINX和PHP-FPM均以
nginx:nginx身份运行
root 1507889 1 0 10:56 ? 00:00:00 nginx: master process /usr/sbin/nginx nginx 1507890 1507889 0 10:56 ? 00:00:00 nginx: worker process nginx 1507891 1507889 0 10:56 ? 00:00:00 nginx: worker process nginx 1507892 1507889 0 10:56 ? 00:00:00 nginx: worker process nginx 1507893 1507889 0 10:56 ? 00:00:00 nginx: worker process
- SELinux状态:
-rwxr-xr-x. 1 nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 60 Aug 26 08:36 ip.sh -rwxr-xr-x. 1 nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 920 Aug 26 10:59 test.php
- sudoers配置:已在
/etc/sudoers中添加
nginx ALL=(user) NOPASSWD: /usr/share/nginx/html/ip.sh
恳请各位帮忙解决这个问题!
内容的提问来源于stack exchange,提问作者quarksrus
相关产品推荐
相关产品推荐

