Apache2 is already installed on any Mac and most setups (like MAMP or MacPorts) just ignore the built in Apache and install their own version. Shame. You wouldn’t ignore your own car just and get another one to pull a trailer while your own car can do the job perfectly.
Choose OSX Version: 10.6 | 10.7 | 10.8
Before you begin; This post is the first post in a series to build the “perfect” setup. See ‘The “Ultimate” Guide …’ or the menu on the right side here for a complete list of all related posts. Also, a few people have commented that below instructions don’t work, only to find that they did NOT follow ALL instructions. Please read and re-read the entire post before you begin. It WILL save you trouble!
1. Your website-storage, a.k.a. website-folders-location, or whatever you want to call it.
Your (development)websites will be stored on your hard drive. If you’re in a multi-user environment, and everyone should be able to use this setup; don’t put it in your home-directory as Alan suggests. Instead put it in the root; in Terminal, type
sudo mkdir -m 777 /DevelopmentThis folder will store your websites.
2. You will need to tell Apache to allow use of this folder. Type;
sudo sh -c "cat >> /etc/apache2/httpd.conf <<'EOF'
<Directory "/Development">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
EOF"3. Installing your database server. This is a 3-step installation
a) Install XCODE. It is available for Snow Leopard and later in the App Store application on your mac. For older versions of OSX you will need to download the installer from the Mac Developer site yourself. You probably need a development account for it.
After installing XCODE, start it up and finish the installation by installing the Commandline Tools from the Downloads panel in the Preferences. After that, you might need to execute the following command;
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developerb) Install HomeBrew. This is a simple Terminal command;
/usr/bin/ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"(See this page for more information)
c) Install MariaDB.
In Terminal, do:
brew install gnu-sed
brew install autoconf
brew install mariadb pidof --use-llvmDuring installation you will be notified of two Terminal command you will need to do a few steps after installation. This is a copy command to copy a file to the LaunchAgents folder and one to add the MySQL loader to the startup sequence. Look for it, but don’t worry; as long as you keep the Terminal window open, you can scroll back to copy it later.
These commands will configure your MariaDB server;
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mariadb)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/var/mysql/my.cnf
sed -i "" 's/max_allowed_packet = 1.*M/max_allowed_packet = 2G/g' /usr/local/var/mysql/my.cnf
[ ! -d /Library/LaunchAgents ] && sudo mkdir /Library/LaunchAgentsYou’ll notice a few differences in my post compared to Andy’s; First, I don’t use a $ prefix to every command to indicate it’s a command you type in the Terminal. I just tell you these are commands and allow you to copy/paste the entire block in one go instead of line by line.
Also, the last line is different. First of all, you’ll need to sudo it and therefore enter your password. This is because I want to start MariaDB on every user account and not just my own. The folder probably exists already.
Now, you’ll need to install the PLIST that will run MySQL (MariaDB) on boot. Check the install log on your screen and look for a copy command to copy com.mysql.mysqld.plist. You’ll need to change the command as well so here’s the deal; just use the version number from your log and use it instead of 5.3.5 in this command;
Please note: apparently the filename of this PLIST has changed as of version 5.2.10. It is now homebrew.mxcl.mariadb.plist. Please read the output and use the right filename. (Thank you, Mike, for bringing this up.)
sudo cp /usr/local/Cellar/mariadb/5.3.5/homebrew.mxcl.mariadb.plist /Library/LaunchAgents/launchctl load -w /Library/LaunchAgents/homebrew.mxcl.mariadb.plist4. Configure PHP.
Again, most tutorials just tell you to install a second copy of PHP. I say NO; just use the one that ships with OSX.
sudo sh -c "grep php /etc/apache2/httpd.conf|grep LoadModule|cut -d'#' -f2 > /etc/apache2/other/php5-loadmodule.conf"
sudo cp -a /etc/php.ini.default /etc/php.ini
sudo sh -c "cat >> /etc/php.ini <<'EOF'
;;
;; User customizations below
;;
; Original -- memory_limit = 128M
memory_limit = 196M
; Original -- post_max_size = 8M
post_max_size = 200M
; Original -- upload_max_filesize = 2M
upload_max_filesize = 100M
; Original -- default_socket_timeout = 60
default_socket_timeout = 600
; Original -- max_execution_time = 30
max_execution_time = 300
; Original -- max_input_time = 60
max_input_time = 600
; Original -- display_errors = Off
display_errors = on
; Original -- display_startup_errors = Off
display_startup_errors = on
; Original -- ;date.timezone =
date.timezone = 'Europe/Amsterdam'
EOF"
sudo /usr/bin/php /usr/lib/php/install-pear-nozlib.phar
cat >> ~/.bashrc <<'EOF'
alias pear="php /usr/lib/php/pear/pearcmd.php"
alias pecl="php /usr/lib/php/pear/peclcmd.php"
EOF
. ~/.bashrc
sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade --force pear
sudo pear upgrade
sudo pecl upgrade
sudo sh -c "cat >> /etc/php.ini <<'EOF'
; Original -- ;include_path = ".:/php/includes"
include_path = ".:/usr/lib/php/pear"
EOF"
sudo sed -i "" 's/\/var\/mysql\/mysql\.sock/\/tmp\/mysql\.sock/g' /etc/php.ini5. To install MCrypt, for example, to use RoundCube IMAP Client, see this post.
6. Activate your FTP server; if you’re planning to develop on WordPress this will come in handy. Check this post.
7. Install the PECL SVN plugin if you want to use SVN functions from PHP.
You’re on Mountain Lion; the development libraries are probably missing. A quick fix is to link to the 10.7 (Lion) version of the headers;sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/subversion-1 /usr/include/subversion-1sudo pecl install svn
sudo sh -c "cat >> /etc/php.ini <<'EOF'
extension=svn.so
EOF"8. Managing your virtual hosts
Option A) Use the script I have provided here to scan your development base-dir and write apache ghost file and hosts file according to that directory.
Option B) Use a DNS based setup required you to either use a virtual document root (see the post on this for more instructions)
Option C) Use VirtualHostX to manage your virtual hosts. VHX will write both Apache configuration and Hosts file changes for you.
Option D) you can always choose to maintain the VirtualHost configuration and hosts files yourself as Alan suggests in his post.
9. And now it is time to reload your web server.
sudo apachectl start
10. Manage your Databases with Sequel Pro.
Footnotes:
[April 2013] Rewritten this post to reflect all ongoing changes and afterthoughts.
[Around october 2012] This post is a re-write of my own post that was here about a year ago. I have rewritten some parts to reflect the changes I have made to my development environments.
[Sometime in 2011] This post is a re-write of this post, by Alan Ivey, for the sole purpose of saving this information for posterity. Also the original article has some excess weight, this is a slimmed down version to reflect my personal setup preference.