This article has detailed steps on doing clean install of PHP 7.2 (latest PHP version as of August 2018). If you already have PHP installed via homebrew, then it requires you to first remove those PHP installations and then do the fresh PHP install. Reason of doing so, is to avoid conflicts that arise because of Homebrew March 2018 updates. Further details within blog!
Mar 16, 2020. Sep 13, 2019. Mar 04, 2020. Jul 23, 2018.
Homebrew When it comes to developing locally, there are many options for Mac users, including the dummy way of MAMP and XAMPP. However, for those who wants a NMP (Nginx, MySql, PHP. In February 2018, the php72 formula (the current version of PHP at that time) has been moved into the core Homebrew tap and renamed as php. The homebrew/php tap has been deprecated in January 2018 and then archived on March 31, 2018. The formulas it contained are not available any more. Since February 2018, installing PHP using Homebrew is as easy as.
Recently, I wanted to include a new module (visualception) in my test automation project that is built on top of codeception. In order to successfully make it work, there was a requirement to have php-imagick
extension already installed in your system.
Initial search showed that, in past you could have installed php-imagick
extension using command like brew install php71-imagick
, but this does not work any more of Homebrew updates. With the migration to Homebrew-core
, the php formula has stopped taking over the role of PECL. So now for installation of php extensions (like imagick or x-debug) you have to use PECL.
Due to older php installations, I was getting lot of issues while trying to install php-imagick extension. Ultimately, I was able to resolve all the problems by installing PHP from scratch. In below, I have listed all the steps for fresh PHP installation.
1. Prerequisite Steps For First Time PHP-Installation
1.1 First install xcode-command-line tools by running below command in terminal. If any popup message appears during installation, that needs to be confirmed. For further details on xcode tools, you may check this link.
1.2 As we are going to do all PHP related installations through macOS package manager Homebrew. So next we need to set it up by running below command:
Installation process will will show several prompts and may also ask for mac password. This may take a few minutes. Once it is done, you can verify the installation was successful by running below commands:
2. Remove EXISTING PHP (homeBREW) INSTALLATIONS
2.1 Removing all PHP-Homebrew related installations
First run below brew commands to make sure brew is updated and has no configuration issues.
If brew doctor or cleanup throws any errors then fix them as per instructions returned by brew-doctor or ask google
🙂
Now onto removing existing PHP-related installations (that were done by homebrew).
After above, again run brew cleanup
and brew doctor
to ensure everything working fine.
3. FINALLY… sTART WITH PHP INSTALLATION !
3.1 Run PHP Installation commands
Once done with above, now verify thatyou are running the correct homebrew–PHP by running type php
command. If it returns /usr/local/...anything.../php
then it means you are running homebrew-PHP. If it returns something like /usr/bin/php
then it means you are running apple-supplied-PHP. In that case you need to fix paths, as we want to use homebrew-PHP! Finally run brew doctor
to make sure everything is fine and no configuration errors are thrown.
3.2 Switching between PHP versions
Php Download Mac Using Brew Maker
If you have multiple php versions and want to switch between them, then you can do so by using brew link
and brew unlink
commands.
3.3 Install PHP extensions
As mentioned in start, php extensions such as php-imagick or php-xdebug which were previously installed by commands like (brew install php53-imagick
) now should be installed by PECL (for details on PECL check this link). Below are example commands for installation of xdebug and imagick extension.
Php Download Mac Using Brew Potions
Now you may run php -v
to verify php version and php -m
to check enabled extensions.