lundi 27 août 2012

Enabling apache and PHP on Mountain Lion

Mac OS X 10.8.1 (Moutain Lion) comes with both Apache and PHP preinstalled, but the Web Sharing option from System preferences disappeared and PHP is not enabled by default. The following instructions should help you get your Web server up and running in a breeze.

Web Sharing — option removed from System Preferences. Apache is still included with the operating system and can be enabled using third-party software.[37]

The Geek way will use the terminal application, but you can also use Finder to search for the files (the Go menu will help you get there directly) and edit them with your favorite text editor.

So, enough talk, open a shell, terminal, bash whatever you call it!

Then enter:
cd /private/etc/apache2/

That should look like:

Should I mention to press enter?
Then type the following command to edit the apache configuration file:
sudo nano httpd.conf
Press enter and enter your password at the prompt.

This opens httpd.conf, the main configuration file for Apache, don't mess it up!!

 Scroll down until you find the code shown in the following screenshot: 

Position your cursor at the beginning of the line:

#LoadModule php5_module libexec/apache2/

 and remove the hash or pound sign (#). It should now look like this:

LoadModule php5_module libexec/apache2/

Et voilà, this enables PHP 5 on your computer.

Now save the file:
And exit nano:

Now we need to create a configuration file for PHP.

Enter the following commands one by one:
First to go to the correct directory:
cd .. or cd /private/etc/
Then copy the default file provided from php.ini.default to php.ini
In other words, you create a php.ini file with default parameters.

sudo cp php.ini.default php.ini
enter your password again at the prompt

Now, let's edit the file:
sudo nano php.ini

The most important change is to a command called error_reporting to avoid a server a bit too chatty.The default setting looks like this:
error_reporting = E_ALL & ~E_NOTICE
change it to:
error_reporting = E_ALL

This ensures that PHP reports all errors, but nothing more. Although no one likes error messages, it's vital to eliminate any errors (even seemingly minor ones) before deploying scripts on a live web server.

NOTE: There are several lines that look similar. Make sure that you edit the line that does NOT begin with a semicolon. A semicolon at the beginning of a line in php.ini indicates a comment, which is ignored by the server.

save php.ini:
exit nano:

To restart the Apache Web server you can go the geek way or reinstall the option in System preferences.

For the geek way, you need to do this :
sudo apachectl restart
enter your password at the prompt

Useful apachectl commands include:

  • apachectl start
  • apachectl stop
  • apachectl restart
  • apachectl -t
or you can reinstall the Web Sharing option from System preferences, provided by a gentleman at: 

Enjoy your brand new personal Web server!

2 commentaires:

Anonyme a dit…

Hello there, just became aware of your blog through Google,
and found that it's truly informative. I am going to watch out for brussels. I will appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!

Also visit my web blog :: tide coupons

Anonyme a dit…

You made some good points there. I checked on the web for more
info about the issue and found most people will go along with your views on this site.

my web blog - Mountain dew Breakfast drink

Marc Augier