LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2)
Following my how to setup your mac web development environment, and today moving to Leopard, my entire offline environment is broken - this is entirely due to the move from Apache 1.3 to Apache 2.2.
This article will discuss the changes required to get your multi-host mac dev environment running again with PHP5, MySQL, Apache 2 and Leopard.
Orientation
Since we're running Apache 2.2, it means a few files have new homes. Here's a comparison:
/etc/httpd/httpd.conf => /etc/apache2/httpd.conf
/etc/httpd/users/ => /etc/httpd/users/
Get your virtual hosts back
Copy your .conf from your old httpd/users/ directory in to the new one (above). For example:
cp /etc/httpd/users/remy.conf /etc/apache2/users/remy.conf
If you restart apache (sudo apache restart) you should have the domains pointing to your sites.
PHP5
PHP5 appears to come with Leopard (though I could be wrong, since I upgraded - please feel free to correct me). To re-enable it, within /etc/apache2/httpd.conf, around line 114 - you should find # LoadModule php5_module - uncomment this and restart apache.
Run a little PHP test, and you'll find you're running PHP again.
MySQL
You have two options to get MySQL running again if you have the following error:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)
- Reinstall PHP5 and compile it with the new path to the MySQL socket (
/tmp/mysql.sock) - Change MySQL's conf to run the socket out of the old location
Since Leopard gave me PHP 5.2.4, which according to Entropy PHP, is the latest version for Apache 2.x, I went with option 2.
If you don't already have the MySQL conf in /etc/my.cnf (I didn't), then you need to copy a template out of the support files from MySQL. If you followed the instructions from my previous article - then you'll need to run the following:
sudo cp /usr/local/mysql-standard-5.0.27-osx10.4-i686/support-files/my-small.cnf /etc/my.cnf
Replace small with whatever suits your setup best.
Now follow these steps:
1. Shutdown MySQL
mysqladmin -uroot shutdown
2. Change the conf
Change all occurrences of /tmp/mysql.sock to /var/mysql/mysql.sock
3. Create /var/mysql/
sudo mkdir /var/mysql
sudo chmod 777 /var/mysql
4. Start MySQL back up again
cd /usr/local/mysql/
sudo ./bin/safe_mysqld &
Wrap Up
That should be it. I've tried to document every change I made to get going again, but if you spot any mistakes or have trouble with these instructions let me know and I'll try to help.
You should follow me on Twitter here I'll tweet about JavaScript, HTML 5 and other such gems (amongst usual tweet-splurges)
Introducing HTML5
After upgrading to Tiger and my apache setup got eaten I found that keeping out of the OS's apache etc is the best solution.
A friend on IRC suggested to me, MAMP. http://mamp.info
After playing for a couple of months I sprung the cash for MAMP Pro which provides virtuals etc GUI.
But if you visit their forums, there is how-to's on setting up virtuals without the pro.
[...] The article LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2) [...]
[...] http://stringfoo.com/2007/11/05/server_setup_on_leopard/ http://remysharp.com/2007/10/27/lamp-in-leopard-osx-105-php5-and-apache-22 [...]
[...] opted to re-configure MySQL by following the instructions in the MySQL section of the blog post at http://remysharp.com/2007/10/27/lamp-in-leopard-osx-105-php5-and-apache-22/ [...]
Thank you! Your explanations were perfect. I am now up and running once again thanks to you. I was stuck on the mysql.sock, but no longer!!!
I need help. Running MacBook Pro Leopard and trying to get MySql working. Have the 64bit version. Keep getting "can't connect to local MySQL server through socket '/tmp/mysql.sock' I have been searching through all files and cannot find file with mysql.sock anywhere. Neither var or tmp have the mysql.sock files. Should there be? Havent done UNIX for ages or this level of manipulation.
Did create a mysql folder in Var but what does the chmod to 777 do?
Thanks a lot, was of gr8 hlp!
I'm not sure you should chmod 777, rather just chown _mysql.
Sam
Hey Guys,
since my macbook is not working (for 1 year) and i´ve not the money for a new one I ´ve no actual information (espacially concerning OS X 10.5) but maybe the Tool mamp is worth the look.
http://www.mamp.info/en/
Works great brings a nice frontend and you have no stress about configuring.
Greets from Germany
Nico
Hey, you say 'LAMP' your lucky the os your talking about starts with an L.
Entropy's Leopard PHP Beta works just fine - in fact, I'm using it on my production servers at the office:
http://www.entropy.ch/phpbb2/viewtopic.php?t=2945&postdays=0&postorder=asc&start=0&sid=8307eca2fafce0ca7df34900d4eb3b32
Serious, running it on a 75+ website environment with mission critical websites; and the only reason I did it is because my developer friends at Apple admitted they were running it in production as well for their retail environment.
hi - nice article on this. I had a similar article but was interested in PHP 5 and your method. Very clear explanation too. Love your jQuery stuff as well dude!
Which conf file am I supposed to change while MySQL is shutdown and where can it be found?
when i tried to access localhost/~min which is my username i got this message. How to solve it?
Forbidden
You don't have permission to access /~macbook on this server.
Hey guys, i got around this problem by sending 127.0.0.1 rather then 'localhost' to the thing that wanted to hook mysql up to (Joomla)
ok i got it all wetup and running great. Now I'm trying to move my DocumentRoot to another partition at "/Volumes/files/localhost". Is this possible? I just get a 403 when i change the DocumentRoot and locations. I did change it in my vhost also. whats wrong with my thinking?
There is another, simpler solution to the problem with PHP looking for mysql.sock. In a terminal window, do the following:
1) Create the /var/mysql directory:
mkdir /var/mysql2) Change to the new directory:
cd /var/mysql3) Create a symbolic link in the new directory that points to /tmp/mysql.sock:
ln -s /tmp/mysqlsock $PWD/mysql.sockVoila! No messing with either the MySQL or PHP installation.