Install different versions of php through brew on Mac
The default version of APACHE is Apache/2.2.26 (Unix), and the php version is PHP 5.4.30. Due to the need to debug the program, I need to install a lower version of php5.3 at the same time, but I don’t want to delete the system’s pre-installed php5.4, or upgrade/downgrade the system’s php5.4, so what should I do? At this time, you can install the new php version through brew. The first step is to install brew Brew is a package management tool for Mac. It hosts compilation configurations and patches suitable for Mac through Github, which makes it easy to install development tools. Mac comes with ruby, so it is very convenient to install, and it will also automatically install git for you. Official website: http://brew.sh Directly enter the command line 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 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 updateb rew tap homebrew/dupes
brew tap homebrew/ phpbrew tap josegonzalez/homebrew-php
You can use the
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
Wait for PHP to be compiled and start installing PHP commonly used Extension, during the extension installation process, brew will automatically install dependent packages. Use the brew search php53- command to check which extensions can be installed, and then execute brew install php53-XXX. Since 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
# 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
# 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
At this time, we use phpinfo The PHP version displayed by the function is still PHP5.4 that comes with max. We need to modify the apache configuration file httpd.conf. The path of the loaded php5 module points to libphp5.so in the php5.3 directory just installed:
LoadModule php5_module /usr/local/opt/php53/libexec/apache2/libphp5.so
Restart apache, and the php version displayed in the phpinfo() script will become PHP Version 5.3.29.
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
