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

群晖DiskStation中含mysqli的PHP文件命令行运行失败问题求助

Troubleshooting "Call to undefined function mysqli_connect()" on Synology CLI 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:
    php73 -c /usr/local/etc/php73/cli/php.ini /volume1/web/test.php
    
    This ensures you’re calling the exact PHP 7.3 binary aligned with your web setup.

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.php file 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.ini instead 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:
    php73 -m
    
    Look for mysqli in the output. If it’s missing, open the ini file you’re using and check for this line:
    extension=mysqli
    
    If it’s commented out (starts with ;), remove the ; to enable it. Also, confirm the extension_dir setting points to the directory where mysqli.so is 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 20:47:49