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

在ZesleCP(Ubuntu 16.04.4 x64)环境下安装MongoDB PHP驱动求助

Hey there, let's figure out how to install the MongoDB PHP driver on your Ubuntu 16.04.4 x64 server running ZesleCP. I’ve walked through similar setups before, so here’s a step-by-step guide that should get you up and running smoothly:

Step 1: Install System Dependencies First

Before we can compile the driver, we need to make sure all the necessary build tools and libraries are in place:

  • Update your system’s package list:
    sudo apt-get update
    
  • Install build essentials, PHP development headers, and MongoDB client libraries:
    sudo apt-get install build-essential php-dev php-pear libmongodb-dev
    
Step 2: Install the Driver via PECL

PECL is the simplest way to install PHP extensions, but we need to make sure we’re using the right PECL binary for your ZesleCP PHP setup:

  • If you’re using the system default PHP (check with php -v), run this command:
    sudo pecl install mongodb
    
  • If you’re using a custom PHP version managed by ZesleCP, you’ll need to use the PECL binary associated with that version. For example, if ZesleCP has PHP 7.4 installed, the path is likely /usr/local/zeslecp/php/7.4/bin/pecl. Run:
    sudo /usr/local/zeslecp/php/7.4/bin/pecl install mongodb
    
    Replace 7.4 with your actual PHP version number from ZesleCP’s control panel.
Step 3: Enable the Driver in PHP Configuration

Once the driver is installed, we need to tell PHP to load it:

  • For system PHP:
    Create a dedicated ini file for the extension:
    sudo echo "extension=mongodb.so" > /etc/php/7.0/mods-available/mongodb.ini
    
    Replace 7.0 with your PHP version (check the /etc/php/ directory for matching folders).
    Then enable the extension:
    sudo phpenmod mongodb
    
  • For ZesleCP’s custom PHP:
    Locate your PHP version’s php.ini file (usually at /usr/local/zeslecp/php/[version]/etc/php.ini). Open it with an editor like nano or vim, and add this line at the end:
    extension=mongodb.so
    
    Alternatively, you can create a mongodb.ini file in the conf.d directory under your PHP version’s folder (e.g., /usr/local/zeslecp/php/7.4/etc/conf.d/) with the same line.
Step 4: Restart Services to Apply Changes

ZesleCP uses either Apache or Nginx with PHP-FPM, so we need to restart these services to pick up the new extension:

  • If you’re using Apache:
    sudo systemctl restart apache2
    
  • If you’re using Nginx:
    sudo systemctl restart nginx
    sudo systemctl restart php7.4-fpm
    
    Again, replace 7.4 with your PHP version’s FPM service name—you can list available services with systemctl list-units | grep php-fpm.
Step 5: Verify the Installation

Let’s confirm the driver is loaded correctly:

  • Create a phpinfo.php file in your web root (e.g., /var/www/html/phpinfo.php) with this code:
    <?php phpinfo(); ?>
    
    Access it via your browser, then search for "mongodb"—you should see the extension listed with its details.
  • Or check from the command line:
    php -m | grep mongodb
    
    If it returns "mongodb", you’re good to go!
Quick Troubleshooting Tips
  • If pecl install fails with library errors, double-check that you installed libmongodb-dev and php-dev in Step 1.
  • If you can’t find ZesleCP’s PHP binaries, check the PHP settings section in your ZesleCP control panel—it should list the installation paths.
  • For older PHP versions (like PHP 5.6, which is default on Ubuntu 16.04), note that the legacy mongo driver (deprecated) is used instead of mongodb. If you must use it, run pecl install mongo—but I strongly recommend upgrading to a supported PHP version if possible.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:20:45