I could call it OS X tradition, Apple again broke the Apache 2 installation with latest OS X Yosemite upgrade. Let’s see how you can fix that and bring your local Apache2, PHP5 and MySQL development environment back.
I did very naive thing and just started the Apache 2 using sudo apachectl start . It worked, I got “It works!” page but nothing more. Then I reviewed Rob Allen’s article about setting up PHP & MySQL on Yosemite. He described steps on setting that on clean install but I needed to go through different steps as I had everything already installed. However, the article was helpful as it covered a few parts of the process.
If you have Apache 2 already installed, these steps can help you to go through to make it working again:
Update Apache 2 configuration
1. Uncomment Virtual Hosts line in Apache2 config (/etc/apache2/httpd.conf ) if you use that file to configure all hosts:
2. Change Access Control block in httpd.conf as it has changed in new Apache 2.4:
AllowOverride All Require all granted
3. Uncomment following lines to enable mod_rewrite and PHP5:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so LoadModule php5_module libexec/apache2/libphp5.so
4. Restart apache:
sudo apachectl restart
After doing these steps my local sites started working again along with PHP5. However, Yosemite upgrade also removed custom extensions and at least Xdebug and Mcrypt were missing.
I wanted to follow Rob’s guide regarding Mcrypt in which he used a Homebrew. Unfortunately the Homebrew didn’t worked for me as I didn’t upgrade that before upgrading OS X to Yosemite. I reinstalled the Homebrew then:
1. Remove old Homebrew
sudo rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
2. Install latest one
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
3.Run brew doctor
It came with a few recommendations. I fixed some of them, then I did the last one which was upgrading Xcode to 6.1. Actually Rob mentioned that in the article but I missed that part. It’s the following package:
Remember to run Xcode ater upgrading, it can save a lot of time later. I didn’t run that and I couldn’t get Mcrypt PHP extension installation working. After installing and running Xcode you also need to install Xcode command line tools. Run following in console to do so:
When Brew and Xcode are on their place, proceed to a Mcrypt installation.
That part comes from Rob Allen’s post mentioned earlier.
1. Install Mcrypt using brew:
brew install mcrypt
2. Prepare for PHP extension installation
Run following commands:
brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/php
I haven’t been able to run successfully some of these commands on my local. I needed to follow recommendations mentioned in commands output eg. to clean some symlinks, install some other packages using brew install, etc.
When these repositories are added, edit one broken file and apply patch:
3. Install PHP extension:
brew install php55-mcrypt --without-homebrew-php
4. Enable PHP extension:
sudo mkdir -p /Library/Server/Web/Config/php sudo ln -s /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini /Library/Server/Web/Config/php/ext-mcrypt.ini
Then restart apache again and mcrypt should work properly.
I’m really happy I made my development environment working after Yosemite upgrade. I also realized what should be the next step – I should get rid of MacPorts leftovers and make sure everything is installed using one package manager.
I hope these steps and Rob’s article can help you in fixing OS X web development environment.