Mac环境搭建PHP开发环境(一)------------------mac升级自带的PHP版本7及注意事项
题外话:在OSX 系统最好使用mac下的软件包管理brew安装:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew常用命令:
brew update #更新brew可安装包 brew search php70 #搜索php7.0 brew tap josegonzalez/php #安装josegonzalez 的php安装包 brew tap #查看安装的扩展列表 brew install php70 #安装php7.0 brew remove php70 #卸载php7.0 brew upgrade php70 #升级php7.0 brew options php70 #查看php7.0安装选项 brew info php70 #查看php7.0相关信息 brew home php70 #访问php7.0官方网站 brew services list #查看系统通过 brew 安装的服务 brew services cleanup #清除已卸载无用的启动配置文件 brew services restart php70 #重启php-fpm
2.install PHP
首先添加brew的PHP扩展库:
brew update brew tap homebrew/dupes brew tap homebrew/php brew tap josegonzalez/homebrew-php
可以使用 brew options php70 命令来查看安装php7.0的选项,显示如下
--with-cgi Enable building of the CGI executable (implies --without-fpm)
--with-debug Compile with debugging symbols --with-enchant Build with enchant support --with-gmp Build with gmp support --with-homebrew-curl Include Curl support via Homebrew --with-homebrew-libressl Include LibreSSL instead of OpenSSL via Homebrew --with-homebrew-libxml2 Include Libxml2 support via Homebrew --with-homebrew-libxslt Include LibXSLT support via Homebrew --with-httpd22 Enable building of shared Apache 2.2 Handler module --with-httpd24 Enable building of shared Apache 2.4 Handler module --with-imap Include IMAP extension --with-libmysql Include (old-style) libmysql support instead of mysqlnd --with-mssql Include MSSQL-DB support --with-pdo-oci Include Oracle databases (requries ORACLE_HOME be set) --with-pear Build with PEAR --with-phpdbg Enable building of the phpdbg SAPI executable --with-postgresql Build with postgresql support --with-thread-safety Build with thread safety --with-webp Build with webp support --without-bz2 Build without bz2 support --without-fpm Disable building of the fpm SAPI executable --without-ldap Build without LDAP support --without-legacy-mysql Do not include the deprecated mysql_ functions --without-mysql Remove MySQL/MariaDB support --without-pcntl Build without Process Control support --without-unixodbc Build without unixODBC support --HEAD Install HEAD version
这里我用下面的选项安装:
brew install php70 --with-apache --with-gmp --with-imap --with-tidy --with-debug
注意如果你希望以mac下的apache作为web server,编译时要加 --with-apache;如果你的web server 是 nginx这类,就需要加上 --with-fpm。重要的事情应定要看。
安装成功,命令行中输入php -v,还是会显示mac自带的旧版本。因此,我们还需要配置一下路径。
sudo vim ~/.bashrc
在文件末尾添加
![]()
最后命令行执行
source ~/.bashrc
全部搞定。命令行输入 php -v 显示
![]()
恭喜你成功了。

浙公网安备 33010602011771号