Before installing PHP, you must install the Command Line Tools for Xcode from the AppStore.
Xcode is an integrated development environment for Mac OS X and iOS. A full Xcode download is optional, just install the command line tools and the compiler. You can verify that Xcode is installed using the command:
$ xcode-select -р
If you are prompted to install the Command Line Tools instead of the path specified above, you should install this package by running the command:
$ xcode-select –install
Now you can begin to install PHP, for which it is best to use the Homebrew package manager. At the time of this writing, Homebrew could be installed using the command:
$ ruby -e “$(curl -fsSL https://raw.githubusercontent.cam/Homebrew/install/master/install)”
However, the exact command can always be found on the official website
http://brew.sh. After installation, the brew command will be available on the command line, with which you can download, remove, and update software packages.
Immediately after installation, it will not be superfluous to install additional libraries that may be required by PHP extensions:
$ brew install freetype jpeg libpng gd zlib
In order to access repositories with PHP distributions, you need to run a series of commands:
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php
By default, the
brew tap command assumes that the GitHub repository names are transferred to it. Thus, the previous commands register access to the following repositories:
You can independently find a distribution kit or alternative project on GitHub and add it to the Homebrew package manager. If the package is no longer needed, it can be removed with the brew untap command. Of course, if possible, use the official Homebrew packages.
После выполнения приведенных выше команд надо убедиться в том, что пакеты успешно добавлены. Для этого следует выполнить команду brew tap без параметров. В результате будет выведен список добавленных репозиториев.
$ brew tap
Now you can install PHP by running the install command:
$ brew install php71
After installing PHP is ready to work.
$ php -v
РНР 7.1.2 (cli) (built: Feb 17 2017 10:51:21) ( NТS )
Copyright (с) 1997-2017 The РНР Group
Zend Engine vЗ.1.0, Copyright (с) 1998-2017 Zend Technologies
If PHP is not available, you should make sure that the path to the Homebrew sbin directory is registered in the PATH environment variable in the file ~/.bash_profile:
# Homebrew sbin path