MAC OS X 10.9.5 system has its own Apache and PHP, but the default is not enabled, we will enable them.
The default version of Apache is apache/2.2.26 (Unix), and the PHP version is PHP 5.4.30.
I need to install a lower version of php5.3 at the same time as the debugger requires, but I don't want to remove the system preinstalled PHP 5.4, or upgrade/downgrade system php5.4, so what? At this point, you can install the new PHP version in brew mode.
The first step is to install brew first
Brew is the package management tool under Mac, which allows you to easily install development tools by Github managed for a MAC-compatible compilation configuration and Patch. The MAC is easy to install with Ruby, and it automatically installs git for you as well. Official website: http://brew.sh
Enter the command line directly from the Mac Terminal:
Ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"
After the installation is complete, it is recommended that you perform a self-test: Brew doctor if you see your system is ready to brew. Then your brew is ready to start using.
Common commands: (All software takes PHP5.5 as an example)
Brew Update #更新brew可安装包 It is recommended that you perform a
Brew Search Php55 #搜索php5.5
Brew Tap josegonzalez/php #安装扩展 <gihhub_user/repo>
Brew Tap #查看安装的扩展列表
Brew Install Php55 #安装php5.5
Brew Remove Php55 #卸载php5.5
Brew Upgrade Php55 #升级php5.5
Brew Options Php55 #查看php5.5 Installation Options
Brew Info php55 #查看php5.5 Related information
Brew Home Php55 #访问php5.5 official website
Brew Services List #查看系统通过 Brew-installed service
Brew Services Cleanup #清除已卸载无用的启动配置文件
Brew Services Restart Php55 #重启php-FPM
Step two, install PHP
Add Brew's PHP expansion Library first:
Brew Update
Brew Tap Homebrew/dupes
Brew Tap homebrew/php
Brew Tap josegonzalez/homebrew-php
You can use the Brew Options php53 command to view the options for installing php5.3, which I install with the following options:
Brew Install php53--with-apache--with-gmp--with-imap--with-tidy--with-debug
Please note that if you want to use Apache as a Web server under Mac, compile with--with-apache, and if your Web server is Nginx, you need to add--with-fpm.
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 instead 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 above)
--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
If you encounter Configure:error:Cannot find OpenSSL ' s <evp.h> error during HP compilation, perform xcode-select--install reinstall Xcode Command Line T Ools can resolve this error (Source: https://github.com/Homebrew/homebrew-php/issues/1181).
After installing PHP, there will be a hint, please read carefully:
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.so
The php.ini file can is found in:
/usr/local/etc/php/5.3/php.ini
✩✩✩✩pear✩✩✩✩
If Pear complains about permissions, ' fix ' 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 have issues with custom extension compiling, ensure that
You are are using the brew version, by Placing/usr/local/bin Before/usr/sbin in your PATH:
Path= "/usr/local/bin: $PATH"
PHP53 Extensions'll always be compiled against this PHP. Please install them
Using--without-homebrew-php to enable compiling against system PHP.
✩✩✩✩php Cli✩✩✩✩
If you are wish to swap the PHP with 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/launchagents
Then to load PHP53 now:
Launchctl Load ~/library/launchagents/homebrew.mxcl.php53.plist
==> Summary
/usr/local/cellar/php53/5.3.29:480 files, 31M, built in 12.9 minutes
Waiting for PHP to compile, start installing PHP Common extensions, Brew will automatically install the dependency pack during the extended installation process, use the Brew Search php53-command, you can see what extensions can be installed, and then execute the brew install PHP53-XXX.
Since the Mac comes with PHP and PHP-FPM, you need to add the system environment variable path instead of the PHP version:
Echo ' Export path= $ (brew--prefix homebrew/php/php53)/bin: $PATH "' >> ~/.bash_profile #for php
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 #更新配置
How do I uninstall the installed php5.3?
# Uninstall
Brew Uninstall PHP53
# Clear cache and old version files
Brew Cleanup-s
Test the effect:
$ php-v
PHP 5.3.29 (CLI) (Built:jan 2015 12:40:58) (DEBUG)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
# Mac system with PHP
$/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
Because we do not have the PHP fpm mode installed, the PHP-FPM-V command displays the Mac itself:
$ 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
This time, we use the Phpinfo function to display the PHP version or Max's own PHP5.4, we need to modify the Apache configuration file httpd.conf, the loaded PHP5 module path to the php5.3 directory just installed libphp5.so:
LoadModule php5_module/usr/local/opt/php53/libexec/apache2/libphp5.so
The PHP version that is displayed in the restart Apache,phpinfo () script is turned into PHP 5.3.29.