How to setup Mac OS X 10.6 Drupal environment

Wednesday, November 3, 2010 - 17:09

I've seen a lot of different local development setups on the computers of our own developers and students in our Drupal training. There are also plenty of blog posts, articles and HOWTOs on setting up PHP development environment on Mac. What I haven't yet found is a comprehensive guide on how to set up a clean and productive environment. So I decided to write one on my own. Unfortunately, setting up a clean environment that supports everything Drupal developers need, and does not get in the way of everything, is a bit hairy process. Many people prefer using MAMP, Macports or other methods, but OS X has almost everything you need already built in – and it's not THAT complicated to set the environment up. This post and some upcoming posts will describe what I consider to be an ideal development environment. Comments are definitely welcome.{C}

Prerequisites:

  • OS X 10.6 (will also work for other versions, but you might have to modify some parts)
  • Admin permissions on your Mac
  • Developing on PHP 5.3 & latest MySQL version

Installing MySQL

Your Mac comes with PHP and Apache. You only need to install MySQL & Drupal and do a bit of configuration. Go and get MySQL from their web site.

MySQL download

The community edition for x86, 64-bit as DMG archive is the version you will want to get. Exact MySQL version number is not that important, the most recent one is ok.

Install MySQL

Mount the DMG disk image by double-clicking it and follow the instructions to install MySQL. You will also want to install the prefPane in order to start and stop the database from OS X System Preferences panel and MySQLStartupitem in order to keep MySQL running after reboot. Just hit continue on all screens and type in your password when being asked.

Start MySQL

After the installation, go to OS X System Preferences pane, start MySQL server and check the checkbox to automatically start on startup.

System setup

In order to run Drupal you need to configure your Apache, PHP and a few small things in OS X. It's easiest to do this by starting terminal application from your Applications / Utilities. Let's start by settings some environment variables:

echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.profile

To get the new profile active close the terminal window and open a new one.

You need root permission in order to modify these files. If your Mac account is not an administrator account you can not do this. On the terminal prompt type:

sudo -s

If you're running sudo for the first time, you will get a warning message. Nevermind – you know what you're doing – right? Just type in your password when prompted. Keep this terminal window open for rest of the installation. Start by creating a short name for your local sites:

/Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts &

This enables you to edit your hosts file that has local aliases for IP addresses. Add the following lines to the end of the file:

127.0.0.1	d6
127.0.0.1	d7
127.0.0.1	customer-1
127.0.0.1	customer-2

Save and quit editor. When you want to add additional sites in the future you will need to add more aliases to this file.

You also need one small change in order to make MySQL compatible with OS X PHP settings. Go back into the terminal and run:

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Configuring Apache

Next, edit Apache settings:

/Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/apache2/httpd.conf &

Edit the following lines in the file by replacing the original with modified version.

Original:

#LoadModule php5_module        libexec/apache2/libphp5.so

Modified:

LoadModule php5_module        libexec/apache2/libphp5.so

Original:

<Directory />
	Options FollowSymLinks
	AllowOverride None
	Order deny,allow
	Deny from all
</Directory>

Modified:

<Directory />
	Options All
	AllowOverride All
	Order deny,allow
	Deny from All
	Allow from 127.0.0.1
</Directory>

Original:

# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf

Modified

# User home directories
#Include /private/etc/apache2/extra/httpd-userdir.conf

Original:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Modified

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

Original:

# Various default settings
#Include /private/etc/apache2/extra/httpd-default.conf

Modified:

# Various default settings
Include /private/etc/apache2/extra/httpd-default.conf

Save the file and close TextEdit. You also need to modify the virtual hosts, so it's back to the shell again:

/Applications/TextEdit.app/Contents/MacOS/TextEdit \
/etc/apache2/extra/httpd-vhosts.conf &

Original:

<VirtualHost *:80>
    ServerAdmin   

	DocumentRoot "/usr/docs/dummy-host.example.com"
	ServerName dummy-host.example.com
	ServerAlias www.dummy-host.example.com
	ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
	CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
	ServerAdmin   

	DocumentRoot "/usr/docs/dummy-host2.example.com"
	ServerName dummy-host2.example.com
	ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
	CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>

Modified:

<VirtualHost *:80>
	DocumentRoot "/Users/mearrafinland/Sites/drupal-6"
	ServerName d6
</VirtualHost>

<VirtualHost *:80>
	DocumentRoot "/Users/mearrafinland/Sites/drupal-7"
	ServerName d7
</VirtualHost>

<VirtualHost *:80>
	DocumentRoot "/Users/mearrafinland/Sites/customer"
	ServerName customer-1
	ServerAlias customer-2
</VirtualHost>

In this you need to replace "mearrafinland" with your own user account. Save the file and close TextEdit.

The last thing you need to modify in Apache is the number of simultaneous processes. Since this is a single user environment we don't have to serve many users at the same time. Back to the shell:

/Applications/TextEdit.app/Contents/MacOS/TextEdit \
/etc/apache2/extra/httpd-mpm.conf &

Again edit the file:

Original:

<IfModule mpm_prefork_module>
	StartServers          1
	MinSpareServers       1
	MaxSpareServers      10
	MaxClients          150
	MaxRequestsPerChild   0
</IfModule>

Modified:

<IfModule mpm_prefork_module>
	StartServers          1
	MinSpareServers       1
	MaxSpareServers       2
	MaxClients           10
	MaxRequestsPerChild 100
</IfModule>

Save the file and close. This will make sure Apache will not use too much resources and it can be left running on background on any modern Apple computer. Now we are ready to start Apache

Sharing preferences

Go to System Preferences / Sharing and enable web sharing.

Installing Drupal

You still need to install Drupal. To make life easier, let's start by installing Drush. Go to http://drupal.org/project/drush and download the latest recommended release. After download double click the drush package to extract it. Let's install it for system wide use, so it's back to the shell again:

mv ~/Downloads/drush /usr/local/
ln -s /usr/local/drush/drush /usr/bin/drush

After this you can continue by downloading Drupal 6 and 7:

cd ~/Sites/

drush dl drupal-7.x
mv drupal-7.x-dev drupal-7
mkdir drupal-7/sites/default/files
cp drupal-7/sites/default/default.settings.php \
drupal-7/sites/default/settings.php
chmod o+w drupal-7/sites/default/settings.php \
drupal-7/sites/default/files

drush dl
mv drupal-6.19 drupal-6
mkdir drupal-6/sites/default/files
cp drupal-6/sites/default/default.settings.php \
drupal-6/sites/default/settings.php
chmod o+w drupal-6/sites/default/settings.php \
drupal-6/sites/default/files

ln -s drupal-7 customer
chown -R mearrafinland:staff drupal*

Create databases to both sites:

mysql -uroot -e "create database drupal6;create database drupal7;"

Again remember to replace mearrafinland with your own user account. You need to chown the directories if you were running these instructions as root (which you were if you haven't closed your console).

And now we are finally ready to install Drupal. Point your browser first to http://d7/ and follow the normal Drupal installer. Database names are drupal6 and drupal7 and addresses simply d6 and d7. Database username for both sites is root and you may leave password blank. Please note that leaving password blank is NOT a good idea in any production environment, but since this is a local development environment it's safe and convenient to do so.

After you have installed both Drupal 6 and 7 it's time to make sure they don't complain about permissions of settings.php. One more trip to the shell:

chmod o-w ~/Sites/drupal-6/sites/default/settings.php \
~/Sites/drupal-7/sites/default/settings.php

You can now close the terminal.

That's it!

You've installed a clean and functional Drupal environment on your Mac with minimal software installations. Some modules on Drupal 6 will still give you warnings or even problems since you are running PHP 5.3, but for many developers this is not an issue. This is also not an issue with Drupal 7.

Please note that now you can also access your Drupal 7 with http://customer-1/ and http://customer-2/ urls. These can be used to set up Drupal multisite setup quickly. It's also easy to add additional local names for different projects either using multisite or installations to separate directories.

I will follow up on this blog post on how to set up PHP extensions (APC, uploadprogress & friends), debug environment, better notifications and other small tweaks that boost developer productivity. We have also set up Aegir on OS X and will blog about that in the future.

Comments

Just ran the procedure through and it took me 16 minutes. Anyone who says that it's hard to get a Drupal development environment running, is plain wrong. You just need to know which howtos to read. :)

Note: My downloads-folder was not the same as in the original scenario so the Drush-stuff didn't go as above. Here's what I did:

* Downloaded Drush on my Desktop
* Opened a new Finder window
* Opened the otherwise hidden /usr/local dir by typing it in the dialogue in Go --> Go to folder
* Drag'n'dropped Drush there (after the passwd confirmation)
* Continued with the instructions

Thanks for sharing. I'm working with MAMP to have PHP 5.2 and APC without too much hassle.
Reading this I'm considering to change my environment.

Could you explain how the result is different than using MAMP? Thanks.

There are a few differences. My primary annoyances with MAMP are that you have to start it manually, configuring it is very different from production environment (read: Linux), it is run as desktop application and running multiple sites at the same time is ugly or difficult. Having subdirectories for each site is just not practical since in production you are more likely not to have them. This causes all sorts of annoying issues that are somewhat easy to fix, but it's even easier to avoid them completely. Also integration with extra PHP/Apache modules is this way much easier and using command line tools like mysqldump or drush work out of the box.

Then again why should you run MAMP when your Mac already has everything but MySQL in it? Sure it's a bit more complex to set everything up my way, but just by following these instructions it will take 15 minutes. My setup will make more and more sense when I follow up on this with more advanced stuff.

>My primary annoyances with MAMP are that you have to start it manually,

See this on how to autostart mamp:

http://linsec.ca/blog/2006/11/22/mamp-and-php-development-on-the-mac/

>Having subdirectories for each site is just not practical since in production you are more likely not to have them

I use virtual hosts/drupal multisite setup on my development machine, exactly like my production enviroment, no difference.

Good stuff! A few things I like to do, as well:

Use TextMate (http://macromates.com/) and create a Project with all essential config files (i.e. hosts, httpd.conf, my.cnf, php.ini, etc.). That way, each file is close at hand to alter.
Add the following lines to my ~/.profile file:

alias m='mysql -uroot -pMYPASS'
alias madmin='mysqladmin -uroot -pMYPASS'
alias mdump='mysqldump -uroot -pMYPASS --compact --compress'

where 'MYPASS' is replaced with the root mysql password. That way, from the command line, I can easily execute commands, such as "madmin create my_database". Some of that, though, I guess you could do with drush.
Install phpmyadmin (http://www.phpmyadmin.net/) for good in-browser management of local databases.

In response to Steven_NC: MAMP is great, but I have run into trouble when trying to install PEAR or PECL extensions. Also, when you build the stack yourself, you can control the versions you run. Whereas with MAMP, you're constrained to whatever is in their latest release.

Again, great article!

This looks like a great setup. Coming from a Ubuntu machine, when I moved over to Mac, I really wanted a package manager like apt-get, so I a colleague introduced me to Macports. Macports work in a similar fashion to Ubuntu's apt-get package manager.

I've used Macports for a long time, but it's a lot more complicated solution. You will end up with many conflicting versions of commands (mysql5 & mysql etc) and you will have a LOT more manual housekeeping to do. I would recommend having macports anyway, but sticking with OS X default Apache and PHP in most cases. Stuff that doesn't come with OS X like Memcached and Varnish are much easier to install with Macports.

Great article!

One thing, the following:

127.0.0.1 customer1
127.0.0.1 customer2

should be:

127.0.0.1 customer-1
127.0.0.1 customer-2

Thanks Steve, I added dashes to those aliases.

Thanks for posting this. I just switched over from Macports, migrated all my existing db's and Apache virtual host settings.

I had .bash_profile in use, so setting up PATH variable in .profile didn't work for me.

I have my whole home directory crypted by FileVault so I had to change the user which Apache runs, by changing httpd.conf:

User: _www
Group: _www

to

User: your_username
Group: staff

Thank you for the detailed tutorial! I just got a new laptop yesterday and had no problem following your directions.

My question is how can I also develop non drupal sites on my laptop with this setup? I'm getting "access denied" or "permission denied" errors when I try and visit another non drupal folder in my sites directory. Thanks for any help anyone!

Try command: tail /var/log/apache2/error_log
right after getting such errors. This should give you an idea why these errors happen. It might be that your directory permissions are incorrect (they should be ok by default) or your site might use something else than index.php / index.html as it's starting point.

Thanks for the help! I feel a bit dumb, but the problem was I didn't turn off and restart Web Sharing (Apache) in system preferences. I look forward to reading your upcoming posts :)

There is a faster way to restart Apache so that you don't have to go to system preferences every time you want to restart Apache. Type 'sudo apachectl restart' in terminal and Apache will restart.

Another option is to install the acquia drupal stack installer, which does everything in this article (and then some further optimizations to configurations specifically for Drupal) in one simple and regular OS X application-installer wizard.

Isn't Acquia Drupal stack installer pretty much like Drupal optimized MAMP? My preference is to get a clean native environment that is lean enough to be always running on the background. Minimal software installations, no duplicate software and optimized for single user. This being said it's far from the simplest possible way of running Drupal on Mac. I'm sure MAMP or Acquia stack is better option for most average Drupal users, my way is targeted to developers as check list on what you should remember to do when setting up a new Mac.

MySQL.com is now recommending MySQL 5.5.x as the primary download version, which has several issues at least with OS X 10.6. It doesn't work currenly out of the box without hacking some things in the terminal. I'd suggest sticking with MySQL 5.1.

I'm getting a warning when using date/time functions:

warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.

To get rid of it copy /private/etc/php.ini.defaults to /private/etc/php.ini and configure date.timezone setting.

Thanks for share this complete walkthrough.
I was using mac port for running apache2 + php5 but can not found PDO_Mysql.
I don't meet exception anymore after using using this article. Great Share

I tried to follow your steps but got stock at running mysql and create the database for Drupal7, sorry forgot to mention that i didn't want to install drupal6 so ignore commands for it.

when i tried:

Create databases to both sites:

mysql -uroot -e "create database drupal6;create database drupal7;"

GOT THE FOLLOWING ERROR

mysql> mysql -uroot -e "create database drupal6;create database drupal7;"
-> help;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -uroot -e "create database drupal6;create database drupal7;"
help' at line 1
mysql>

Interesting enough when I tried to open "http://d7/" i got the following error:

Unable to connect.

Firefox can't establish a connection to the server at d7.

BUT WHEN I TRIED "http://customer-1/"

I got to the install and setup page of Drupal7 on my browser @ "http://customer-1/install.php"

THIS IS MY VHOST FILE "httpd-vhost.conf":

NameVirtualHost *:80

DocumentRoot "/U
sers/leonardojimenez/Sites/drupal-7.0"
ServerName d7

DocumentRoot "/Users/leonardojimenez/Sites/customer"
ServerName customer-1
ServerAlias customer-2

AND MY APPACHE "httpd.conf"

#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See for detailed information.
# In particular, see
#
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "/private/var/log/apache2/foo_log"
# with ServerRoot set to "/usr" will be interpreted by the
# server as "/usr//private/var/log/apache2/foo_log".

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk. If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule authn_file_module libexec/apache2/mod_authn_file.so
LoadModule authn_dbm_module libexec/apache2/mod_authn_dbm.so
LoadModule authn_anon_module libexec/apache2/mod_authn_anon.so
LoadModule authn_dbd_module libexec/apache2/mod_authn_dbd.so
LoadModule authn_default_module libexec/apache2/mod_authn_default.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule authz_groupfile_module libexec/apache2/mod_authz_groupfile.so
LoadModule authz_user_module libexec/apache2/mod_authz_user.so
LoadModule authz_dbm_module libexec/apache2/mod_authz_dbm.so
LoadModule authz_owner_module libexec/apache2/mod_authz_owner.so
LoadModule authz_default_module libexec/apache2/mod_authz_default.so
LoadModule auth_basic_module libexec/apache2/mod_auth_basic.so
LoadModule auth_digest_module libexec/apache2/mod_auth_digest.so
LoadModule cache_module libexec/apache2/mod_cache.so
LoadModule disk_cache_module libexec/apache2/mod_disk_cache.so
LoadModule mem_cache_module libexec/apache2/mod_mem_cache.so
LoadModule dbd_module libexec/apache2/mod_dbd.so
LoadModule dumpio_module libexec/apache2/mod_dumpio.so
LoadModule ext_filter_module libexec/apache2/mod_ext_filter.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule filter_module libexec/apache2/mod_filter.so
LoadModule substitute_module libexec/apache2/mod_substitute.so
LoadModule deflate_module libexec/apache2/mod_deflate.so
LoadModule log_config_module libexec/apache2/mod_log_config.so
LoadModule log_forensic_module libexec/apache2/mod_log_forensic.so
LoadModule logio_module libexec/apache2/mod_logio.so
LoadModule env_module libexec/apache2/mod_env.so
LoadModule mime_magic_module libexec/apache2/mod_mime_magic.so
LoadModule cern_meta_module libexec/apache2/mod_cern_meta.so
LoadModule expires_module libexec/apache2/mod_expires.so
LoadModule headers_module libexec/apache2/mod_headers.so
LoadModule ident_module libexec/apache2/mod_ident.so
LoadModule usertrack_module libexec/apache2/mod_usertrack.so
#LoadModule unique_id_module libexec/apache2/mod_unique_id.so
LoadModule setenvif_module libexec/apache2/mod_setenvif.so
LoadModule version_module libexec/apache2/mod_version.so
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_connect_module libexec/apache2/mod_proxy_connect.so
LoadModule proxy_ftp_module libexec/apache2/mod_proxy_ftp.so
LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
LoadModule proxy_scgi_module libexec/apache2/mod_proxy_scgi.so
LoadModule proxy_ajp_module libexec/apache2/mod_proxy_ajp.so
LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so
LoadModule ssl_module libexec/apache2/mod_ssl.so
LoadModule mime_module libexec/apache2/mod_mime.so
LoadModule dav_module libexec/apache2/mod_dav.so
LoadModule status_module libexec/apache2/mod_status.so
LoadModule autoindex_module libexec/apache2/mod_autoindex.so
LoadModule asis_module libexec/apache2/mod_asis.so
LoadModule info_module libexec/apache2/mod_info.so
LoadModule cgi_module libexec/apache2/mod_cgi.so
LoadModule dav_fs_module libexec/apache2/mod_dav_fs.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule negotiation_module libexec/apache2/mod_negotiation.so
LoadModule dir_module libexec/apache2/mod_dir.so
LoadModule imagemap_module libexec/apache2/mod_imagemap.so
LoadModule actions_module libexec/apache2/mod_actions.so
LoadModule speling_module libexec/apache2/mod_speling.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule bonjour_module libexec/apache2/mod_bonjour.so
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User: _www
Group: _www

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# definition. These values also provide defaults for
# any containers you may define later in the file.
#
# All of these directives may appear inside containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin you@example.com

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#

Options All
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.1

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks MultiViews

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#

DirectoryIndex index.html

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#

Order allow,deny
Deny from all
Satisfy All

#
# Apple specific filesystem protection.
#

Order allow,deny
Deny from all
Satisfy All

Order allow,deny
Deny from all
Satisfy All

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a
# container, that host's errors will be logged there and not here.
#
ErrorLog "/private/var/log/apache2/error_log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a
# container, they will be logged here. Contrariwise, if you *do*
# define per- access logfiles, transactions will be
# logged therein and *not* in this file.
#
CustomLog "/private/var/log/apache2/access_log" common

#
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog "/private/var/log/apache2/access_log" combined

#
# Redirect: Allows you to tell clients about documents that used to
# exist in your server's namespace, but do not anymore. The client
# will make a new request for the document at its new location.
# Example:
# Redirect permanent /foo http://www.example.com/bar

#
# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the server will
# require it to be present in the URL. You will also likely
# need to provide a section to allow access to
# the filesystem path.

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) "/Library/WebServer/CGI-Executables/$1"

#
# ScriptSock: On threaded servers, designate the path to the UNIX
# socket used to communicate with the CGI daemon of mod_cgid.
#
#Scriptsock /private/var/run/cgisock

#
# "/Library/WebServer/CGI-Executables" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#

AllowOverride None
Options None
Order allow,deny
Allow from all

#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /private/etc/apache2/mime.types

#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi

# For type maps (negotiated resources):
#AddHandler type-map var

#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type. The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile /private/etc/apache2/magic

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# 6894961
TraceEnable off

# Supplemental configuration
#
# The configuration files in the /private/etc/apache2/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.

# Server-pool management (MPM specific)
Include /private/etc/apache2/extra/httpd-mpm.conf

# Multi-language error messages
#Include /private/etc/apache2/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
Include /private/etc/apache2/extra/httpd-autoindex.conf

# Language settings
Include /private/etc/apache2/extra/httpd-languages.conf

# User home directories
#Include /private/etc/apache2/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include /private/etc/apache2/extra/httpd-userdir.conf

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
Include /private/etc/apache2/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include /private/etc/apache2/extra/httpd-dav.conf

# Various default settings
Include /private/etc/apache2/extra/httpd-default.conf

# Secure (SSL/TLS) connections
#Include /private/etc/apache2/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#

SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

Include /private/etc/apache2/other/*.conf

Not sure what I didn't wrong, could any one help me out pls??? I really would like to learn how to set up a clean dev environment on my Mac

I work on multiple drupal sites for work...but we use a shared server and it's just messy, so I wanted to setup a local dev env. I've used MAMP but wasn't all that impressed and deleted it.

I tried using macports last night and some today and kept running into problems. I always wondered why people seem to want us to replace the built in php and apache...Why is that?

Also, do you have your local env setup for rsyncing using drush to a live server? I need info about that if at all possible!

Thanks for the post! Most helpful I've found about this topic.

We don't use rsync for moving sites to production, we have all of them in a version control system. Most commonly we use Git for local development and for making deployments for production. This also protects you against your own stupid mistakes that are difficult to revert with rsync.

Hi,
I installed drupal with your settings and it works great ! But the reason I did that was to host an intranet survey. And I don't know why, I cannot access my webpage from other computers on the network using the url http://10.0.1.10/ that worked before !

Please help me

Thanks a lot

The likely reason for this is that your computer now has multiple virtual hosts. If you have a name server (DNS) for your internal network just set a name for your computer and add the name in /etc/apache2/extra/httpd-vhosts.conf. For example add ServerAlias intranet-survey after ServerName d7.

However if you don't have a DNS set up for your internal network (most small private networks don't) you can just add a IP based virtual host:

Add this to end of /etc/apache2/extra/httpd-vhosts.conf:

<VirtualHost 10.0.1.10>
DocumentRoot "/Users/mearrafinland/Sites/drupal-7"
</VirtualHost>

..be sure to replace mearrafinland with your username and drupal-7 with something else if required. That should fix the problem.

Thanks a lot for your great walk-through!

One more thing though: my machine is in a network and has a permanent IP and name. The Web Sharing was accessible before going through the Drupal installation but now it's not anymore. I would have liked other people (also from outside) to access the development server.

I tried adding ServerAlias mymachine after ServerName d7 and also the IP based virtual host, both without success. Any suggestion? Thanks!

I found the solution:

If, usually after installing/upgrading your mac, you can’t access your ~/Sites folder on your browser ( http://localhost/~username , where username is your mac username):

Open a Terminal and $ sudo nano /private/etc/apache2/httpd.conf ;
ctrl+w (where is) : “” ;
Alter the line below from “Deny from all” to “Allow from all“;
ctrl+x and y to save;
now $ sudo httpd -k restart to restart your Apache 2 server;

Now retry accessing http://localhost/~username on your browser – that should do it;

Thanks for the post. After upgrade to OS X 10.7 (Lion) I had to change
Allow from 127.0.0.1
to
Allow from ::1

Thanks for the articulate post! Just got a mac pro and this is my first time using mac so im very noobie. Went through this tutorial and everything worked great :)

Onto more Drupal web developing!

Excellent Article!!

I was using Acquia-drupal for about a year now and never really liked the way it worked for having to backup databases when installing updates. Or having to boot it up every time i wanted to work on something. But now, I have a much cleaner system that works like it should! Thanks a bunch! :O)

I did run into a couple of problems though....

When trying to execute a mysql command I got the error:

bash: mysql: command not found

This was fixed by adding the line:

/usr/local/mysql/bin
to the file:
/etc/paths

Also had to change permissions to ~/Sites/drupal-7/sites/default/settings.php to 777 (because I'm lazy) for the install to take place. I changed them back to 333 when install completed.

Love your blog, keep up the solid work!!