Install different versions of PHP under Mac with Brew

Source: Internet
Author: User
Tags gmp imap install brew mssql pear php cli snmp tidy
The MAC OS X 10.9.5 system has its own Apache and PHP, but it is not enabled by default, we will enable them.
the default version of Apache is apache/2.2.26 (Unix), PHP 5.4.30. as the debugger requires, I need to install the lower version of php5.3 , but do not want to delete the system pre-installed PHP 5.4, or upgrade/downgrade system php5.4, then how to do? At this point, you can install the new PHP version by using the Brew method. The first step is to install brew first Brew is the package management tool under Mac, and it's easy to install development tools by using Github to host your Mac-friendly compilation configuration and patches. Mac comes with Ruby so it's easy to install, and it automatically installs git as well. Official website:http://brew.sh Enter the command line directly in the Mac Terminal:

Ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"

after the installation is complete, it is recommended to perform a self test: Brew Doctor If you see your system is a ready-to-brew. Then your brew can start using it. Common commands: (All software with PHP5.5 as an example)

Brew Update #更新brew可安装包, it is recommended to perform each
Brew Search Php55 #搜索php5.5
Brew Tap josegonzalez/php #安装扩展
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 the Brew PHP Extension Library first:

Brew Update
Brew Tap Homebrew/dupes
Brew Tap homebrew/php
Brew Tap josegonzalez/homebrew-php

can use Brew Options Php53 command to view the options for installing php5.3, here I use the following options to install:

Brew Install php53--with-apache--with-gmp--with-imap--with-tidy--with-debug

Please note: If you want to use Apache under Mac as Web server, 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

PHP Compilation Process if you encounter Configure:error:Cannot Find OpenSSL ' s error, execution Xcode-select--install Reinstall Xcode Command Line Tools To resolve the 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 on 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 is 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 have a issues with a custom extension compiling, ensure that
You is using the brew version, by Placing/usr/local/bin Before/usr/sbin in your path:path= "/usr/local/bin: $PATH" PHP53 Extensions always is 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" has 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



wait for PHP to compile, start installing PHP common extensions, and during the extended installation, brew will automatically install the dependent packages, using Brew Search php53- command, you can see which 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 12:40:58) (DEBUG)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend technologies# mac system comes 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

since we do not have the FPM mode installed for PHP, the php-fpm-v command displays the Mac's own:

$ 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



At 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 shown in the Apache,phpinfo () script will be changed to PHP versions 5.3.29.

The above describes the Mac under the Brew to install different versions of PHP, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.