Install different php versions through brew on Mac

Source: Internet
Author: User
Tags gmp install brew php cli sapi tidy
: This article describes how to install different versions of php Through brew in Mac. For more information about PHP tutorials, see. Apache and php are already included in mac OS X 10.9.5, but they are not enabled by default.
The default APACHE version is Apache/2.2.26 (Unix), and php version is PHP 5.4.30. Due to the need of debugging programs, I need to install php5.3 of a lower version at the same time, but do not want to delete php 5.4 pre-installed in the system or upgrade/downgrade the php5.4 of the system. what should I do? In this case, you can use brew to install the new php version. The first step is to install brew Brew, which is a package management tool under Mac. you can install the development tool conveniently by hosting Mac-compatible compilation configurations and patches through Github. Mac comes with ruby, which makes it easy to install. It also automatically installs git for you. Official website: http://brew.sh in the mac terminal directly enter the command line:

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

After the installation is complete, we recommend that you perform self-check: brew doctor. if you see that Your system is ready to brew. then Your brew can be used. Common commands: (all software uses PHP5.5 as an example)

Brew update # update the brew installation package. it is recommended that you execute it each time.
Brew search php55 # search for php5.5
Brew tap maid/php # installation extension
Brew tap # view the list of installed extensions
Brew install php55 # install php5.5
Brew remove php55 # Uninstall php5.5
Brew upgrade php55 # upgrade php5.5
Brew options php55 # View php5.5 installation options
Brew info php55 # View php5.5 related information
Brew home php55 # visit the official php5.5 website
Brew services list # View services installed by the system through brew
Brew services cleanup # clear useless startup configuration files that have been uninstalled
Brew services restart php55 # restart php-fpm

Step 2: install PHP

Add the brew PHP Extension Library first:

Brew update
Brew tap homebrew/dupes
Brew tap homebrew/php
Brew tap maid/homebrew-php

You can run the brew options php53 command to check the options for installing php5.3. here I use the following options for installation:

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

Note: If you want to use apache under mac as the web server, add -- with-apache during compilation. if your web server is nginx, -- with-fpm must be added.

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 during PHP compilation Error, execute xcode-select -- install to reinstall Xcode Command Line Tools to solve this error (source: https://github.com/Homebrew/homebrew-php/issues/1181 ). After installing php, there will be a prompt. 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.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 ~ /. 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, 31 M, built in 12.9 minutes



Wait until PHP compilation is complete and start to install common PHP extensions. during the extension installation process, brew automatically installs the dependency package. use the brew search php53-command to check which extensions can be installed, then execute the brew install php53-XXX. Because Mac comes with php and php-fpm, you need to add the system environment variable PATH to replace the built-in 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 # Update configuration

How can 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 24 2015 12:40:58) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies # 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 have not installed the fpm mode of php, the php-fpm-v command displays the built-in mac:

$ 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 the PHP5.4 that comes with max. we need to modify the apache configuration file httpd. conf, the path of the loaded php5 module is directed to libphp5.so in the php5.3 directory just installed:

LoadModule php5_module/usr/local/opt/php53/libexec/apache2/libphp5.so


Restart apache. The php Version shown in the phpinfo () script becomes PHP Version 5.3.29.

The above introduces how to install different versions of php Through brew in Mac, including some content, and hope to help those who are interested in PHP tutorials.

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.