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

Mac Catalina下安装php7.4的sqlsrv扩展失败:无法创建目录求助

Fixing "failed to mkdir" Error When Installing sqlsrv Extension on macOS Catalina

Hey there, let's work through this frustrating sqlsrv installation issue you're hitting on Catalina. That "failed to mkdir" error almost always boils down to permission problems or missing parent directories, so let's break down the fixes step by step:

Step 1: Manually Create the Target Directory & Set Correct Permissions

The error tells us pecl can't create /usr/local/Cellar/php/7.4.1/pecl/20190902—let's handle that ourselves:

  • First, check if the parent pecl directory exists:
    ls -ld /usr/local/Cellar/php/7.4.1/pecl/
    
  • If it doesn't exist (or the 20190902 subdir is missing), create it with sudo:
    sudo mkdir -p /usr/local/Cellar/php/7.4.1/pecl/20190902
    
  • Now set ownership to your user account (Homebrew expects your user to own these directories):
    sudo chown -R $(whoami):admin /usr/local/Cellar/php/7.4.1/pecl/
    
    This ensures pecl has full write access to the directory.

Step 2: Re-Run the pecl Installation

With permissions fixed, try installing sqlsrv again:

pecl install sqlsrv

If you have multiple PHP versions installed, specify the 7.4 version explicitly to avoid confusion:

php7.4 pecl install sqlsrv

Step 3: Check for macOS Catalina-Specific SIP Restrictions

While /usr/local isn't protected by System Integrity Protection (SIP), it's worth verifying just in case:

  • Run this command to check SIP status:
    csrutil status
    
    If SIP is enabled, that's fine—no need to disable it. The issue is still almost certainly permissions, not SIP.

Alternative: Manual Compilation & Installation

If pecl still fails, you can compile the extension manually:

  • Grab the sqlsrv source code compatible with PHP 7.4 (look for versions tagged for PHP 7.4 support)
  • Extract the archive, navigate to the source directory in your terminal
  • Run these commands to compile:
    phpize
    ./configure
    make
    sudo make install
    
  • After compilation finishes, copy the generated sqlsrv.so file to the target directory:
    sudo cp ./modules/sqlsrv.so /usr/local/Cellar/php/7.4.1/pecl/20190902/
    
  • Finally, add extension=sqlsrv.so to your PHP 7.4 php.ini file (you can find its location with php7.4 --ini)

Give these steps a shot—permission issues are the most common culprit here, so the first two steps should get you sorted. If you run into any other errors, feel free to share the details!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 18:32:41