Home >Backend Development >PHP Tutorial >Install different versions of php through brew on Mac
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After the installation is complete, it is recommended to execute Do a self-check: brew doctor If you see Your system is ready to brew. Then your brew is ready to be used. Common commands: (All software uses PHP5.5 as an example)brew update brew tap josegonzalez/php #Install extension
brew tap #Uninstall php5.5
brew upgrade php55 #Upgrade php5.5
brew options php55 #View php5. 5 Installation options
brew info php55 # #
brew services cleanup #Clear uninstalled and useless startup configuration files
brew services restart php55 #Restart php-fpm
The second step is to install PHP
brew options php53
command to view the options for installing php5.3. Here I use the following options to install:
Options
--disable-opcache
Build without Opcache extension
--disable-zend-multibyte
Disable auto-detection of Unicode encoded scripts
--homebrew-apxs
Build against apxs in Homebrew prefix
--with-apache
Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache
--with-cgi
Enable building of the CGI executable (implies --without-apache)
--with-debug
Compile with debugging symbols
- -with-fpm
Enable building of the fpm SAPI executable (implies --without-apache)
--with-gmp
Build with gmp support
--with-homebrew-curl
Include Curl support via Homebrew
--with- homebrew-libxslt
Include LibXSLT support via Homebrew
--with-homebrew-openssl
Include OpenSSL support via Homebrew
--with-imap
Include IMAP extension
--with-libmysql
Include (old-style) libmysql support in stead of mysqlnd
--with-mssql
Include MSSQL-DB support
--with-pdo-oci
Include Oracle databases (requries ORACLE_HOME be set)
--with-phpdbg
Enable building of the phpdbg SAPI executable (PHP 5.4 and a bove )
--with-postgresql
Build with postgresql support
--with-thread-safety
Build with thread safety
--with-tidy
Include Tidy support
--without-bz2
Build without bz2 support
--without -mysql
Remove MySQL/MariaDB support
--without-pcntl
Build without Process Control support
--without-pear
Build without PEAR
--without-snmp
Build without SNmp support
--HEAD
Install HEAD version
Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php53/ libexec/apache2/libphp5.soThe php.ini file can be found in:
/usr/local/etc/php/5.3/php.ini???? PEAR ????
If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
chmod -R ug+w /usr/local/Cellar/php53/5.3.29/lib/php
pear config-set php_ini /usr/local/ etc/php/5.3/php.ini
???? 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"
PHP53 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/php53)/bin:$PATH"
To have launchd start PHP53 at Login:
LN -SFV /usr/local/opt/php53/*.plist ~/library/launchagentsthen to load PHP53 now:
LAUNCTL LOAD ~/ Library/launchagents/Homebrew. mxcl.php53.plist==> Summary
/usr/local/Cellar/php53/5.3.29: 480 files, 31M, built in 12.9 minutes
echo 'export PATH="$(brew --prefix homebrew/php/php53)/sbin:$PATH"' >> ~/.bash_profile #for php-fpm
echo 'export PATH="/usr/local/bin:/usr/local/sbin:$PATH"' >> ~/.bash_profile #for other brew install soft
source ~/.bash_profile #Update configuration
brew uninstall php53
# Clear cache and old version files
brew cleanup -s
Test the effect:
$php -v
PHP 5.3.29 (cli) (built: Jan 24 2015 12:40:58) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2 .3.0, Copyright (c) 1998-2014 Zend Technologies
# The php that comes with the mac system
$ /usr/bin/php -v
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
$php-fpm -v
PHP 5.4.30 (fpm-fcgi) (built: Jul 29 2014 23:44:15)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
LoadModule php5_module /usr/local/opt/php53/libexec/apache2/libphp5.so
The above introduces how to install different versions of php through brew on Mac, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.