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

如何修复CentOS 6.5中yum安装php-mysqli及安装后的报错问题

Fixing PHP-MySQLi Issues on CentOS 6.5

Hey there, let’s work through these two php-mysqli headaches you’re facing on CentOS 6.5— I’ve debugged similar problems plenty of times, so let’s break it down step by step.


Problem 1: Errors when installing php-mysqli via YUM

CentOS 6 is past its end-of-life, so most default repos are no longer active, which is the #1 cause of YUM install failures here. Let’s cover the most common fixes:

  • Fix outdated YUM repos
    Since official CentOS 6 repos are offline, you’ll need to switch to archived repos. Here’s how:

    1. Back up your existing repo config:
      mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
      
    2. Create a new CentOS-Base.repo file with archived sources. Open it in an editor:
      vi /etc/yum.repos.d/CentOS-Base.repo
      
      Paste this content (uses an archived CentOS 6 repo):

      [base]
      name=CentOS-6 - Base - Archived
      failovermethod=priority
      baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/$basearch/
      gpgcheck=1
      gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

      [updates]
      name=CentOS-6 - Updates - Archived
      failovermethod=priority
      baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/$basearch/
      gpgcheck=1
      gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

      [extras]
      name=CentOS-6 - Extras - Archived
      failovermethod=priority
      baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/$basearch/
      gpgcheck=1
      gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

    3. Clean and refresh YUM cache:
      yum clean all && yum makecache
      

    Now try installing php-mysqli again with yum install php-mysqli.

  • Fix PHP version mismatches
    CentOS 6 ships with PHP 5.3 by default, but if you’ve installed a newer PHP version (like 5.4/5.5 from third-party repos), the package name might differ. First check your PHP version:

    php -v
    

    Then install the matching mysqli package— for example, if you’re on PHP 5.4, use yum install php54-mysqli.

  • Fix dependency conflicts
    If YUM throws dependency errors, try skipping broken packages temporarily (only do this if you’re sure the broken dependencies aren’t critical):

    yum install --skip-broken php-mysqli
    

    Or resolve the missing dependencies first by installing the required packages manually.


Problem 2: Abnormal behavior even after installing php-mysqli

Installing the package doesn’t always mean the extension is working correctly. Let’s troubleshoot the most common culprits:

  • Check if mysqli is enabled in PHP
    First verify if the extension is loaded:

    php -m | grep mysqli
    

    If there’s no output, it’s not enabled. Here’s how to fix that:

    1. Find your active php.ini file:
      php --ini | grep "Loaded Configuration File"
      
    2. Open the file in an editor and add/uncomment this line:
      extension=mysqli.so
      
    3. Restart your web service to apply changes:
      • For Apache: service httpd restart
      • For PHP-FPM (if using Nginx): service php-fpm restart
  • Verify extension path is correct
    Sometimes PHP can’t find the mysqli.so file. Check your extension directory:

    php -i | grep "extension_dir"
    

    Make sure mysqli.so exists in that path (e.g., /usr/lib64/php/modules/ for 64-bit systems). If not, you may need to specify the full path in php.ini:

    extension_dir = "/usr/lib64/php/modules/"
    extension=mysqli.so
    
  • Fix file permission issues
    Ensure the mysqli.so file has proper permissions for your web server to read it:

    chmod 644 /usr/lib64/php/modules/mysqli.so
    

    Also confirm the web server user (usually apache or nginx) has read access to the file and its parent directories.

  • Check MySQL-PHP compatibility
    CentOS 6’s default MySQL version is 5.1. If you’ve upgraded to MySQL 5.6+/MariaDB, there might be compatibility gaps with the system’s php-mysqli package. In this case, you can either:

    • Downgrade MySQL to 5.1 to match the system PHP
    • Recompile the mysqli extension against your newer MySQL version (more advanced)
  • Debug code-level issues
    Sometimes the problem isn’t with the extension itself, but your code. Test with a simple connection script to rule this out:

    <?php
    // Replace with your database credentials
    $host = 'localhost';
    $user = 'your_username';
    $pass = 'your_password';
    $dbname = 'your_database';
    
    $conn = mysqli_connect($host, $user, $pass, $dbname);
    if (!$conn) {
        die('Connection failed: ' . mysqli_connect_error());
    }
    echo 'Successfully connected to the database!';
    mysqli_close($conn);
    ?>
    

    Save this as test_mysqli.php in your web root, access it via browser, and check the exact error message— this will point you to whether it’s a connection issue or something else.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:37:02