This guide shows how to set up a PHP and MySQL development environment using OSX's built-in Apache, using Homebrew to install necessary components. With this strategy, you can use different versions of PHP for certain virtual hosts.
VirtualHostX is a convenient way to manage development sites, but not required.
Install PHP and MySQL with Homebrew
brew update
brew install php56
brew install php56-mcrypt
brew install mysql
mysql.server start
The mcrypt extension is required for some PHP frameworks such as Laravel.
Optional: Install other extensions or versions of PHP
brew install php56-xdebug
brew install php55
brew install php55-mcrypt
Configure PHP
Test PHP:
/usr/local/Cellar/php56/5.6.0/bin/php --version
This should yield PHP 5.6.0 (cli)
.
Edit your ~/.bash_profile
by adding the line:
alias php='/usr/local/Cellar/php56/5.6.0/bin/php'
alias php56='/usr/local/Cellar/php56/5.6.0/bin/php'
Test your PHP alias:
php --version
This should again yield PHP 5.6.0 (cli)
.
VirtualHostX
Configure VirtualHostX to use Built-in Apache instead of MAMP.
Create a new site with custom virtual host directives:
LoadModule php5_module /usr/local/Cellar/php56/5.6.0/libexec/apache2/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.html index.htm index.php
Optional: Apache Without VirtualHostX
You can achieve the above without VirtualHostX by manually editing:
/private/etc/hosts
/private/etc/apache2/httpd.conf
/private/etc/apache2/extra/httpd-vhosts.conf
MySQL
With a MySQL client such as Sequel Pro, connect to MySQL at 127.0.0.1
with the username root
and no password. Change the password if you like.
Permissions
Enable write permissions for Apache by changing its User and Group settings.
Edit /private/etc/apache2/httpd.conf
:
User your_mac_username
Group staff