"Done! Now it works AND looks good" - Mads
"Just like the EchoDitto Dev team." - Dan
OS X 10.7 Lion Development: Native MAMP with MySQL installer
With the release of Lion, there are some subtle differences to setting up a local MAMP (Mac OS X, Apache, MySQL, PHP) environment compared to Snow Leopard. In an effort to keep this from being overly wordy and just get to the good stuff, we'll dive right in, so read on to get started.
Note that for all commands before that are starting with a $, the dollar sign is showing a command-line prompt in Terminal, and you should not actually type it as part of the commands.
Apache
We'll set things up so we won't need sudo often in the future, and so we can manage multiple VirtualHosts. We'll keep the Apache information and our website roots in ~/Sites, and Apache logs in ~/Sites/logs
$ [ ! -d ~/Sites ] && mkdir ~/Sites
$ touch ~/Sites/httpd-vhosts.conf
$ sudo ln -s ~/Sites/httpd-vhosts.conf /etc/apache2/other
$ mkdir ~/Sites/logs
$ chmod 0777 ~/Sites/logs
Edit the new ~/Sites/httpd-vhosts.conf file and add the following. Note that you'll need to change all instances of "/Users/name" to your actual home folder path.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# Set up permissions for VirtualHosts in ~/Sites
#
<Directory "/Users/name/Sites">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# For http://localhost in the OS X default location
<VirtualHost _default_:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
#
# VirtualHosts below
#
## Template
#<VirtualHost *:80>
# ServerName domain.local
# CustomLog "/Users/name/Sites/logs/domain.local-access_log" combined
# ErrorLog "/Users/name/Sites/logs/domain.local-error_log"
# DocumentRoot "/Users/name/Sites/domain.local"
#</VirtualHost>
Launch System Preferences and go to Sharing and toggle Web Sharing off and on so it's started and reloaded with the new settings. Then click on the blue underlined link under "Your computer's website is available at this address:" to ensure Apache is working correctly, and you should see text saying "It works!"
To add a site, duplicate the <VirtualHost> section under the Template, remove the comments, and edit appropriately. Edit /etc/hosts (or use Gas Mask) and add an entry for 127.0.0.1 for your project.local, and make the appropriate change in the conf file, along with the correct DocumentRoot and Log file locations. See Apache's documentation for more information.
PHP
OS X has shipped with PHP for quite some time, but not had it enabled by default. We'll enable mod_php for Apache, and also set up an /etc/php.ini file based on the default one shipped with Lion with some development-friendly changes. Change your timezone as needed.
$ 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 = 'America/New_York'
EOF"
Optional: Lion ships with PEAR but not installed, whereas Snow Leopard it was installed. This will install PEAR from the phar archive, upgrade it, and add 'pear' and 'pecl' aliases to your shell.
$ 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"
Note that installing most pecl modules will require having a compiler installed via Xcode. I'll be addressing installing uploadprogress and APC in a later post, since this walkthrough requires no compiling.
Toggle Web Sharing in System Preferences > Sharing for the new PHP options to take effect.
MySQL
MySQL is the only thing not shipped with OS X that we need for our development environment. Go to the download site for OS X pre-built binaries at http://dev.mysql.com/downloads/mysql/index.html#macosx-dmg and choose the DMG Archive most appropriate for your system. As of this writing, the most recent version says OS X 10.6, but it will work on 10.7 as well.
Open the downloaded disk image and begin by installing the mysql-5.x.x-osx10.6-x86_64.pkg file. Once the Installer script is completed, install the Preference Pane by double-clicking on MySQL.prefPane. If you are not sure where to install the preference pane, choose "Install for this user only."
Optional: If you wish to have MySQL start on boot, you do need to additionally install the MySQLStartupItem.pkg file. The preference pane has a toggle for starting on boot, but it will not work until you install the pkg and you run the following in Terminal:
$ sudo chown -R root:wheel /Library/StartupItems/MySQLCOM
Open System Preferences and MySQL and start the database by clicking the Start MySQL Server button.
Optional: The MySQL installer installed its files to /usr/local/mysql, and the binaries are in /usr/local/mysql/bin which is not in the $PATH of any user by default. Rather than edit the $PATH shell variable, we add symbolic links in /usr/local/bin (a location already in $PATH) to a few MySQL binaries. Add more or omit more binaries as desired:
$ [ ! -d /usr/local/bin ] && sudo mkdir -p /usr/local && sudo chmod 0777 /usr/local && mkdir /usr/local/bin && sudo chmod 0755 /usr/local
$ cd /usr/local/bin
$ ln -s /usr/local/mysql/bin/mysql
$ ln -s /usr/local/mysql/bin/mysqladmin
$ ln -s /usr/local/mysql/bin/mysqldump
$ ln -s /usr/local/mysql/support-files/mysql.server
This script ships with MySQL and only needs to be run once, and it should be run with sudo. As you run it, you can accept all other defaults after you set the root user's password:
$ sudo /usr/local/mysql/bin/mysql_secure_installation
After installing MySQL, several sample my.cnf files are created but none is placed where MySQL can find it. Start with a "small" configuration file and make a few changes to increase the max_allowed_packet variable:
$ sudo cp /usr/local/mysql/support-files/my-small.cnf /usr/local/mysql/data/my.cnf
$ sudo sed -i "" 's/max_allowed_packet = 1.*M/max_allowed_packet = 2G/g' /usr/local/mysql/data/my.cnf
To load in these changes, go back to the MySQL System Preferences pane, and restart the server by pressing "Stop MySQL Server" followed by "Start MySQL Server."
Make PHP and MySQL Play Nice
If you were to run php -i|egrep 'mysql.*default_socket' you would see that PHP was compiled to expect the MySQL socket file in /var/mysql, but MySQL will place it in /tmp. This easiest fix is to tell PHP to look in /tmp:
$ sudo sed -i "" 's/\/var\/mysql\/mysql\.sock/\/tmp\/mysql\.sock/g' /etc/php.ini
Toggle Web Sharing in System Preferences > Sharing for the new PHP options to take effect.
Hooray!
You should now be all set to keep adding more VirtualHosts in httpd-vhosts.conf and begin development on your local machine. Stay tuned for instructions on how to use MariaDB or MySQL with Homebrew instead of the Oracle MySQL installer, and MacPorts!







Comments
Hi,
Thanks for the tutorial. I've followed the content exactly but I am getting stuck after installing the Pear components. The tutorial says to toggle the Web Sharing but it refuses to start up now. It was working after the first step for Apache. Every time I try to toggle it on now it just goes back to Off.
Looking at the terminal output the only thing that might be needed is that after installing pear it says:
You may want to add: /usr/lib/php/pear to your php.ini include_path
I've linked my terminal output for the pear installation. Your help would be really appreciated.
Thanks,
Rory
19 May 2008
1 hour 35 min
Your output from the pastebin looks good, there are some warnings and notices but no errors. I made some changes to my instructions and I think I'll address your other problems to your other comments.
Actually the issue I'm facing has to do with the php5-loadmodule.conf file. The console error is:
25/08/11 2:36:07.452 PM org.apache.httpd: httpd: Syntax error on line 665 of /private/etc/apache2/httpd.conf: Syntax error on line 1 of /etc/apache2/other/php5-loadmodule.conf: LoadModule takes two arguments, a module name and the name of a shared object file to load it from
I've checked the file and it looks fine. Could the issue be caused by the large gap between the arguments?
19 May 2008
1 hour 35 min
I had shortened what I had in my notes for this blog post and I guess the php5-loadmodule.conf file wasn't being created successfully. I updated this post to actually grab the commented-out line in httpd.conf and put it into php5-loadmodule.conf, so it's the equivalent of removing the comment on Apple's file. Delete php5-loadmodule.conf, and try the new command:
sudo sh -c "grep php /etc/apache2/httpd.conf|grep LoadModule|cut -d'#' -f2 > /etc/apache2/other/php5-loadmodule.conf"
Though, it does sound like the problem may have been related to copy+paste from the formatting of this site, sorry about that. If you're still getting errors, run: $ sudo apachectl -t and send me the output
Sorry for all the spam but I got Web Sharing to work again by changing:
libexec/apache2/libphp5.so
to
/usr/libexec/apache2/libphp5.so
Is this the correct approach? My console still gives me the error:
25/08/11 4:07:04.415 PM org.apache.httpd: httpd: Could not reliably determine the server's fully qualified domain name, using Rorys-MacBook-Air.local for ServerName
Thanks,
Rory
19 May 2008
1 hour 35 min
If you grep for php in /etc/apache2/httpd.conf, you'll see the commented line that will work uncommented does not have the full path, but relative to the apache root. That being said, it will work as you have it, but the console message you're seeing is a warning, not an error. It's telling you that since you did not explicitly define a ServerName in httpd.conf, it'll use your system's hostname. Looks good to me, but if you encounter more errors, let me know.
THere were some more issues I encountered during the MySQL installation which may help other users:
1. /usr/local/bin/ does not exist. Need to create that first. (sudo mkdir /usr/local/bin/)
2. Get access denied when trying to create links in bin. Need to put sudo in front of the link commands (Maybe the permissions for bin should be changed?)
3. Need to rename the my-small.cnf file to my.cnf after it has been copied.
Everything seems to be working now except that it doesn't appear as though my httpd-vhosts.conf file is being picked up. None of the aliases that I have entered are working and the settings are not being picked up. I am accessing my files through localhost/~username/. Do you know what could be going wrong?
Sorry for all the questions / comments. I have really found this post useful.
Thanks,
Rory
19 May 2008
1 hour 35 min
1. You're right, my apologies. I added a command to make /usr/local/bin user-writable. I loaded up a fresh Lion install and /usr/local doesn't even exist until the MySQL installer is run. I likely had /usr/local/bin created by my Homebrew installer and assumed it was there by default. I ran through my new commands on the fresh Lion install and it worked better this time.
2. Right, same thing. I had /usr/local/bin owned by me in my system, but with my new addition to the steps it can make the symlinks without sudo
3. Ouch, my apologies, I forgot to add /my.cnf to the end of the cp command. That's been fixed.
As for the problem with httpd-vhosts.conf, I noticed on a fresh Lion install that ~/Sites doesn't exist. This is a big change from the last several versions of OS X where it was always there by default. I added a check for this directory and then to create it if it doesn't exist. You may need to create ~/Sites, recreate the ~/Sites/httpd-vhosts.conf, and then create the symlink again with the ln -s command.
Let me know if you need anything else!
Thanks for the gasmask tip! Also looking forward to the instruction for homebrew :)
However, an obvious question is: why not use Acquia Dev Desktop? (I'm asking this purely out of interest, I'm not affiliated with Acquia.) Purely because you want to stay in control? I'm looking for the most easily manageable installation, and this is not it. (MAMP Pro isn't either, I have been using that for years now.)
19 May 2008
1 hour 35 min
You're welcome!
Acquia Dev Desktop seems really geared for Drupal development and that's it. It also duplicates packages that we already have on our systems, like Apache and PHP. We often do some WordPress development and other random non-Drupal projects and this approach is more flexible.
This method is likely going to be a little more of a headache than MAMP Pro, because this requires you to make additions in /etc/hosts (or Gas Mask) and a plain text file for your VirtualHosts, but it's also free :)
Thank you for your excellent tutorial :) I'm referring to it in my Running WordPress locally on Mac OS X Lion tutorial
19 May 2008
1 hour 35 min
Great tutorial, thanks for the nod!
I definitely prefer to use the default PHP & Apache; I'm on an air so every byte of HDD space saved counts... but without mcrypt and pear, it seems like it might be somewhat limited. I guess I can compile them specifically but that starts adding up to a substantial admin overhead. How do you get around that?
19 May 2008
1 hour 35 min
You can get Pear installed with this walkthrough, but not Pecl packages. It's easy to bolt on mcrypt; I'll actually cover it in my next blog where I include Homebrew. It does unfortunately require compiling, and keeping up to date would be tedious. Short of using MacPorts, there isn't really a good way to keep up-to-date with non-OS X UNIX components.
Hey.
Thanks a lot for this tutorial, I really needed this today.
Cheers!
great work here.
just to note my new MBP httpd.host file references httpd-vhosts.conf file in /etc/apache2/extra and not /etc/apache2/other, i did the symlink like this
$ sudo ln -s ~/Sites/httpd-vhosts.conf /etc/apache2/otherafter that, apache seems happy although my logs are not showing up in ~/Sites and this is the only warning in apache at this point:
mod_bonjour: Cannot stat template index file '/System/Library/User Template/English.lproj/Sites/index.html'.not sure how to solve it if you have any pointers
thanks again!
just to follow up on the error log part,
httpd.conf is where I was able to set the apache error log path
ErrorLog "/private/var/log/apache2/error_log"19 May 2008
1 hour 35 min
/etc/apache2/httpd.conf does reference httpd-vhosts.conf, but it is commented out:
#Include /private/etc/apache2/extra/httpd-vhosts.conf
The same file includes all files in /etc/apache2/other:
Include /etc/apache2/other/*.conf
So in my guide, I put my symlink in /etc/apache2/other so it's picked up by Apache without needing to edit httpd.conf. Reason being, I can't count on Apple to not make modifications to httpd.conf and overwrite changes, like the comment coming back in the first Include line above referencing the extra folder. Since OS X 10.5, /etc/apache2/other*.conf has been there and I image it shall continue to be.
As for the warning about bonjour, does that file exist?
Hey ya Alan,
Thank u kindly! All clear now. As of Lion, there ain't no Sites folder. I created one meself. As a result this file does not in fact exist. Is there any harm in making one? /System/Library/User Template is owned by root. Just wanna make everyone happy.
cheers matey
Update
I chowned away and created the dastardly file bonjour was complaining about and low and behold, the error mysteriously disappeared. lucky for me. Thanks again for the excellent post.
I found that the Sites folder doesn't exist under this User Template folder, so bonjour complaints. Any ideas how to fix this?
Hey Alan!
What an awesome tutorial. It's great! Thank you so very much for all the time you spent on this.
Being somewhat of a newbie at the terminal, I could follow along till I got to the part of installing Pear. I had some difficulty here Alan.. hopefully you can help me out?
Your instructions say...
$ 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"
Ok Alan... so I typed into terminal this:
sudo /usr/bin/php /usr/lib/php/install-pear-nozlib.phar
I got this:
[PEAR] Archive_Tar - already installed: 1.3.7
[PEAR] Console_Getopt - already installed: 1.3.0
[PEAR] Structures_Graph- already installed: 1.0.4
[PEAR] XML_Util - already installed: 1.2.1
[PEAR] PEAR - already installed: 1.9.2
Wrote PEAR system config file at: /private/etc/pear.conf
You may want to add: /usr/lib/php/pear to your php.ini include_path
I then typed into terminal this:
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"
And terminal issues me this and I loose my prompt! So I guess Im not inputting the commands into terminal correctly. Here's what I get...
Marks-MacBook-Air:~ mark$ cat >> ~/.bashrc <<'EOF'
>
> alias pear="php /usr/lib/php/pear/pearcmd.php"
> alias pecl="php /usr/lib/php/pear/peclcmd.php"
> EOF
Marks-MacBook-Air:~ mark$ $ . ~/.bashrc
-bash: $: command not found
Marks-MacBook-Air:~ mark$ $ sudo pear channel-update pear.php.net
-bash: $: command not found
Marks-MacBook-Air:~ mark$ $ sudo pecl channel-update pecl.php.net
-bash: $: command not found
Marks-MacBook-Air:~ mark$ $ sudo pear upgrade --force pear
-bash: $: command not found
Marks-MacBook-Air:~ mark$ $ sudo pear upgrade
-bash: $: command not found
Marks-MacBook-Air:~ mark$ $ sudo pecl upgrade
-bash: $: command not found
Marks-MacBook-Air:~ mark$ $ sudo sh -c "cat >> /etc/php.ini <<'EOF'
> ; Original - ;include_path = ".:/php/includes"
> include_path = ".:/usr/lib/php/pear"
> EOF"
So Alan... I'd be very grateful if you could point out to me what I'm doing wrong!
Many thanks!
Mark
19 May 2008
1 hour 35 min
Hi Mark. Fortunately this looks like an easy fix. It looks like you're including the $ characters in your commands. I include them on the post as a reference for when a new command begins, but you should not be using this in the command in Terminal. For example, type:
sudo pear upgrade
and NOT
$ sudo pear upgrade
Hopefully that clears it up!
And to add xdebug after this article:
1)
sudo pecl install xdebug2) Uncomment
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"from /etc/php.ini3) add this to the [xdebug] section of /etc/php.ini:
xdebug.remote_autostart=1
4) sudo apachectl restart
Hi
Thanks Alan & Tyler!
Much appreciated all this help!
Cheers
mark
Awesome! You saved me a lot of time, thx!
Thanks for the tutorial! Everything works well apart from writing privileges. Here's more info on it: http://stackoverflow.com/questions/8035939/write-privileges-localhost-ma...
Great tutorial, thanks! A real time-saver!