You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP调用Luminoth预测Shell脚本无响应问题求助

Troubleshooting PHP exec() Failure for Luminoth Prediction Script

Let's break down why your PHP call to the Luminoth prediction script isn't working, even though it runs fine locally. Here are the most likely fixes to try:

1. Capture Error Output First

The biggest blind spot right now is that you can't see why the script fails when called via PHP. Modify your PHP code to capture both standard output and error messages—this will give you concrete clues:

<?php
// Execute script and capture all output + return status code
exec("./script.sh 2>&1", $output, $return_code);

// Print debug info to see what's happening
echo "Return Code: $return_code<br>";
echo "Script Output:<br>";
print_r($output);
?>

This will reveal exactly what's going wrong—like missing commands, permission blocks, or invalid file paths.

2. Fix Environment & Command Path Issues

When you run the script locally, it uses your user's environment variables (including the PATH where lumi is installed). But PHP runs under the web server user (usually www-data), which has a much more restricted environment.

  • First, find the absolute path to lumi in your local terminal:
    which lumi
    
  • Replace the lumi command in your script.sh with this full path. For example:
    #!/bin/bash -l
    /usr/local/bin/lumi predict /full/path/to/image1.jpg --checkpoint instruments -f /var/www/html/pictures/predictions/objects.json -d /var/www/html/pictures/predictions/
    
  • Also, use an absolute path for image1.jpg—PHP's working directory might not match where your script is stored, so relative paths can break.

3. Verify File & Directory Permissions

Even though you set 777 on the script, the web server user needs access to all related resources:

  • Ensure www-data can read the input image and write to the output directory:
    # Assign ownership to the web server user (adjust if your user is different)
    sudo chown -R www-data:www-data /var/www/html/pictures/
    # Or set secure minimum permissions (better than 777 for long-term use)
    sudo chmod -R 755 /var/www/html/pictures/
    

Avoid using 777 permanently—it’s a major security risk. Stick to the least permissions needed for the job.

4. Check for Invalid Script Syntax

Double-check the --checkpoint flag in your script. Sometimes copy-pasting replaces the English double dash -- with a Chinese long dash –, which bash won’t recognize. Make sure it’s the correct English double dash:

# Wrong (Chinese dash):
lumi predict image1.jpg –checkpoint instruments ...

# Correct (English double dash):
lumi predict image1.jpg --checkpoint instruments ...

5. Rule Out Web Server Restrictions

  • PHP Disable Functions: Check your php.ini file for the disable_functions directive—if exec is listed, you’ll need to remove it (or try alternatives like shell_exec if allowed).
  • SELinux: If you’re on a system with SELinux enabled (like RHEL/CentOS), it might block the web server from executing external scripts. Check its status:
    getenforce
    
    If it says Enforcing, try temporarily disabling it for testing:
    sudo setenforce 0
    
    If the script works after this, configure a proper SELinux policy instead of leaving it disabled long-term.

Start with capturing error output first—it’s the fastest way to pinpoint the exact issue. Most of the time, problems like this come down to path or permission differences between your local user and the web server user.

内容的提问来源于stack exchange,提问作者Martin Hetzenegger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 21:57:47