Enable WebSharing & PHP – Mac OS X 10.8

Well… here I was racking my brain as to why I couldn’t find any toggle for Web Sharing in Mac OS X 10.8.2. The Answer is a kicker in the pants. Apple have removed Web Sharing as an essential service and moved it over to Mac OS X Server. But thanks to Google for being my friend. I found out there is not only a way to re-enable the Web Sharing but someone had been kind enough to write a WebSharing prefpane. Once this was installed from Clickontyler.com. All I had to do then is enable PHP.

As the prefpane I just installed had told me PHP was not enabled. Thankfully OSXDaily.com had an article for this subject and it’s quite very simple to enable. this is how it’s done.

Launch Terminal and enter the following command, using the administrator password when requested: sudo nano /etc/apache2/httpd.conf
Now hit Control+W to use the search feature of nano, and type in “php” Locate the following line and remove the comment (#) from the beginning:
LoadModule php5_module libexec/apache2/libphp5.so

Now hit Control+O to save the changes, followed by Control+X to quit out of nano. Back at the command prompt, you’ll want to restart the Apache server for the php module to load.
This is done with the following command, or you can toggle the on/off switch in the 3rd party WebSharing panel:

sudo apachectl restart
Apache quickly restarts and PHP will be enabled.

Now up until now I was sailing pretty smoothly getting everything back on track to where I wanted it. But I hit a snag. I wasn’t able to see anything from the http://localhost/~user I was getting permission denied errors. I was getting the you do to have permission error 403. So thank you Topher Kessler from cnet for posting his article “How to enable Web Sharing in OS X Mountain Lion.
I followed these easy steps:

  • 1.    Open the OS X Terminal utility (/Applicaitions/Utilities/)
  • 2.    Create and edit an Apache user configuration file named after your user account by running the following command.
sudo pico /etc/apache2/users/`whoami`.conf
  • 3.    Copy the following text into the Terminal editor that opens, but be sure to change the “username” text to the short name of your user account:
<Directory “/Users/username/Sites/”>
     Options Indexes MultiViews
     AllowOverride All
     Order allow,deny
     Allow from all
</Directory>
  • 4.    Save and close the editor by pressing Control-O followed by Control-X.

This was great I had the web sharing enabled,PHP configured and I was about to install wordpress on my iMac and I came unstuck . With this little beauty of an error message:
“Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required in Unknown on line 0 ”

Thanks to this How to solve “Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required in Unknown on line 0 ” problem?

This error is due to the file permission. To resolve this issue we should change permission with SuperUser (sudo). To do we use the following:
sudo chmod -R 0755 foldername
so for my example sudo chmod -R 0755 /Users/username/Sites/wordpress/

I then restarted the apache server with: sudo apachectl restart
Then opened a new browser tab & browsed to localhost/~user/wordpress and I was greeted with the setup page, successs!

I hope this helps someone else in need.

References:
google.com
http://rat32.com/rat32/?p=25
http://clickontyler.com/blog/2012/02/web-sharing-mountain-lion/
http://osxdaily.com/2012/09/10/enable-php-apache-mac-os-x/
http://reviews.cnet.com/8301-13727_7-57481978-263/how-to-enable-web-sharing-in-os-x-mountain-lion/