Mac中如何安装PHP7,为什么brew 安装php7为什么找不到.so文件呢,安装php7后丢失libphp7.so了吗 。那安装brew install php72时怎么配置参数呢
常见问题 找不到libphp7.so
首先系统中brew 1.4.0版本
➜ apache2 git:(stable) ✗brew -v
Homebrew 1.4.0
Homebrew/homebrew-core (git revision 7990; last commit 2017-12-14)
➜ apache2 git:(stable) ✗
查看php72有哪些options选项可以安装,那其中--with-httpd看到没,这个就是libphp7.so文件的关键参数,其他参数根据需要自行选择。
➜ apache2 git:(stable) ✗brew options php72
--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-httpd
Enable building of shared Apache 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
那这里根据开发需要我选择了自己需要的参数,命令如下,要先解绑之前的PHP版本,如下执行过程:
➜ apache2 git:(stable) ✗ brew install php72 --with-httpd --with-debug --with-imap --with-mssql --with-pear --with-postgresql --with-webp
==> Installing php72 from homebrew/php
Error: Cannot install homebrew/php/php72 because conflicting formulae are installed.
php71: because different php versions install the same binaries.
Please `brew unlink php71` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.
➜ apache2 git:(stable) ✗ brew unlink php71
Unlinking /usr/local/Cellar/php71/7.1.12_23... 39 symlinks removed
➜ apache2 git:(stable) ✗ brew install php72 --with-httpd --with-debug --with-imap --with-mssql --with-pear --with-postgresql --with-webp
Updating Homebrew...
==> Installing php72 from homebrew/php
==> Installing dependencies for homebrew/php/php72: libsodium
==> Installing homebrew/php/php72 dependency: libsodium
==> Downloading https://homebrew.bintray.com/bottles/libsodium-1.0.16.sierra.bottle.tar.gz
############################################################ 100.0%
==> Pouring libsodium-1.0.16.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/libsodium/1.0.16: 71 files, 945.3KB
==> Installing homebrew/php/php72 --with-webp --with-postgresql --with-httpd --with-debug --with-imap --with-mssql --with-pear
==> Downloading https://php.net/get/php-7.2.0.tar.bz2/from/this/mirror
==> Downloading from https://secure.php.net/get/php-7.2.0.tar.bz2/from/this/mirror
########################################################### 100.0%
==> ./configure --prefix=/usr/local/Cellar/php72/7.2.0_11 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/7.2 --with-config-file-path=
==> make
==> make install
==> /usr/local/Cellar/php72/7.2.0_11/bin/pear config-set php_ini /usr/local/etc/php/7.2/php.ini system
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php72/libexec/apache2/libphp7.so
SetHandler application/x-httpd-php
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini file can be found in:
/usr/local/etc/php/7.2/php.ini
✩✩✩✩ PEAR ✩✩✩✩
If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
chmod -R ug+w /usr/local/opt/php72/lib/php
pear config-set php_ini /usr/local/etc/php/7.2/php.ini system
✩✩✩✩ Extensions ✩✩✩✩
If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
PATH="/usr/local/bin:$PATH"
PHP72 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"
✩✩✩✩ FPM ✩✩✩✩
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php72/homebrew.mxcl.php72.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php72.plist
The control script is located at /usr/local/opt/php72/sbin/php72-fpm
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
PATH="/usr/local/sbin:$PATH"
You may also need to edit the plist to use the correct "UserName".
Please note that the plist was called 'homebrew-php.josegonzalez.php72.plist' in old versions of this formula.
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd option. See brew options php72 for more details.
To have launchd start homebrew/php/php72 now and restart at login:
brew services start homebrew/php/php72
==> Summary
🍺 /usr/local/Cellar/php72/7.2.0_11: 508 files, 69.4MB, built in 10 minutes 20 seconds
到此安装步骤完成,libphp7.so在目录/usr/local/Cellar/php72/7.2.0_11/libexec/apache2/libphp7.so下,具体使用请在apache配置文件httpd.conf中引入切换。
另外之前有版本的参数是--with--apache,旧版本在这里不予赘述。 希望本文可以帮助到你,欢迎指正和提问。
作者博客:开发者说PHPersay
网友评论