简体   繁体   English

从终端运行shell脚本有效,但从PHP shell_exec运行时不起作用

[英]Running shell script from terminal works but doesn't work when running from PHP shell_exec

I've just started with shell scripts a week ago so please be easy on me. 我一周前才刚开始使用Shell脚本,所以请对我轻松一点。 When I run create.sh from the terminal, everything works great as expected. 当我从终端运行create.sh ,一切都按预期运行。 However when I execute the same script create.sh from create.php it doesn't work. 但是,当我从create.php执行相同的脚本create.sh ,它不起作用。

I'm executing my PHP script from the web browser by visiting the URL: http://192.168.8.108:8083/create.php 我正在通过访问以下网址从Web浏览器执行PHP脚本: http://192.168.8.108:8083/create.php : http://192.168.8.108:8083/create.php : http://192.168.8.108:8083/create.php

create.php – This file is responsible for running the create.sh file create.php –该文件负责运行create.sh文件

echo shell_exec('/usr/local/panel/bin/create.sh');

create.sh – This file creates a directory under /var/www . create.sh –此文件在/var/www下创建目录。 The permission 许可

#!/bin/bash
sudo mkdir -p /var/www/example.com
  • Owner : root Access : Read and Write 所有者 :root用户访问权限 :读写
  • Group : root Access : Read-only :root用户访问权限 :只读
  • Public : Access : Read-only 公开访问 :只读

You need to make sure that user who run php script has correct permission. 您需要确保运行php脚本的用户具有正确的权限。 If script create.php run as apache then you need to make sure apache user has write access to /var/www directory. 如果脚本create.phpapache create.php运行,则需要确保apache用户具有对/var/www目录的写权限。

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

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