After upgrading to Snow Leopard today I tried to access my localhost versions of the websites I have under development and was met by this great message, (impatient? skip to the step-by-step solution):
Forbidden
You don’t have permission to access / on this server.
Great. I couldn’t even access http://john-mbp/ – my computer’s name, and the URL that the System Preferences’ Web Sharing pane tells me I can access. However, all is not lost.
Part 1: Get the Virtualhosts Online
The first place I looked was my httpd-vhosts.conf file, located in /var/apache2/extra, (this has not changed since 10.5), and as I suspected it had been reset to the Apache defaults, (thanks Apple). I suspected this might happen though, and had made a backup of the file, (actually, I backed up my whole hard drive, then made a separate, easier to find, copy of the file). Replacing the new httpd-vhosts.conf with the old one and doing an sudo apachectl graceful
got the virtualhosts responding to requests again.
Part 2: Establish a MySQL Connection
While my virtualhosts were up and running at this point they did not have a MySQL connection. Maybe this is because my MySQL installation is from MacPorts so the socket is in a different place, or maybe not. Either way it had to be fixed.
Upon running a phpinfo();
I discovered a couple of things. First, the included version of PHP is now 5.3.0 and second, PHP was not loading any php.ini file, so I went on a php.ini hunt and found 2 files: php.ini.default and php.ini.default-5.2-previous, both located in /etc. Copying php.ini.default to /etc/php.ini and doing a sudo apachectl graceful
brought my MySQL connections back online, leaving one final problem.
Part 3: Getting rid of the timezone warnings
Since I usually code with an error reporting level of E_ALL, and PHP 5.3 doesn’t seem to like not having a timezone set in the php.ini file, (it’s not set by default, at least not in Snow Leopard), I was getting a bunch of warnings whenever I used the date();
function in PHP, so, I needed to set a default timezone in php.ini. If you don’t already know the PHP name for your timezone, go to the PHP timezones page and find it, then open php.ini, (sudo vi /etc/php.ini
the sudo is important), and search for “timez” to find the timezone section of the file. Now, on the line that says “;date.timezone = ” add the name of your timezone after the equals sign and remove the semicolon from the beginning of the line. Once you’ve done that, save the file, (it’s set as read-only for some reason so in vi you need to do :w!
to make it save), then quit your text editor and do one more sudo apachectl graceful
and you should be good to go.
Step by Step
- before installing, back up your computer
- before installing, make a copy of /etc/apache2/extra/httpd-vhosts.conf and put it somewhere safe
- install Snow Leopard
- replace the new /etc/apache2/extra/httpd-vhosts.conf with the old one you saved in step 2. If you don’t have a backup you’ll have to re-enter your virtualhosts in the new httpd-vhosts.conf file which isn’t the end of the world
- in Terminal type
sudo apachectl graceful
and enter your password if prompted to restart apache with the new configuration. Your virtualhosts should now be online - rename or copy /etc/php.ini.default to /etc/php.ini (
sudo cp /etc/php.ini.default /etc/php.ini
) - Find the name of your PHP timezone, (look on the PHP timezones page). Write it down.
- Edit the new php.ini file to have the correct timezone.
- open the new php.ini file (
sudo vi /etc/php.ini
) - find the timezone section, (type
/timez
and press enter). - move your cursor to the line that says “;date.timezone = ” using the arrow keys
- press the i key to edit the text
- add the name of your PHP timezone after the equals sign
- remove the semicolon from the beginning of the line
- press the escape key to stop editing the text
- type
:w!
to save the file - type
:q
to quit the text editor
- open the new php.ini file (
- One final
sudo apachectl graceful
and you should be back up and running.
One other thing… I had a bunch of extensions in /usr/lib/php/extensions. All of these were deleted by the Snow Leopard installation. Back these up if you have them! I suppose if they had been somewhere else (/usr/local ?) they might have been spared.
That’s good to know too. It seems that the full PHP/Apache stack is replaced. I haven’t been using Ruby & RoR, but I think those are replaced as well.
Snow Leopard – Umstiegshürden eines Webentwicklers…
Nun läuft Mac 10.5.6 alias Snow Leopard schon über 24h auf meinem MacBook Pro.Der anfängliche Begeisterung über den spürbaren Geschwindigkeitspush folgt nur leider der eine oder andere Katzenjammer. Bei mir bedeutet dies den Ausfall von wichtigen Pro…
Nice write up John.
Just in case anyone else gets stuck in the same place as me with the ERROR 2002 message and hasn’t used MacPort for the MySQL server … check that your php.ini is actually pointing to the mysql sockets … ie that “/var/mysql/mysql.sock” is changed to “/tmp/mysql.sock” (assuming you check that’s where the socket actually is).
cheers and thanks again.
Very true Brent. The Snow Leopard install plays fast & loose with the configuration files for pretty much the whole LAMP stack.
The php.ini file that comes with Snow Leopard defines:
mysql.default_socket = /var/mysql/mysql.sock
...
pdo_mysql.default_socket=/var/mysql/mysql.sock
You might need to change these depending on your MySql setup.
Yes. I probably should have pointed that out.
On the flip side, you could edit the my.cnf file to put the socket where PHP expects it, but it’s probably easier to keep most of your editing in one place.
[…] found this post useful. Here is another similar post. Grab Bag Apple, Mac OS X, PHP Development, tips & tricks, Website […]
I’m in a bit of a pickle – MySQL broke after I updated to 10.6.3.
http://discussions.apple.com/thread.jspa?threadID=2390204&stqc=true
Any chance you experience same? I have local DBs I need to move from their now-broken locations and am on deadline to finish a project! Whoops! Great blog btw, I linked to you a while back.
Sorry for the delay getting back to you – it didn’t happen to me, but it looks like you solved it!
[…] Get your Development Server Running after Upgrading to Snow Leopard MP3 (3.1 MB) Filed in Mac, Movable Type, PHP Posted by Roger Johansson Tagged .NET, 10, Ad, ads, All, App, article, Blogs, dev, downloads, fun, list, mysql, PHP, Time, top, war, Working blog.lanche86.com is powered by WordPress using theme Tribune […]
Thanks for sharing. I was having problems with my virtual hosts and I had not looked at virtual host file