当前位置:   article > 正文

mac 源码编译安装php8.3.9

mac php 8.3 配置

前提条件

确保你已经安装了 HomebrewXcode Command Line Tools。你可以通过以下命令安装它们:

  1. /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
  2. xcode-select --install

https://www.cnblogs.com/niuben/p/16109703.html

安装必要的依赖项

使用 Homebrew 安装 PHP 编译所需的依赖项:

brew install autoconf bison re2c libxml2 openssl@3 libiconv icu4c bzip2 readline krb5 curl

下载 PHP 源代码

PHP 官方网站下载源码包,或者使用 wget

  1. wget https://www.php.net/distributions/php-8.3.9.tar.gz
  2. tar -xvf php-8.3.9.tar.gz
  3. cd php-8.3.9

编写配置脚本

创建一个名为 configure_php.sh 的脚本文件,并写入以下内容:

  1. #!/bin/bash
  2. # 清理之前的编译结果
  3. make clean
  4. rm -rf config.cache
  5. # 设置PKG_CONFIG_PATH
  6. export PKG_CONFIG_PATH="/opt/homebrew/opt/krb5/lib/pkgconfig:/opt/homebrew/opt/openssl@3/lib/pkgconfig:/opt/homebrew/opt/libiconv/lib/pkgconfig:/opt/homebrew/opt/icu4c/lib/pkgconfig:/opt/homebrew/opt/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
  7. # 设置CFLAGS和LDFLAGS,确保不重复
  8. export CFLAGS="-I/opt/homebrew/opt/krb5/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/libiconv/include -I/opt/homebrew/opt/icu4c/include -I/opt/homebrew/opt/readline/include"
  9. export LDFLAGS="-L/opt/homebrew/opt/krb5/lib -L/opt/homebrew/opt/bzip2/lib -L/opt/homebrew/opt/libiconv/lib -L/opt/homebrew/opt/icu4c/lib -L/opt/homebrew/opt/readline/lib"
  10. # 运行配置脚本
  11. ./configure \
  12. --prefix=/usr/local/php \
  13. --with-config-file-path=/usr/local/php/etc \
  14. --with-config-file-scan-dir=/usr/local/php/etc/php.d \
  15. --enable-bcmath \
  16. --enable-calendar \
  17. --enable-exif \
  18. --enable-fpm \
  19. --enable-intl \
  20. --enable-mbstring \
  21. --enable-mysqlnd \
  22. --enable-opcache \
  23. --enable-pcntl \
  24. --enable-soap \
  25. --enable-sockets \
  26. --with-bz2=/opt/homebrew/opt/bzip2 \
  27. --with-curl \
  28. --with-freetype \
  29. --with-jpeg \
  30. --with-kerberos=/opt/homebrew/opt/krb5 \
  31. --with-libxml \
  32. --with-mysqli \
  33. --with-openssl=/opt/homebrew/opt/openssl@3 \
  34. --with-pdo-mysql \
  35. --with-pdo-sqlite \
  36. --with-readline=/opt/homebrew/opt/readline \
  37. --with-xsl \
  38. --with-zlib \
  39. --with-iconv=/opt/homebrew/opt/libiconv

运行配置脚本

赋予脚本执行权限并运行它:

  1. chmod +x configure_php.sh
  2. ./configure_php.sh

运行测试

建议在安装之前运行测试:

make test

编译和安装

运行以下命令进行编译和安装:

  1. make -j$(sysctl -n hw.ncpu)
  2. sudo make install

安装完成

  1. Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20230831/
  2. Installing PHP CLI binary: /usr/local/php/bin/
  3. Installing PHP CLI man page: /usr/local/php/php/man/man1/
  4. Installing PHP FPM binary: /usr/local/php/sbin/
  5. Installing PHP FPM defconfig: /usr/local/php/etc/
  6. Installing PHP FPM man page: /usr/local/php/php/man/man8/
  7. Installing PHP FPM status page: /usr/local/php/php/php/fpm/
  8. Installing phpdbg binary: /usr/local/php/bin/
  9. Installing phpdbg man page: /usr/local/php/php/man/man1/
  10. Installing PHP CGI binary: /usr/local/php/bin/
  11. Installing PHP CGI man page: /usr/local/php/php/man/man1/
  12. Installing build environment: /usr/local/php/lib/php/build/
  13. Installing header files: /usr/local/php/include/php/
  14. Installing helper programs: /usr/local/php/bin/
  15. program: phpize
  16. program: php-config
  17. Installing man pages: /usr/local/php/php/man/man1/
  18. page: phpize.1
  19. page: php-config.1
  20. Installing PDO headers: /usr/local/php/include/php/ext/pdo/

验证安装

安装完成后,检查 PHP 的版本和已启用的扩展:

  1. /usr/local/php/bin/php -v
  2. /usr/local/php/bin/php -m

配置 PHP 环境

为了方便使用,将 PHP 二进制文件添加到系统的 PATH 中:

  1. echo 'export PATH="/usr/local/php/bin:$PATH"' >> ~/.zshrc
  2. source ~/.zshrc

验证 PATH

重新打开终端或运行 source 命令后,验证 PHP 是否在 PATH 中:

php -v

你应该能够看到 PHP 版本信息。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/989061
推荐阅读
相关标签
  

闽ICP备14008679号