Drupal Development in Mac OSX
I have used MAMP for a while and it is a great tool. I do however, develop on Linux as well and prefer to run Drupal natively. Snow Leopard 10.6 comes with php 5.3 pre-installed and apache.
I thought I would take advantage of this and install mysql too and run my drupal sites natively. As installing php5.2 alongside is a bit of a pain at the moment, to be on the safe side I will use MAMP for the few sites that still run on php5.2. As the default setting of MAMP mean that it runs on ports 8888 and 8889, it shouldn't cause any conflict.
Apache
First off let's start Apache
sudo apachectl start
Check it's working: http://localhost/
You should get a simple web page saying "It Works"
PHP
Next step is to get the configuration of PHP.
In /etc/apache2/httpd.conf, uncomment this line:
LoadModule php5_module libexec/apache2/libphp5.so
Now restart Apache (don't worry about that error message you get, we will sort this in a minute)
sudo apachectl restart
Create a php.ini file from the default and make it writeable
cd /etc sudo cp php.ini.default php.ini sudo chmod 666 php.ini
In php.ini, find this line:
;date.timezone =
Uncomment it and insert your time zone PHP Timezones
In my case it was:
date.timezone =Europe/London
Restart Apache
sudo apachectl restart
Ok now we will deal with the error message you will get, you should have something like the following:
/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument
If not, just ignore this part. If you do, we need to edit:
sudo nano /usr/sbin/apachectl
and then find the following line:
ULIMIT_MAX_FILES="ulimit -S -n ulimit -H -n"
replace with
ULIMIT_MAX_FILES=""
This should fix the warning, try and restart apache to test it.
Next up MySQL
Download the MySQL package for Mac OS X (32 or 64 bits depending on your machine, if like me your using a macbook pro and a recent one then it will be the 64bit)
Important make sure you download the .dmg file, otherwise you will download an archive file which won't contain what you need and this guide will make no sense.
Install everything in the package in this order with the default options:
mysql-5.1.42-osx10.5-x86_64.pkg
MySQLStartupItem.pkg
MySQL.prefPanel
Start MySQL in the preference pane (this is on the settings page of your mac).
Test it's working, in terminal type:
/usr/local/mysql/bin/mysql
At this point I like to set an alias in my .bashrc for mysql so that it behaves like linux, in your .bashrc do the following:
alias mysql='/usr/local/mysql/bin/mysql'
To ensure that this is picked up in terminal, please check my other post on sourcing /.bashrc from /.bash_profile, here it is bashrc blog
Maintenance
Next we need to do a bit of maintenance, fix mysql.sock location in php.ini
In /etc/php.ini, replace the three occurences of /var/mysql/mysql.sock by /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
Restart Apache
sudo apachectl restart
Now we have the tools in place we need to do a bit of work on apache to get the virtual hosts correct.
edit /etc/apache2/httpd.conf and uncomment the following line:
# Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf
next we need to edit where localhost points to (http://localhost), currently as there are no vhosts set up it uses a default location of :
/Library/Webserver/Documents
so to edit where the server picks up the localhost files edit the following:
sudo nano /etc/apache2/extra/httpd-vhosts.conf
then inside there copy & paste the following, in snow leopard we conveniently have a Sites directory:
<VirtualHost *:80>
DocumentRoot /Users/username/Sites
</VirtualHost>Here is also obviously where we can add more specific vhosts if necessary.
We also need to ensure clean_urls is working, the mod_rewrite module should already be enabled in apache modules but we need to AllowOverrride All to let it work it's magic. So in the same file, somewhere add this:
<Directory /Users/username/Sites> AllowOverride all </Directory>
That's it, you may want to note that in Snow Leopard 10.6 there is a problem with phpmyadmin and the mycrypt extension, so perhaps use something like macports to install this.
I personally use sql buddy (doesn't like importing databases so I use terminal for this) or terminal, as it's easy when you know how.
You can now add your code to your Sites directory and import your database and you should be good to go.





Comments
cool
Thanks for the tutorial. I am using MAMP also and want to run everything natively. I will give this a try this week.