php exec文件从终端运行,而不是从浏览器运行

我有一个应该启动屏幕保护程序的程序:

<?php
$cmd='automator /Users/myusername/Library/Services/Start_Screensaver.workflow';
shell_exec($cmd);
?>

当我用

php index.php

它工作正常,但是当我尝试从浏览器运行它时,我总是在apache error_log文件中得到以下错误:

The workflow file does not exist.

我觉得这很奇怪,因为我确实有从根文件夹开始的正确路径。任何帮助,将不胜感激。谢谢!

另外,尽管我非常确定apache在我的mac上已正确设置,但我只能通过mac本身上的mac的ip adres访问网页。因此,例如,当我在手机上访问Mac的IP时,它无法加载页面,但是当我访问Raspberry Pi的IP地址(也运行apache)时,它可以正常工作。

编辑:明确地说,这不是在Mac上启动屏幕保护程序,而是从Tasker内的手机远程启动屏幕保护程序。

编辑:我把自动化工作流文件放在同一目录中,并做了

sudo chmod 777 start_screensaver.workflow

现在出现以下错误:

2015-12-24 19:12:26.376 automator[2313:462937] Not loading action at /Library/Automator/Create Table from Data in Workbook.action: No bundleIdentifier.
2015-12-24 19:12:26.377 automator[2313:462937] Not loading action at /Library/Automator/Save Outlook Messages as Files.action: No bundleIdentifier.
2015-12-24 19:12:26.677 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.678 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.679 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.680 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.692 Automator Runner[2314:462973] Not loading action at /Library/Automator/Create Table from Data in Workbook.action: No bundleIdentifier.
2015-12-24 19:12:27.692 Automator Runner[2314:462973] Not loading action at /Library/Automator/Save Outlook Messages as Files.action: No bundleIdentifier.
2015-12-24 19:12:27.757 Automator Runner[2314:462973] Script Monitor is missing or damaged: Error Domain=NSCocoaErrorDomain Code=256 "The application “ScriptMonitor” could not be launched because a miscellaneous error occurred (OSStatus -10810)." UserInfo={NSURL=file:///System/Library/CoreServices/ScriptMonitor.app/, NSLocalizedDescription=The application “ScriptMonitor” could not be launched because a miscellaneous error occurred (OSStatus -10810)., NSUnderlyingError=0x7f80f3411190 {Error Domain=NSOSStatusErrorDomain Code=-10810 "kLSUnknownErr: Unexpected internal error"}}
2015-12-24 19:12:27.758 Automator Runner[2314:462973] Script Monitor is missing or damaged
2015-12-24 19:12:27.843 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.844 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.844 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.846 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.872 Automator Runner[2314:462980] warning: failed to get scripting definition from /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app; it may not be scriptable.
2015-12-24 19:12:27.966 Automator Runner[2314:462980] Scripting Bridge could not launch application /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app.
2015-12-24 19:12:27.997 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-user-standardLocations.plist: The folder “com.apple.automator.actionCache-user-standardLocations.plist” doesn’t exist.
2015-12-24 19:12:30.830 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-system-standardLocations.plist: The folder “com.apple.automator.actionCache-system-standardLocations.plist” doesn’t exist.
2015-12-24 19:12:31.148 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-bundleLocations.plist: The folder “com.apple.automator.actionCache-bundleLocations.plist” doesn’t exist.
亚历山大·米哈申科(Alexander Mikhalchenko)

看来您的Apache用户无权访问该目录。当您从cli运行php脚本时,您以的身份运行它们myusername,但是一旦从浏览器中打开它,它便是另一个用户_www)。

因此,您需要确保_www用户可以访问该文件777为该文件设置权限可能会起作用。

PS:btw @Mike绝对正确,您应该重新考虑使用脚本的方式。

UPD

屏幕保护程序启动,这很酷。因此,问题只与权限有关。因此,您可以尝试使用php内置服务器运行它

php -S localhost:8000 index.php

或配置apache并更改apache用户

另外,您也可以将所有与屏幕保护程序有关的内容移动到可公开访问的目录中,但这又可能会导致一些安全漏洞。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

浏览器试图下载PHP文件而不是运行它们(Linux Mint,Apache2)

来自分类Dev

文件不是从浏览器运行,而是从终端运行

来自分类Dev

如何在不使用php exec的情况下通过浏览器运行代码接收

来自分类Dev

如何在不使用php exec的情况下通过浏览器运行代码接收

来自分类Dev

当我在浏览器中访问目标php时,exec()才运行

来自分类Dev

使用 php 运行 python 脚本 - 在控制台中而不是在 Web 浏览器中工作

来自分类Dev

从命令行在浏览器中运行php文件

来自分类Dev

如果关闭浏览器,PHP代码是否继续运行?

来自分类Dev

从浏览器启动/停止在后台运行的php脚本

来自分类Dev

运行PHP脚本而不输出到浏览器

来自分类Dev

如何从Android的浏览器运行php脚本?

来自分类Dev

如何直接从Geany在浏览器中运行PHP代码?

来自分类Dev

我如何显示输出到终端而不是浏览器的php / html代码?

来自分类Dev

PHP exec运行文件

来自分类Dev

PHP可在命令行上运行,但不能在浏览器中运行

来自分类Dev

Myphp.php编辑器无法与浏览器一起运行

来自分类Dev

浏览器使用运行下载的PHP文件名下载文件

来自分类Dev

浏览器自动下载PHP文件

来自分类Dev

浏览器自动下载PHP文件

来自分类Dev

在浏览器中查看php文件?

来自分类Dev

在PHP中,即使浏览器退出后,如何确保脚本将继续运行直到完成?

来自分类Dev

终端和浏览器之间的PHP结果不同

来自分类Dev

通过CMD(Ubuntu)调用时,Apache下载PHP文件而不是在浏览器中显示

来自分类Dev

PHP中的popen()可从命令行运行,但不能从浏览器运行

来自分类Dev

php-在浏览器中显示png / image可以在localhost上运行,但不能在aws上运行

来自分类Dev

当运行5分钟的php脚本时,我无法在另一个浏览器选项卡中访问此文件

来自分类Dev

从另一个PHP文件运行一个php文件,就像我直接从浏览器中打开它一样(相对路径问题)

来自分类Dev

Cake PHP:由于浏览器缓存而引起的问题,站点在我的本地系统中正常运行,但是当移至远程服务器时却无法运行

来自分类Dev

使用PHP在浏览器中预览PDF文件

Related 相关文章

  1. 1

    浏览器试图下载PHP文件而不是运行它们(Linux Mint,Apache2)

  2. 2

    文件不是从浏览器运行,而是从终端运行

  3. 3

    如何在不使用php exec的情况下通过浏览器运行代码接收

  4. 4

    如何在不使用php exec的情况下通过浏览器运行代码接收

  5. 5

    当我在浏览器中访问目标php时,exec()才运行

  6. 6

    使用 php 运行 python 脚本 - 在控制台中而不是在 Web 浏览器中工作

  7. 7

    从命令行在浏览器中运行php文件

  8. 8

    如果关闭浏览器,PHP代码是否继续运行?

  9. 9

    从浏览器启动/停止在后台运行的php脚本

  10. 10

    运行PHP脚本而不输出到浏览器

  11. 11

    如何从Android的浏览器运行php脚本?

  12. 12

    如何直接从Geany在浏览器中运行PHP代码?

  13. 13

    我如何显示输出到终端而不是浏览器的php / html代码?

  14. 14

    PHP exec运行文件

  15. 15

    PHP可在命令行上运行,但不能在浏览器中运行

  16. 16

    Myphp.php编辑器无法与浏览器一起运行

  17. 17

    浏览器使用运行下载的PHP文件名下载文件

  18. 18

    浏览器自动下载PHP文件

  19. 19

    浏览器自动下载PHP文件

  20. 20

    在浏览器中查看php文件?

  21. 21

    在PHP中,即使浏览器退出后,如何确保脚本将继续运行直到完成?

  22. 22

    终端和浏览器之间的PHP结果不同

  23. 23

    通过CMD(Ubuntu)调用时,Apache下载PHP文件而不是在浏览器中显示

  24. 24

    PHP中的popen()可从命令行运行,但不能从浏览器运行

  25. 25

    php-在浏览器中显示png / image可以在localhost上运行,但不能在aws上运行

  26. 26

    当运行5分钟的php脚本时,我无法在另一个浏览器选项卡中访问此文件

  27. 27

    从另一个PHP文件运行一个php文件,就像我直接从浏览器中打开它一样(相对路径问题)

  28. 28

    Cake PHP:由于浏览器缓存而引起的问题,站点在我的本地系统中正常运行,但是当移至远程服务器时却无法运行

  29. 29

    使用PHP在浏览器中预览PDF文件

热门标签

归档