Apache examples and exercise's
Open up the httpd.conf file (Located: C:\Program Files\Apache Group\Apache2\conf\httpd.conf) with Notepad - then do a search for index.html. (Any line that starts with the # symbol in the configuration file is a Comment). This should bring you to a line of code that looks like this:
DirectoryIndex index.html index.html.var
Change this to DirectoryIndex MyNewIndex.html Now whenever you request a specific directory - this will be the page Apache will first look for. You can add additional default pages to that and Apache will look for those pages in that order, personally I like to change this to DirectoryIndex index.php index.html index.htm. (This is usually never needed - although it's nice to know how to do).
AllowOverride None To AllowOverride All (This allows us to use .htaccess files in any directory).
Example 1: Creating directory specific DirectoryIndex files. Use notepad or a similar text editor to create a file called .htaccess and place that file in a directory/folder you want this to be valid for. Inside this file place the following;
This will make it so that if you visit this directory (folder) such as http://localhost/MyFolder/ - the default start page will be MyMainPage.html.
Example 2: Creating Custom error pages within a specific directory. Follow the above steps to create a .htaccess file and add the following to that file;
ErrorDocument 404 http://www.domain.com/404.html
ErrorDocument 401 http://www.domain.com/401.html
ErrorDocument 500 http://www.domain.com/500.html
This just creates custom error documents and tells the server what to do and where to go if it finds an error such as your page not being found. You can also specify default error pages in the main httpd.conf settings. However those settings will be valid throughout your site and not just in one directory.
Example 3: Creating a password protected Directory. This gets a little tricky. But is one of the most useful examples of the .htaccess file for our purpose's. Create an .htaccess file as before with the following and place it inside any directory you want to password protect.
AuthName "restricted stuff"
You will also need to create a file that contains a UserName and a Password. This file will be called (for this example) users (with no file extension) and placed in a folder we just created called Passwords at C:\Passwords\. Their are two basic ways you can create the UserName and encrypted password 1 way is using the PHP crypt() function, the second is using the htpasswd program that comes with Apache. We will be using the second method.
To create this file you'll have to open a Dos prompt and CD (Change directory) to CD C:\Program Files\Apache Group\Apache2\Bin\ Then run the following command:
htpasswd -bc users Jeff mypass (the format is -bc NameToCallFile UserName Password). This will create a file called users in the Bin directory. The contents will look similiar to: Jeff:$apr1$aq2.....$OtFywTSs9g9dBsnFlTRTj/ (The first part is the userName the second part after the colon is the encrypted password). Copy and paste this file into the C:\Passwords\ folder we created just a bit ago.
When you try to access the Folder/Directory you placed this .htaccess file in with a web browser you will be prompted to enter a UserName and Password. Enter in the UserName and password you used to create the file and you'll be allowed in.
Overall it's not that important or secure to use this type of directory protection on Windows (cause it's still windows after all) and where mainly going to be using this as a local testing area. If you allow access to your server by others from all over the internet it will still help in keeping specified directory's contents private and with controlled access.
That's about it for the Apache installation. By locating your IP address that your computer is currently using for it's connection to the internet, you'll be able to give that address to others so they can view your website running on your own personal computer. Since most ISP's such as cable and DSL providers change your IP address all the time you'll either have to keep telling others what your new IP is - or sign up for a service which constantly updates each time your IP changes and points it to a specific domain name for you. If you are planning on letting other's visit your website running on a server on your home computer it's also a good idea to keep your firewall going - you'll have to change some settings so that it allows others to view your site.
Next it's onto PHP..
|» Level Advanced|
Rating: 9 Votes: 108
|Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content, applications, and content management systems. Specialty's include SQL, PHP, Perl, XML, web services, and Flash clients for web services.|
|Download the files used in this tutorial.|
|Download (30 kb)|
|More help? Search our boards for quick answers!|