This is a follow-up to my previous article on installing a LAMP Stack on Snow Leopard and explains the steps that you need to get Lion up and running for LAMP development. (Linux, Apache, MySQL and PHP in case you don’t already know). Lion comes pre-installed with Apache and PHP 5.3.6 so you only need to enable those features. MySQL is the only component that you have to install.
UPDATE: I’ve posted a new tutorial for OSX 10.8 Mountain Lion
1.Turn on Apache
Go to System Settings->Sharing and turn on Web Sharing. If necessary click the button that says “Create Home Folder” which will create a folder called “Sites” in your home directory. You now have a web server that you can access at http://localhost/~username/ (“username” being your own account login name)
2. Edit /private/etc/apache2/httpd.conf
To enable PHP uncomment (remove the number sign at the beginning of) the line:
#LoadModule php5_module libexec/apache2/libphp5.so
(optional) you can re-map the server root to your home website directory by editing DocumentRoot:
DocumentRoot “/Users/username/Sites”
If you wish to use .htaccess files then look a bit further down AllowOverride and set it to “All” like so:
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
3. Edit /private/etc/apache2/users/username.conf
Your user directory has it’s own permissions as well which are located in this separate file. You may wish to enable FollowSymLinks and AllowOverride again here by changing these two lines like so:
Options Indexes MultiViews FollowSymLinks
AllowOverride All
4. Copy /private/etc/php.ini.default to /private/etc/php.ini
OSX includes a default php.ini file that you can use but you must rename or copy it first. If you don’t do this then PHP will still run but it will just be using the default initialization settings with no way for you to override them.
Edit these settings in php.ini (some of these settings will not come into play until they are installed)
display_errors = On
mysql.default_socket = /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock
date.timezone = ‘America/Chicago’
include_path = “.:/usr/lib/php/pear”
5. (Optional) Install PEAR
If you use the PEAR libraries you can install them using the included phar file like so:
sudo php /usr/lib/php/install-pear-nozlib.phar
sudo pear config-set php_ini /private/etc/php.ini
sudo pecl config-set php_ini /private/etc/php.ini
sudo pear upgrade-all
6. Install MySQL
This doesn’t really require instructions, simply download the latest MySQL from mysql.com. I installed the 64 bit version.
7. (Optional) Install Apache Plugins
If you use encryption you may need to install mcrypt. Instructions have been provided by Michael Gracie
If you use the Zend debugger you can install that using these instructions.
Custom Installs
These are here for my selfish purposes, install if you so choose!
sudo pear install --alldeps -f Spreadsheet_Excel_Writer
Total (total) newbie got this to work perfectly. Couldn’t save the php.ini file via terminal though so had to go what I suspect is a long route and show hidden files, change permissions.Thanks for the post.
Hey Amanda, you probably just need to authentication as root in order to edit files. You can so that by entering the command:
sudo su
then you’ll be logged in as root and will have access to edit those files.
Here’s what you want to do in Terminal to copy the php.ini file and make it writable:
sudo cp /etc/php.ini.default /etc/php.ini
sudo chmod u+w /etc/php.ini
You’ll still be asked for the admin password to edit the file, but that’s good practice.
Thank you! Yours was *by far* the simplest and best summary I found – it worked first try.
Hello,
I think it is an mistake. Instead of “AllowOverride to All” it should be “AllowOverride All” in /private/etc/apache2/users/username.conf
Hey Andrei, I did mean to say change the value of AllowOverride to “All” but that’s inconsistent with the rest of my tutorial so I changed it as you suggested to avoid confusion. Thanks!
another noob here — thanks for the easy to follow tutorial so i didn’t have to make more of a fool of myself on my first day at a new job