简体   繁体   English

PHP 中的 shell_exec

[英]shell_exec in PHP

I have PHP code (setup.php) that execute bash-script, this is my code:我有执行 bash 脚本的 PHP 代码(setup.php),这是我的代码:

$hasil = shell_exec("./setup-srv.sh testajah mydomain.com");
echo "<pre>".$hasil."</pre>";

successfull when executed from commadline (setup-srv.sh), but failed when executed from browser (setup.php)从命令行(setup-srv.sh)执行时成功,但从浏览器(setup.php)执行时失败

these 2 files at /var/www/html/这两个文件位于 /var/www/html/

setup-srv.sh has several jobs: setup-srv.sh 有几个工作:

  • register subdomain to DNS server将子域注册到 DNS 服务器
  • create and populate data to mysql database创建数据并将其填充到 mysql 数据库
  • copy master folder and it's contents to new folder将主文件夹及其内容复制到新文件夹
  • execute certbot to new subdomain执行 certbot 到新的子域

I chmod 2 files with 777, but still failed.我用 777 chmod 2 个文件,但仍然失败。

I need help, thank you at advance.我需要帮助,提前谢谢你。

I'm assuming you're on a newer PHP than 5.3, or you have safe mode off.我假设您使用的是比 5.3 更新的 PHP,或者您已关闭安全模式。

This is likely to be an issue with the differences between your environment and the web server's environment.这可能是您的环境与 web 服务器环境之间存在差异的问题。

Things to try:要尝试的事情:

Unlikely to be the problem, but.. $hasil = shell_exec("/var/www/html/setup-srv.sh testajah mydomain.com");不太可能是问题,但是.. $hasil = shell_exec("/var/www/html/setup-srv.sh testajah mydomain.com");

SU to the webserver user and try to run the script, see what happens. SU 到网络服务器用户并尝试运行脚本,看看会发生什么。

Make sure SELinux isn't interfering with the webserver's ability to execute external programs.确保 SELinux 不会干扰网络服务器执行外部程序的能力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM