$ brew install [email protected] $ brew install [email protected] $ brew install [email protected] $ brew install [email protected] The first one will take a little bit of time as it has to install a bunch of brew dependencies. Subsequent PHP versions will install faster.
![Mac Mac](/uploads/1/2/5/6/125629720/698165667.jpg)
Step by step instructions to setup a local development environment running multiple versions of PHP simultaneously. Sure, you could use like many other developers out there, and there’s nothing wrong with that, but setting things up this way will give you a better understanding of how all of these things come together and nearly everything you learn here will help you in the future if you need to setup Linux servers; Which in all likelihood you will do as understanding is a useful skill to have. I took the steps below using a clean install of macOS Sierra, so hopefully I have covered everything that you need to do.
MacOS Sierra / Xcode is bundled with Apache and PHP, but we won’t be using these as it is an old version of PHP and messing around trying to update it could potentially break something. A disclaimer is necessary here, if you already have a functional development environment, and you decide to follow these steps, you can’t hold me responsible if it all goes wrong and you break your current setup. Install Xcode and Xcode Command Line Tools Open up the App Store and search for Xcode to install it. Once it has installed, you’ll need to open Xcode at least once as there is a Terms & Conditions prompt to accept before you can use the command line tools. Once you have got past the prompt, if any appears you may have already cleared it previously, open the Terminal and enter the command below to install Xcode Command Line Tools.
![Configure apache for php 7 mac high sierra vista Configure apache for php 7 mac high sierra vista](/uploads/1/2/5/6/125629720/194019849.png)
$ which apachectl /usr/local/bin/apachectl Homebrew installs everything within /usr/local/ so there is no danger of it conflicting with any system-level software. If you get anything else returned as the file path for apachectl, then something hasn’t been setup properly, likely your PATH isn’t setup correctly, run brew doctor again to check. Assuming everything is fine, we are now ready to start Apache. You’ll need to use sudo with this command because it opens port 80. Don’t use sudo when you don’t need to, it could mess up file ownership and/or permissions. ONLYFULLGROUPBY,STRICTTRANSTABLES,NOZEROINDATE,NOZERODATE,ERRORFORDIVISIONBYZERO,NOAUTOCREATEUSER,NOENGINESUBSTITUTION Now this is fine to leave as the default, I would recommend you leave the settings alone unless you have problems.
Initially I tried fixing some of the custom queries, but then started noticing problems from queries generated by WordPress’ getposts function, and as I work on so many different WordPress sites I figured that I would end up wasting loads of time trying to fix these on other sites. You can override this setting by creating a config file for mysql, create a file /usr/local/etc/my.cnf with these settings. $ brew services restart mysql Summary Now you should have everything you need to get started, each time you need to work on a new project, reference the previous steps to setup a new virtual host for it and restart Apache. In the future, if you need to install a different version of PHP, you can reference the steps here, and it should work. If you got stuck at any point, and want to reference my configuration files, you can browse them here: Further Reading. Written by Luke Armstrong December 28, 2016.