Installing Aegir Hosting System on OSX 10.6 with MAMP

Cross posted at http://groups.drupal.org/node/30270.

Aegir install on OSX Snow Leopard

Aegir install instructions are fantastic if you run Debian/Ubuntu Linux. Some of the steps for OS X are a quite different

Setting up the Server components.

Your Mac will need to run Apache, Php, Mysql, and Bind (for DNS). Snow Leopard comes with Apache, Php and Bind installed, however it comes with version 5.3 of Php which is not compatible wit Aegir and other parts of Drupal (as far as I can tell).
The easy solution is to downnload and install MAMP 1.82 from Sourceforge. Here is the direct link: http://sourceforge.net/projects/mamp/files/mamp/1.8.2/MAMP_1.8.2.dmg.zip.... Note: this is not the latest version of MAMP. The latest version runs PHP 5.3 also. MAMP 1.82 runs PHP 5.2.10. This is what we need. This gives us Apache, Php and Mysql. However, OSX still has the original versions of Apache and PHP. So we can trick the system using the MAMP versions as follows:

First back up the original version of Php.

$ sudo mv /usr/bin/php /usr/bin/php-apple

Symlink the MAMP version to /usr/bin/php

$ sudo ln -s /Applications/MAMP/bin/php5/bin/php /usr/bin/php

Symlink mysql the same way if needed. (If you have never installed Mysql before than this will not be needed).

Back up the original version of apachectl.

$ sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-apple

Symlink the apachectl version to /usr/sbin/apachectl

$ sudo ln -s /Applications/MAMP/bin/apache2/bin/apachectl /usr/sbin/apachectl 

Next, set up DNS services. See http://geoffhankerson.com/node/108 for a complete guide

You should now have Apache, Php, Mysql, and Bind running.

1. Create the aegir user
$ sudo dscl . -create /Users/aegir NFSHomeDirectory /var/aegir 

2. Set password for Aegir user

$ sudo passwd aegir
New Password:
Retype Password:

3. Create aegir home directory
$sudo mkdir /var/aegir

4. Make aegir user the owner of his home directory
$sudo chown aegir /var/aegir/

5. Change group to _www
$sudo chgrp _www /var/aegir/

6. Become the aegir user

su - aegir
password:

###Preparations
Setup CVS repository...

export CVSROOT=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib 
cvs login 

###Download Drush and Provision

cvs -z6 co -d drush -r DRUPAL-6--2-0 contributions/modules/drush 
mkdir .drush 
cd .drush
/var/aegir/drush/drush.php dl provision
cd ..

At this point we need to gain superuser privileges to execute the next few commands, so we logout of the aegir session...

exit 

sudo -s

chmod u+x /var/aegir/drush/drush  

ln -s /var/aegir/drush/drush /usr/bin/drush 

su - aegir

We're now back as the aegir user.

Test that the drush setup is working:

drush

This should list all available drush commands. Check that it includes the 'provision' commands. If this doesn't work as expected troubleshooting is needed... check the permissions of the directories and drush file. Try /var/aegir/drush/drush.php. If that works, then there's a problem with the symlink.

If all is working with drush, let's move on to the next step.

###Setup Drupal codebase
We start by checking out the latest drupal 6 release...

drush dl drupal

See how easy drush makes things?!

###Get Hostmaster install profile

cd aegir/drupal-6.*/profiles 
export CVSROOT=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib  
cvs login 
cvs -z6 co -d hostmaster -r DRUPAL-6--0-3 contributions/profiles/hostmaster 
mkdir hostmaster/modules
mkdir hostmaster/themes 
/var/aegir/drush/drush.php dl --destination=/var/aegir/drupal-6.*/profiles/hostmaster/modules hosting install_profile_api admin_menu
/var/aegir/drush/drush.php dl --destination=/var/aegir/drupal-6.*/profiles/hostmaster/themes eldir

Note that the hostmaster profile still needs to be checked out via CVS, as drush has problems downloading profiles (see http://drupal.org/node/500324).

###Configure Apache
Now we'll copy across a file template (with the filename changed from aegir.example.com to the domain name of our aegir install)...

mkdir -p /var/aegir/config/vhost.d 
chmod 0711 /var/aegir/config
cp hostmaster/apache2.conf.txt ~/config/vhost.d/aegir.example.com 

Edit this file as you wish, but you must ensure the servername, documentroot and directory are all correct for the codebase. So:
vim ~config/vhost.d/aegir.example.com

Next, we'll create some other useful directories...

mkdir /var/aegir/backups 
chmod 0700 /var/aegir/backups

mkdir /var/aegir/platforms 

mkdir  /var/aegir/drupal-6.*/sites/all/modules 
chmod 0777 /var/aegir/drupal-6.*/sites/all/modules 

mkdir  /var/aegir/drupal-6.*/sites/all/themes 
chmod 0777 /var/aegir/drupal-6.*/sites/all/themes 

mkdir /var/aegir/drupal-6.*/sites/aegir.example.com
cp /var/aegir/drupal-6.*/sites/default/default.settings.php /var/aegir/drupal-6.*/sites/aegir.example.com/settings.php
chmod a+w /var/aegir/drupal-6.*/sites/aegir.example.com/settings.php
mkdir /var/aegir/drupal-6.*/sites/aegir.example.com/files
chmod 2770 /var/aegir/drupal-6.*/sites/aegir.example.com/files

And then...
logout 
sudo -s

So we're now back as root. Next we add the aegir user to the _www group.

$ dscl . -append /Groups/_www GroupMembership aegir

Now we want to tell apache to include aegir's vhost files. Apache will automatically run files in /etc/apache2/conf.d, so add/edit the new file with:
sudo vim /etc/apache2/conf.d/aegir 
putting the following inside it:
Include /var/aegir/config/vhost.d/* 

Next we configure sudo to allow aegir user permission to restart apache:
sudo visudo 
Use the arrow keys to go to the last line. Press 'a' to add a line. Type:
aegir ALL=NOPASSWD: /usr/sbin/apache2ctl 
Hit Esc. Type ':'. type 'wq' and hit ENTER.

###Configure MySQL
We'll now setup the necessary users and database in MySQL.

The main aegir site uses database 'aegir' and a database user 'aegir'.

mysql -uonlyme -p 

mysql> CREATE DATABASE aegir
mysql> GRANT ALL ON aegir.\* TO 'aegir'@'localhost' IDENTIFIED BY 'password'; 

We also configure a MySQL 'superuser' who is capable of creating more databases. It is advised to not use the same user as the previous db user, but instead a separate superuser for security. As a naming standard, we recommend calling this superuser 'aegir_root'

mysql> GRANT ALL PRIVILEGES ON \*.\* TO 'aegir_root'@'localhost' IDENTIFIED BY 'password'  WITH GRANT OPTION; 
mysql> exit 

If your database server is running not on the local server but as a remote database server, substitute the 'localhost' commands for the wildcard '%'.

###Run the installer
First, restart apache:
sudo /etc/init.d/apache2 restart 

Then in a browser, go to http://aegir.example.com (you will need to have setup the DNS entries for your domain to point at the IP of your server).

###Hosting setup
Setup the database with the 'hostmaster' details we created earlier.

The setup will ask you to enter the path to drush.php. This is:
/var/aegir/drush/drush.php 

The configuration path is:
/var/aegir/config 

And the backup path is:
/var/aegir/backups 

We've already done the step of adding the line to httpd.conf.

On the Database page, enter the details for the 'aegir' database user.

At some point during the install you'll be prompted to enter a drush command to run the hosting setup...

su - aegir 
cd /var/aegir/drupal-6.*
/var/aegir/drush/drush.php --uri=http://yoursite.com hosting setup 

###Configure Aegir
Aegir is now installed, and you can configure it with your preferred settings. Have a browse around. Read the wiki and other posts on here: http://groups.drupal.org/aegir-hosting-system to find out what you can do with it. Prepare to be excited (if you're a geek)!

For next steps see: Aegir Is Installed - What Next?

###Preparations
Setup CVS repository...

export CVSROOT=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib 
cvs login 

###Download Drush and Provision

cvs -z6 co -d drush -r DRUPAL-6--2-0 contributions/modules/drush 
mkdir .drush 
cd .drush
/var/aegir/drush/drush.php dl provision
cd ..

At this point we need to gain superuser privileges to execute the next few commands, so we logout of the aegir session...

logout 

chmod u+x /var/aegir/drush/drush  

ln -s /var/aegir/drush/drush /usr/bin/drush 

su - aegir

We're now back as the aegir user.

Test that the drush setup is working:

drush

This should list all available drush commands. Check that it includes the 'provision' commands. If this doesn't work as expected troubleshooting is needed... check the permissions of the directories and drush file. Try /var/aegir/drush/drush.php. If that works, then there's a problem with the symlink.

If all is working with drush, let's move on to the next step.

###Setup Drupal codebase
We start by checking out the latest drupal 6 release...

drush dl drupal

See how easy drush makes things?!

###Get Hostmaster install profile

cd aegir/drupal-6.*/profiles 
export CVSROOT=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib  
cvs login 
cvs -z6 co -d hostmaster -r DRUPAL-6--0-3 contributions/profiles/hostmaster 
mkdir hostmaster/modules
mkdir hostmaster/themes 
/var/aegir/drush/drush.php dl --destination=/var/aegir/drupal-6.*/profiles/hostmaster/modules hosting install_profile_api admin_menu
/var/aegir/drush/drush.php dl --destination=/var/aegir/drupal-6.*/profiles/hostmaster/themes eldir

Note that the hostmaster profile still needs to be checked out via CVS, as drush has problems downloading profiles (see http://drupal.org/node/500324).

###Configure Apache
Now we'll copy across a file template (with the filename changed from aegir.example.com to the domain name of our aegir install)...

mkdir -p /var/aegir/config/vhost.d 
chmod 0711 /var/aegir/config
cp hostmaster/apache2.conf.txt ~/config/vhost.d/aegir.example.com 

Edit this file as you wish, but you must ensure the servername, documentroot and directory are all correct for the codebase. So:
vim ~config/vhost.d/aegir.example.com

Next, we'll create some other useful directories...

mkdir /var/aegir/backups 
chmod 0700 /var/aegir/backups

mkdir /var/aegir/platforms 

mkdir  /var/aegir/drupal-6.*/sites/all/modules 
chmod 0777 /var/aegir/drupal-6.*/sites/all/modules 

mkdir  /var/aegir/drupal-6.*/sites/all/themes 
chmod 0777 /var/aegir/drupal-6.*/sites/all/themes 

mkdir /var/aegir/drupal-6.*/sites/aegir.example.com
cp /var/aegir/drupal-6.*/sites/default/default.settings.php /var/aegir/drupal-6.*/sites/aegir.example.com/settings.php
chmod a+w /var/aegir/drupal-6.*/sites/aegir.example.com/settings.php
mkdir /var/aegir/drupal-6.*/sites/aegir.example.com/files
chmod 2770 /var/aegir/drupal-6.*/sites/aegir.example.com/files

And then...
logout 

So we're now back as root. Next we add the aegir user and yourself to the _www group.

dscl / -append /Groups/_www GroupMembership aegir
dscl / -append /Groups/_www GroupMembership yourusername

Now we want to tell apache to include aegir's vhost files. Apache will automatically run files in /etc/apache2/conf.d, so add/edit the new file with:
sudo nano /Applications/MAMP/conf/apache/httpd.conf 
putting the following inside it:
Include /var/aegir/config/vhost.d/* 

Next we configure sudo to allow aegir user permission to restart apache:
sudo visudo 
Use the arrow keys to go to the last line. Press 'a' to add a line. Type:
aegir ALL=NOPASSWD: /usr/sbin/apache2ctl 
Hit Esc. Type ':'. type 'wq' and hit ENTER.

###Configure MySQL
We'll now setup the necessary users and database in MySQL.

The main aegir site uses database 'aegir' and a database user 'aegir'.

mysql -uonlyme -p 

mysql> CREATE DATABASE aegir
mysql> GRANT ALL ON aegir.\* TO 'aegir'@'localhost' IDENTIFIED BY 'password'; 

We also configure a MySQL 'superuser' who is capable of creating more databases. It is advised to not use the same user as the previous db user, but instead a separate superuser for security. As a naming standard, we recommend calling this superuser 'aegir_root'

mysql> GRANT ALL PRIVILEGES ON \*.\* TO 'aegir_root'@'localhost' IDENTIFIED BY 'password'  WITH GRANT OPTION; 
mysql> exit 

If your database server is running not on the local server but as a remote database server, substitute the 'localhost' commands for the wildcard '%'.

###Run the installer
First, restart apache:
sudo /etc/init.d/apache2 restart 

Then in a browser, go to http://aegir.example.com (you will need to have setup the DNS entries for your domain to point at the IP of your server).

###Hosting setup
Setup the database with the 'hostmaster' details we created earlier.

The setup will ask you to enter the path to drush.php. This is:
/var/aegir/drush/drush.php 

The configuration path is:
/var/aegir/config 

And the backup path is:
/var/aegir/backups 

We've already done the step of adding the line to httpd.conf.

On the Database page, enter the details for the 'aegir' database user.

At some point during the install you'll be prompted to enter a drush command to run the hosting setup...

su - aegir 
cd /var/aegir/drupal-6.*
/var/aegir/drush/drush.php --uri=http://yoursite.com hosting setup 

###Configure Aegir
Aegir is now installed, and you can configure it with your preferred settings. Have a browse around. Read the wiki and other posts on here: http://groups.drupal.org/aegir-hosting-system to find out what you can do with it. Prepare to be excited (if you're a geek)!

For next steps see: Aegir Is Installed - What Next?

Thank you for us Mac OS X users

This is exactly the information I was looking for. We are a Mac shop.

Although I was exploring using Debian to have Ægir installed. But know I will do this on an Intel Mac.

Thank you.

My Pleasure

It took a fair amount of persistence to get this working. I hope this helps you get Aegir working. Let me know how it goes!

MacPorts

May I know how can I set it up using macports?

Thanks.

Macports

Well Mac ports will be almost the same except for the paths to Apachectl, Mysql, and Php. To install Php 5.2 with mac ports use: sudo port install php52 The your path to Php will be at /opt .... something, but I had trouble getting PHP an Apache to compile with macports.

MySQL reports the following message: No such file or directory

If you are getting the error "MySQL reports the following message: No such file or directory" during the aegir installation process, you can do

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

as described in http://www.fischerlaender.net/web-20/mac-os-x-trouble-with-mamp-mysql
Thanks for the post,
Albert.

One small detail...

I followed this tutorial to the letter and kept getting a message when verifying my sites about /default/settings not being present as well as seeing "nobody" as the user when I logged in as aegir.

If you scroll down to "note: on snow leopard I had to assign a uid to the user in order to be able to chown, etc..." on the crosspost http://groups.drupal.org/node/30270 these instructions of getting a UUID fixes those issues. Here's what I had to do after assigning UUID...

1. change visudo from nobody back to aegir
2. chown -R /var/aegir to aegir
3. go into mysql and change user from nobody to aegir
(UPDATE 'aegir'.'hosting_web_server' SET 'script_user' = 'aegir' WHERE `hosting_web_server`.'script_user' ='nobody';)
4. su as aegir and rerun drush hosting setup to setup cron again