It works!

It works! is the error message, that appears in the frame of a browser while one tries to access the URL Localhost, using the apache software at the poor configuration .

Sometimes, the sentence It works! is stored in file /Library/Webserver/Documents/index.html.en and can be substituted to something meaningful. In other cases, the content of file /Library/Webserver/Documents/index.html.en does not affect the look of sites localhost nor http://127.0.0.1 and it requires serious efforts to locate the file that produces the error message.

The path to the secret file, that generate message It works! can be cracked with the appropriate hummer or ax. In Linux and Macintosh operational system, the efficient ax seems to be

ls -ax

Attempts to solve the problem indicated with sentence "It works!"
In general, sentence It works! in the frame of a browser has meaning, opposite to that it could have in the common English. Sentence It works! indicates, that something is wrong with the server, and it does not work as follows. In some cases, the experienced administrators can solve the problem. The hints to do this are available : <!-- The Setting up PHP

Enter the following into the command line/shell (Terminal): sudo nano -w +114 /etc/apache2/httpd.conf Whenever you put sudo in front of a command you will need to enter your root/administrator password when prompted to do so.

Your cursor will now be at the beginning of line 114, which should look like this: Uncomment that line by removing the pound/hash sign (#).
 * 1) LoadModule php5_module libexec/apache2/libphp5.so

Before you close the httpd.conf file you should hit control w and search for: DirectoryIndex index.html Add index.php to the end of the line like so: DirectoryIndex index.html index.php

When you are finished hit control x to exit, then type y, and hit return to save your changes.

Now, you should type the following into Terminal: sudo cp /etc/php.ini.default /etc/php.ini

I’ll let you choose how you configure your php.ini file but I’d suggest you make sure PHP reports all errors, so in shell type: sudo nano -w +305 /etc/php.ini Change line 305: error_reporting = E_ALL & ~E_NOTICE To: error_reporting = E_ALL Close and save (unless you have any other changes to make of course). If you’re lazy you can just download php.ini-recommended and overwrite php.ini with that.

Setting up Apache If you’re like me and use rewrite rules in an .htaccess file for those nice clean search engine-friendly URLs you’ll need to make sure mod_rewrite is working properly. For this you will need to know your computer’s short name, on this one it is ariadoss, so replace ariadoss with whatever yours happens to be, you can easily tell what it is from the Terminal cause it’s the name right before the dollar sign (e.g. danilo-stern-sapads-macbook:~ ariadoss$). If you still can’t figure it out it doesn’t matter since there is only one file in /etc/apache2/users, which should be yourname.conf.

Go to the Terminal and type in everything except the bold part unless you know what goes there, hit tab to autocomplete the missing bold part with your info before hitting return: sudo nano -w /etc/apache2/users/ariadoss.conf

You should now see something like this on line 1:  Directly underneath line 1, you should change lines 2 and 3 to look like this: Options All AllowOverride All Close and save.

We’re not exactly done yet but let’s go ahead and test that Apache and PHP are running. Go to System Preferences, click on the Sharing icon, then select Web Sharing and make sure it’s checked, the light will turn green and it will say Web Sharing: On. Now open up your favorite web browser and go to: http://localhost/

If you want to see the contents of your Sites directory go to: http://localhost/~ariadoss Again, make sure you replace ariadoss with your short name.

Personally, I hate typing in ~ariadoss every time I need to test a site so I made some further changes to my httpd.conf file, which you probably only want to implement if there are no other users on your computer. We could setup virtual hosts to make short memorable URLs like http://ariadoss/ instead of just pointing /Users/ariadoss/Sites to http://localhost but that’s outside the scope of this tutorial. However, if this interests you read my tutorial on How to setup virtual hosts on Mac OS X 10.5 (Leopard).

So here’s what you do, back to Terminal: sudo nano -w /etc/apache2/httpd.conf Once open, replace the two occurrences of /Library/WebServer/Documents (on lines 163 and 190) with the full path to your own Sites directory (e.g. /Users/ariadoss/Sites). To easily find the path to your particular directory open another Terminal window (command n) and enter: cd ~/Sites pwd

Once you finish finding and replacing all that jazz, restart Apache using the command below: sudo apachectl restart

You’ll want to restart the Apache service either from System Preferences or the command line whenever you make a change to a configuration file.

Okay, now I know that was a lot to absorb and we haven’t even gotten to building and installing MySQL yet, so get a drink of water, stretch, even walk around a little bit, just make sure to clear your head before proceeding to the next section. You may want to go to http://localhost/ and make sure it’s displaying the contents of your Sites directory – if not make sure you clear your cache and refresh the page before assuming you did something wrong and double check your index.html file’s contents so you know what to expect. !-->

ps -ax


Many colleagues suggest various hints about guessing the location of the apache root directory. Some of them are listed in the article apache.

The most efficient seems to be command ps -ax ; it returns the list, that can be used to guess, which apache directory is used as default.

With this ax, the secret of location of the Apache root directory can be broken (cracked, revealed).

Keywords
Apache, Localhost, 127.0.0.1, error