PHP调用Luminoth预测Shell脚本无响应问题求助
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
lumiin your local terminal:which lumi - Replace the
lumicommand in yourscript.shwith 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-datacan 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.inifile for thedisable_functionsdirective—ifexecis listed, you’ll need to remove it (or try alternatives likeshell_execif 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:
If it saysgetenforceEnforcing, try temporarily disabling it for testing:
If the script works after this, configure a proper SELinux policy instead of leaving it disabled long-term.sudo setenforce 0
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

