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

Mac(Sierra 10.13)安装PHP 7.2线程安全版遇阻求助

解决macOS Sierra 10.13安装PHP 7.2线程安全版的问题

Hey there, I’ve dealt with this exact frustration before— Homebrew dropped thread-safety support for older PHP versions a while back, so let’s walk through two reliable ways to get a thread-safe (ZTS) PHP 7.2 build running on your Sierra system.

为什么Homebrew的方法没用?

Homebrew removed the --with-thread-safety flag from its PHP formulas because they focus on maintaining the non-thread-safe (NTS) build by default. That’s why you got the warning saying the option would be ignored— it no longer exists in the formula.


方案1:用php-build快速编译ZTS版本

php-build is a handy tool that takes the hassle out of compiling custom PHP versions. Here’s how to use it for ZTS:

  1. First, install php-build and all required dependencies (note we use openssl@1.1 since newer versions don’t support Sierra):

    brew install php-build autoconf automake libtool openssl@1.1
    
  2. Compile PHP 7.2 with ZTS enabled:

    PHP_BUILD_CONFIGURE_OPTS="--enable-maintainer-zts --with-openssl=$(brew --prefix openssl@1.1)" php-build 7.2.34 ~/local/php72-ts
    
    • Swap 7.2.34 for any 7.2.x patch version you need (all 7.2 releases are compatible here)
    • ~/local/php72-ts is where your PHP will be installed— feel free to change this path to something more convenient
  3. Check if it worked:

    ~/local/php72-ts/bin/php -v
    

    You’ll know it’s thread-safe if you see ZTS in the output, like this:

    PHP 7.2.34 (cli) (built: Oct 12 2024 10:30:00) ( ZTS )


方案2:手动编译PHP源码(完全可控)

If you want full control over every part of the build, go with manual compilation. Here’s the step-by-step:

  1. Install all build dependencies first:

    brew install openssl@1.1 curl libxml2 libjpeg libpng freetype autoconf automake libtool
    
  2. Grab the PHP 7.2 source code and extract it:

    curl -O https://www.php.net/distributions/php-7.2.34.tar.gz
    tar -xzf php-7.2.34.tar.gz
    cd php-7.2.34
    
  3. Configure the build with ZTS (adjust the flags to include any extensions you need):

    ./configure \
      --prefix=/usr/local/php72-ts \
      --enable-maintainer-zts \
      --with-openssl=$(brew --prefix openssl@1.1) \
      --with-curl \
      --with-libxml-dir=$(brew --prefix libxml2) \
      --with-jpeg-dir=$(brew --prefix libjpeg) \
      --with-png-dir=$(brew --prefix libpng) \
      --with-freetype-dir=$(brew --prefix freetype) \
      --enable-mbstring \
      --enable-cli
    
    • --enable-maintainer-zts is the key flag for thread safety (it replaced the old --with-thread-safety option you tried earlier)
    • Add flags like --enable-mysqlnd if you need MySQL support, or remove any extensions you don’t use
  4. Compile and install:

    # Use all your CPU cores to speed up compilation
    make -j$(sysctl -n hw.ncpu)
    sudo make install
    
  5. Verify the thread-safe build:

    /usr/local/php72-ts/bin/php -v
    

    Look for the ZTS tag in the version output to confirm it worked.


小提醒

  • macOS Sierra 10.13 is no longer supported, so some newer packages might fail to install. If you hit compilation errors, try installing older versions of problematic dependencies (e.g., brew install libxml2@2.9 if the latest version causes issues).
  • If you need to use this PHP with a web server like Apache or Nginx, add the corresponding SAPI flag during the configure step (e.g., --enable-apache2 for Apache).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:05:05