Download Required Software
- MAMP – http://download.living-e.com/MAMP/releases/1.7.2/MAMP_1.7.2.dmg
- cronolog – http://cronolog.org/download/cronolog-1.6.2.tar.gz
Base Setup
This article assumes you have a clean Mac OS X 10.5.x install on a mac and have installed the XCode Developer Tools.
Configure Mac OS X
There are a variety of things I do when I configure a new Mac. Most of it is personal preferences, some of it is for performance (like setting a solid color desktop background on a machine I know I will only see via Screen Sharing), other things for configuring a work environment. All of that is out of scope for what we are doing here, so just do the following as a the minimum. I will create a page for configuring a Mac dev box in the future that will go into all the details of how I configure my system, .profile, .vimrc, .screenrc, etc.
- Open Software Update and make sure that you are up to date on everything.
- Open System Preferences -> Sharing and make sure that the following are on and everything else is off
- Screen Sharing
- File Sharing – Click Options and make sure ‘Share files and folders using FTP’ is checked
- Remote Login
- Make sure the Computer Name is one word without spaces or apostrophes. Something like kimiko is good, something like Jamie’s MacBook Pro is bad
Install MAMP
MAMP is a .dmg so if you have direct control on the machine or remote access that is ideal. Download the .dmg, mount it, drag MAMP to the Applications folder and you are done with the install.
Configure MAMP and Apache
These steps are too interlaced to separate configuring MAMP and configuring Apache into separate sections.
The MAMP Application
- Launch up MAMP. The first time it launches it will start up your default web browser (probably Safari if you haven’t already installed Firefox) and turn everything on.
- Click the Stop Servers button to stop everything
- Click the Preferences and do the following:
- on Start/Stop, uncheck everything
- on Ports, Set to default Apache and MySQL ports
- on PHP, use PHP5, uncheck Zend Optimizer, and use APC for the Cache
- on Apache, set the document root to /Library/WebServer/Documents
- Quit the MAMP application
Mac OS X Settings
- In Finder, open
/Applications/MAMP/and delete all the readme files that are in a language that you can’t read and delete the htdocs folder
Symlinks and New Directories
In Terminal, go to your MAMP directory, create a symlink named htdocs to /Library/WebServer/Documents/, go to /etc and create a symlink for mamp to /Applications/MAMP/conf, move apache2 to apache2.d (I don’t like deleting things), create a symlink for apache2 to /Applications/MAMP/conf/apache, go to /etc/mamp/apache and create a vhosts folder, and go to /var/log and create a symlink for mamp to /Applications/MAMP/logs. If you aren’t positive how to do all that, here is a transcript:
$ cd /Applications/MAMP $ ln -s /Library/WebServer/Documents htdocs $ cd /etc $ sudo ln -s /Applications/MAMP/conf mamp $ sudo mv apache2 apache2.d $ sudo ln -s /Applications/MAMP/conf/apache apache2 $ cd /etc/mamp/apache $ mkdir vhosts $ cd /var/log $ sudo ln -s /Applications/MAMP/logs mamp
Apache httpd.conf
There are some changes you will want to make to the httpd.conf file. $ sudo vim /etc/mamp/apache/httpd.conf. All line numbers referenced below are from MAMP 1.7.2 and the higher the number gets, the more chance they are of being wrong cause I didn’t really pay attention to what all I edited that added lines as I went.
- Turn on ExtendedStatus (for non-production servers only). This is on line 295. Change
#ExtendedStatus OntoExtendedStatus On(remove the hash (#)) - Make sure User on line 326 has administrative privileges on the mac.
- ServerAdmin on line 336 should an email address that you can be contacted at (this is not all that important to change if you are going to setup vhosts)
- ServerName on line 351 should be the domain name you are using (this is also not all that important if you are going to setup vhosts)
- IMPORTANT, on line 639 you will notice that /Applications/MAMP/bin/SQLiteManger and /Applications/MAMP/bin/mamp are shared and publically available. While convenient for administrators, this is not good for the public to see, so you will want to set a password on these directories. We will insure that phpmyadmin asks for a password later as well. Change that section to look like this:
Alias /SQLiteManager "/Applications/MAMP/bin/SQLiteManager" <Directory "/Applications/MAMP/bin/SQLiteManager"> Options Indexes MultiViews AllowOverride None AuthType Basic AuthName "YOUR_SERVER_HOSTNAME" AuthUserFile /Library/WebServer/passwords/password Require valid-user </Directory> Alias /MAMP "/Applications/MAMP/bin/mamp" <Directory "/Applications/MAMP/bin/mamp"> Options Indexes MultiViews AllowOverride None AuthType Basic AuthName "YOUR_SERVER_HOSTNAME" AuthUserFile /Library/WebServer/passwords/password Require valid-user </Directory>
- Uncomment relevant lines 1087 – 1092, this will turn on server-status (only do this on non-production boxes). Either leave
Allow from .example.comcommented out and addAllow from allor put in a valid domain name in place of .example.com
<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from all </Location>
- Uncomment line 1133 for the
NameVirtualHostand add lines so it looks like this:
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /Library/WebServer/Documents/ </VirtualHost> Include /Applications/MAMP/conf/apache/vhosts/*.conf
Create htpasswd file for Authentication
$ mkdir /Library/WebServer/passwords $ cd /Library/WebServer/passwords $ htpasswd -cs password username
vhost .conf file
A typical vhost file should be in /etc/mamp/apache/vhosts and look something like the following. Don’t worry about the cronolog line yet, we will install that later down in this article.
<VirtualHost *:80> ServerName psyjinx.com ServerAdmin jyoung@psyjinx.com ServerAlias *.psyjinx.com DocumentRoot /Library/WebServer/Documents/psyjinx/ ErrorLog "|/usr/sbin/cronolog /var/log/mamp/psyjinx_error_log-%Y%m%d" CustomLog "|/usr/sbin/cronolog /var/log/mamp/psyjinx_access_log-%Y%m%d" combined </VirtualHost>
.profile or .bash_profile or .bashrc
You will need to make the following changes to your .bash_profile or .profile (or .bashrc). I recommend just using a .profile. Again, there will be a different article on all the changes I typically put in my .profile. At a minimum you should add the following:
export PATH=/Applications/MAMP/bin:/Applications/MAMP/Library/bin:$PATH
Configure MAMP to Start Silently on Boot
MAMP by default only starts the servers when you boot the computer, sign in as a user, and launch the application. This is not acceptable if your server is being used for anything other than personal use. Ideally you want MAMP to start on boot, so when the power goes out in the middle of the night and comes back on, the computer will boot up automatically and everything will just work without you needing to drive to the office, login in and launch an application.
This involves created 2 files and placing them in /Library/LaunchDaemons/. You need to have root privledges to do this, so you must use the terminal. I use vim.
$ sudo touch /Library/LaunchDaemons/info.mamp.start.apache.plist $ sudo touch /Library/LaunchDaemons/info.mamp.start.mysql.plist
UPDATE: At some point in the 10.5.x life this changed. I haven’t narrowed it down to what update breaks this, but something does. If you have the most current 10.5.x, you will want to put the apache startup file in LaunchDaemons and you will want to put the mysql startup file in LaunchAgents and chown it to admin and NOT chown the db and tmp directories.
The two files should look like this:
info.mamp.start.apache.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>info.mamp.start.apache</string> <key>ProgramArguments</key> <array> <string>/Applications/MAMP/Library/bin/apachectl</string> <string>start</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
info.mamp.start.mysql.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http:// www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>info.mamp.start.mysql</string> <key>ProgramArguments</key> <array> <string>/Applications/MAMP/Library/bin/mysqld_safe</string> <string>--port=3306</string> <string>--socket=/Applications/MAMP/tmp/mysql/mysql.sock</string> <string>--lower_case_table_names=0</string> <string>--pid-file=/Applications/MAMP/tmp/mysql/mysql.pid</string> <string>--log-error=/Applications/MAMP/logs/mysql_error_log</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Before this can do it’s magic you need to change some permissions for mysql.
NOTE: I have noticed some inconsistent results with this. Try everything without changing permissions first. If something doesn’t work, give the following a shot.
$ sudo chown -R mysql:admin /Applications/MAMP/db/mysql $ sudo chown -R mysql:admin /Applications/MAMP/tmp/mysql
Install Cronolog
Cronolog is what I last used to do log rotation. I can’t say it works exactly the way I want it to, or more likely I haven’t configured it correctly. Once you download it, un tar.gz it, compile it and move it to the proper place.
$ cd to/whereever/you/saved/cronolog-1.6.2.tar.gz $ tar -xvzf cronolog-1.6.2.tar.gz $ cd cronolog-1.6.2 $ ./configure $ make $ sudo cp src/cronolog /usr/sbin/
Confirming It Works
Ok, you should be done. Restart your computer and on boot Apache and MySQL should startup on boot. You can confirm this by trying to hit your machine from a different machine on your network with a web browser or log in and start up the MAMP application and make sure it shows Apache and MySQL as running.
Configure PHPMyAdmin
There isn’t much to do here, but you want to make sure it asks for a password, so you want to edit the config.inc.php file in /Applications/MAMP/bin/phpMyAdmin and make sure $cfg['Servers'][$i]['auth_type'] is set to http. It is on line 84 (or thereabouts) and should look like this when you are done:
$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?
Go to http://localhost/phpMyAdmin to make sure it is working. The default user/pass for MAMP is root / root. You will want to change this. In phpmyadmin, click on Privileges. You should see a page w/ 3 users listed. Only one of which will have Grant privilegs, the User should be root. In the last column on that row, click the edit icon, scroll down to the ‘Change Password’ section and change the password to something you will never forget.
Consequences of Changing the root Password (which you should do)
-
/Applications/MAMP/bin/stopMysql.shwill need to be updated. Just edit it with vim (or something), change -proot to -p[yournewpassword] /Applications/MAMP/bin/mamp/index.phpwill need to be updated. At a minimum you need to change the$link, otherwise this page will only show a mysql error when loaded. change the 2nd ‘root’ to be your new password.
Install DBI and DBD::MySQL
It is unfortunate that this does not work out of the box, cause it was a pain to figure out. The MAMP pre-compiled .dmg does not have the mysql include and lib folders with it. You need to get the MAMP source, configure and build mysql from there, then move the include and lib folders in place. Unfortunately the lib folder has synlinks pointing all over the place so I took the overkill approach and just put the entire mysql folder where the libs should be and modified the mysql_config file to point to the new place.
Good news is installing DBD is easy – If this is your first time installing anything from CPAN, you will go though a CPAN setup, just take all the defaults (there are a lot of questions) the ones that don’t have defaults, just take the obvious answers (like country to download files from)
$ sudo perl -MCPAN -e 'install DBI'
Installing DBD::mysql is the problem – go ahead and try to install it anyway
$ sudo perl -MCPAN -e 'install DBD::mysql'
Do the following to fix it.
- get the MAMP source – Source forge link is – http://sourceforge.net/project/showfiles.php?group_id=121134&package_id=132117
- For MAMP 1.7.2 you need MySQL 5.0.41
$ curl -O http://internap.dl.sourceforge.net/sourceforge/mamp/MAMP_1.7.2_src.zip
- Once you have it downloaded, unzip it, then find mysql and un-tar.gz it, go in it, get the include and lib files and copy them out
$ unzip MAMP_1.7.2_src.zip $ rm -rf __MACOSX $ cd MAMP_1.7.2_src $ tar -xvzf mysql-5.0.41.tar.gz $ cd mysql-5.0.41 $ mkdir -p /Applications/MAMP/Library/include/mysql $ ./configure $ make $ cp -r include/* /Applications/MAMP/Library/include/mysql/ $ cd .. $ mv /Applications/MAMP/Library/lib/mysql /Applications/MAMP/Library/lib/mysql.disabled $ cp -r mysql-5.0.41 /Applications/MAMP/Library/lib $ vim /Applications/MAMP/Library/bin/mysql_config ... set pkglibdir around line 86 to be /Applications/MAMP/Library/lib/mysql-5.0.41/libmysql ... $ cd ~/.cpan/build/DBD-mysql-4.010 $ sudo rm mysql.xsi $ sudo perl Makefile.PL --testuser=test --mysql_config=/Applications/MAMP/Library/bin/mysql_config $ sudo make $ sudo make install $ cd /tmp $ ln -s /Applications/MAMP/tmp/mysql/mysql.sock
I don’t think that symlink will survive a restart though since mysql.sock is destroyed UPDATE: it doesn’t…
Install PERL CGI
is easy
$ sudo perl -MCPAN -e 'install CGI'
Available Tools
MAMP comes with all sorts of goodies, just look in /Applications/MAMP/bin and /Applications/MAMP/Library/bin to see them all. Here are some of the ones I use most commonly:
- To start Apache:
$ sudo apachectl start - To stop Apache:
$ sudo apachectl stop - To restart Apache:
$ sudo apachectl restart - To view all Apache vhosts:
$ apachectl -t -D DUMP_VHOSTS - To start MySQL:
$ startMysql.sh & - To stop MySQL:
$ stopMysql.sh - To view domain names in a log file:
- There are two ways to do this, and it is a two step process both ways
- Method 1: This is the typical way to view one log file
$ logresolve -s ~/resolvedlog.txt < /var/log/mamp/log_filename $ cat ~/resolvedlog.txt
-
- Method 2: This is the only way to view multiple logs since using a wildcard in the above syntax will generate an error
$ cat /var/log/mamp/log_* | logresolve -s ~/resolvedlog.txt</code> $ cat ~/resolvedlog.txt
- MAMP Admin Page: http://localhost/MAMP/ (should work w/ any vhost you have configured)
- APC: http://localhost/MAMP/frame.php?src=apc.php
- PHPMyAdmin: http://localhost/PhpMyAdmin/ or http://localhost/MAMP/frame.php?src=%2FphpMyAdmin%2F%3Flang%3Den-iso-8859-1
- PHPInfo: http://localhost/MAMP/frame.php?src=info.php
- SQLiteManager: http://localhost/MAMP/frame.php?src=%2FSQLiteManager%2F
FAQ
Why do you do all these settings and not just use the defaults setup by MAMP
You could, well some of them. You don’t want to use the non-standard ports and you want everything to startup on boot, not on login of a user, and you want to have some command line access to control the servers. Much of the other settings, like all the symlinks, I mainly just do it be more ‘standard’ so that things are where I expect them to be in the unix filesytem, not all tucked away inside of /Applications/MAMP/
References
I wish I could say that I just knew all this but I didn’t.
I found two articles that combined together gave me the solution to get MAMP to start silently on boot.
- http://stringfoo.com/2008/08/25/tutorial-launching-mamp-silently-on-startup/
- http://linsec.ca/blog/2006/11/22/mamp-and-php-development-on-the-mac/
I found a couple of posts on getting DBD::MySQL working, these were the most helpful
- http://forum.webedition.de/phpBB/viewtopic.php?t=1204&highlight=dbd#p10223
- http://bugs.mysql.com/bug.php?id=30121
With thanks!!
VERY GOOD !!!
Thanks YVM !
But !….
What about mod_perl !?!?.. For OCS Inventory !…