Apache Web Sever Configuration

 

  1. The default root directory for Apache is /var/www/html - You should put anything you want to be seen on the WWW under this folder.
  2. The default location for the configuration file (called httpd.conf) is /etc/httpd/conf/httpd.conf. I suggest taking a look at this file (explained later) in case you need to modify anything in it later. For initial set up, everything should work just fine.
  3. For the manual to Apache web server you can either browse the files in /var/www/manual or go online to http://httpd.apache.org/docs-2.0/
  4. Perl/CGI & PHP support are already built in to Apache and do not require you to modify or configure anything! Just simply put your php files under the /var/www/html folder or .cgi files in the /var/www/cgi-bin/ folder).
  5. Security - Password protecting your files and folders is very important, especially since a user would have access to mySQL databases and much more through your web server. Here is just a small example of how to password protect the folder /var/www/html/phpMyAdmin-2.5.1 (phpMyAdmin is a graphical way of managing mySQL databases - please see the phpMyAdmin tutorial for more information).
  6. To view/edit the Apache configuration file, go to a terminal command (do not type Shell> - this is the command prompt and may be different on your system - more commonly [root@localhost root]# - see Fig 2.2 for more information) and type the following:

 

shell> vi /etc/httpd/conf/httpd.conf

 

  1. At the bottom of this Apache configuration file, insert the following lines in by touching i (for insert) on the keyboard:

<Directory> "/var/www/html/phpMyAdmin-2.5.1">

AllowOverride AuthConfig

AuthType Basic

AuthName "PHP Administration Password Required"

AuthUserFile /var/www/passwd.file

Require user bob

</Directory>

·        Figure 2.1 shows a screen capture of the vi program and the addition of the above lines.

 


Figure 2.1

 

  1. When you are done putting these lines in, hit the Esc key and then type :wq which means write & quit.
  2. Next, you will need to create the password file that you specified in the AuthUserFile line. In my example I called it passwd.file and it was in the /var/www/ directory. Make sure that this password file is not accessible to outside users (i.e don't put it in /var/www/html).

10.   To create the file and add a password for a user named Bob, type the following at a command prompt:

 

shell> htpasswd -c /var/www/passwd.file bob

 

11.   This will effectively create a file called /var/www/passwd.file and put a line containing the password for bob. The program will ask you to input the password for bob twice and will encrypt it so it can't be read by humans.

 

*NOTE: All usernames & passwords on Linux are CaSe SenSiTive.

 

12.   Change the permissions on the file so the server can have access to the file:

 

shell> chmod 755 /var/www/passwd.file

 

13.   To add more users type the same command without the -c option included (the -c option creates a new file). So for example, if I want to add another username/password combo for jane, then you would type:

 

shell> htpasswd /var/www/passwd.file jane

 

14.   Make sure you add jane to the Require user line of the httpd.conf Apache configuration file or else it will not work correctly (i.e. Change the line to read Require user bob,jane).

15.   Now you will need to restart the apache webserver. To do this, go to a terminal command prompt and type:

 

shell> service httpd restart

 

16.   Apache will shutdown and restart loading the new configuration file (/etc/httpd/conf/httpd.conf) you have modified.  Figure 2.2 shows the terminal command screen after all of the above commands have been executed.

 


Figure 2.2

 

Reference

 

http://httpd.apache.org/ - Online manual and documentation for help installing and configuring Apache.