群晖DiskStation中含mysqli的PHP文件命令行运行失败问题求助
Let’s work through this issue systematically—since your script runs perfectly in Web Station but fails in the CLI even when pointing to the same php.ini, there are a few key areas to dig into:
1. Make sure you’re using the correct PHP version in the CLI
Synology often installs multiple PHP versions side by side. Running just php might invoke a default version that doesn’t match what Web Station uses, even if you specify a PHP 7.3 ini file.
- First, confirm Web Station’s PHP version: Head to Web Station > PHP Settings and double-check you’re using PHP 7.3.
- Instead of
php, use the version-specific binary to match Web Station:
This ensures you’re calling the exact PHP 7.3 binary aligned with your web setup.php73 -c /usr/local/etc/php73/cli/php.ini /volume1/web/test.php
2. Verify Web Station’s actual loaded php.ini path
Web Station uses PHP-FPM, which typically loads a different ini file than the CLI version. Your assumption that it uses /usr/local/etc/php73/cli/php.ini might be incorrect.
- Create a
phpinfo.phpfile in your web directory:<?php phpinfo(); ?> - Access it via your browser, then locate the Loaded Configuration File line. This is the real ini Web Station uses—it might be something like
/usr/local/etc/php73/fpm/php.iniinstead of the CLI variant. - Run your script with this corrected path:
php73 -c /usr/local/etc/php73/fpm/php.ini /volume1/web/test.php
3. Check if mysqli is enabled in the CLI PHP configuration
Even with the right ini path, the mysqli extension might not be enabled for the CLI.
- List loaded extensions for your PHP 7.3 CLI:
Look forphp73 -mmysqliin the output. If it’s missing, open the ini file you’re using and check for this line:
If it’s commented out (starts withextension=mysqli;), remove the;to enable it. Also, confirm theextension_dirsetting points to the directory wheremysqli.sois stored (usually/usr/local/lib/php73/modules/on Synology).
4. Confirm the configuration file is actually being loaded
Sometimes PHP might ignore the -c flag and fall back to a default ini. Verify which file is loaded with:
php73 -c /usr/local/etc/php73/cli/php.ini -i | grep "Loaded Configuration File"
If the output doesn’t match your specified path, double-check the path spelling or file permissions (ensure the CLI user can read the ini file).
5. Ensure the mysqli extension is installed for CLI PHP
Web Station often pre-installs required extensions, but the CLI version might not have them. Check Synology’s Package Center:
- Look for packages named "PHP 7.3 Extension" (or similar)
- Make sure the mysqli extension package for PHP 7.3 is installed. If not, install it and retest your script.
Following these steps should narrow down the root cause—most likely it’s a version mismatch, wrong ini path, or missing extension for the CLI environment.
内容的提问来源于stack exchange,提问作者Henry Finnell

