Apache Web Server Setup 2

3,561 views
3,464 views

Published on

http://www.cju.com/classes/2002/WMB-520/

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,561
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
310
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Apache Web Server Setup 2

  1. 1. WMB-520: Web Technology Web Server Setup <ul><li>Meeting 2: Apache Installation and Initial Configuration </li></ul><ul><li>Rutgers University Center for Applied Computing Technology </li></ul><ul><li>Instructor: Chris Uriarte </li></ul>
  2. 2. Apache <ul><li>The world’s leading web server software (powers 65% of all web sites in the world) </li></ul><ul><li>Runs on UNIX and Windows platforms. UNIX version is the most stable and most widely used. </li></ul><ul><li>Configuration is the same on all UNIX platforms, varies slightly on Windows systems. </li></ul>
  3. 3. How Do I Get Apache? <ul><li>There are currently two supported releases of Apache: v1.3 and v2.0. Version 1.3 is the most widely used (95% of all Apache installation), but version 2.0 will become more popular over the next 12-18 months. </li></ul><ul><ul><li>There are many subversions released throughout the lifetime of a major version (i.e. 1.3.10) </li></ul></ul><ul><li>You can download it from the Apache Website: http://www.apache.org/dist/ </li></ul><ul><ul><li>Binary Versions – software that is ready-to-use for your specific operating system platform </li></ul></ul><ul><ul><li>Source Code – the computer code used to build Apache. You must use a compiler to build the code. </li></ul></ul><ul><li>You can buy a Unix distribution that comes bundled with Apache pre-built (most Linux distributions include Apache by default). </li></ul>
  4. 4. Installing Apache from Source <ul><li>Allows you to build the Apache binaries from scratch. </li></ul><ul><li>Optimizes Apache for the platform on which it will run. </li></ul><ul><li>Allows you to specify special server features at build-time. </li></ul><ul><li>You need a C compiler (i.e. gcc) installed on your system to compile source code, which is included in most UNIX distributions. </li></ul>
  5. 5. Apache Modules <ul><li>Apache has a modular structure. Only a core set of features exists within the main Apache executable. </li></ul><ul><li>Apache Modules provide additional functionalityto Apache. </li></ul><ul><li>Example Module: mod_speling : The Speling module attempts to correct misspellings of URLs that users might have entered, namely by checking capitalization or by allowing up to one misspelling (character insertion, omission, transposition, typo). </li></ul>
  6. 6. Apache: Static vs. Dynamic Servers <ul><li>Static Servers </li></ul><ul><ul><li>Must decide at build time what modules to include. Recompiling will be necessary to add modules later. </li></ul></ul><ul><li>Dynamic Servers </li></ul><ul><ul><li>Allows you to utilize new modules without re-compiling apache. </li></ul></ul>
  7. 7. Static vs. Dynamic Apache <ul><li>Building a static (standard) Apache distribution limits you to the modules you choose when you compile the server. </li></ul><ul><li>However, using Apache with dynamic modules makes apache more difficult to administer, perform slower and increases its memory requirements. </li></ul><ul><li>Consider building a static server, as the need to add new modules is not very common and re-compiling Apache is simple. </li></ul>
  8. 8. Installing Apache Source <ul><li>Create a directory under your blender.rutgers.edu home directory called “apache” </li></ul><ul><ul><li>mkdir apache </li></ul></ul><ul><li>You now need to obtain the Apache source file (which you’d usually do from http://www.apache.org/dist ). You can copy the source that is contained locally on the blender.rutgers.edu server: </li></ul><ul><ul><li>cd apache </li></ul></ul><ul><ul><li>cp ~chrisjur/apache_1.3.27.tar.gz . </li></ul></ul><ul><li>You should now have the Apache source file under your home directory in /home/<username>/apache. </li></ul>
  9. 9. Unzipping and Untar’ing the Source File <ul><li>You now have the Apache source distribution under your home directory in /home/<username>/apache. </li></ul><ul><li>The source file is actually a group of tar’ed files and directories, which is then zipped using the gzip utility. </li></ul><ul><li>You can untar and unzip the source distribution by issuing: </li></ul><ul><ul><li>tar –xvzf apache_1.3.27.tar.gz </li></ul></ul>
  10. 10. Unzipping and Untar’ing the Source File – con’t. <ul><li>Unpacking the distribution file will create another directory under /home/<username>/apache called “apache_1.3.27” (/home/<username>/apache/apache_1.3.27). </li></ul><ul><li>“ cd” to the apache_1.3.27 to view the files and directories that are included in the distribution. </li></ul>
  11. 11. Sample Directory Listing from Source Distribution <ul><li>iti% cd apache_1.3.27 </li></ul><ul><li>iti% ls </li></ul><ul><li>ABOUT_APACHE LICENSE README.NT conf htdocs </li></ul><ul><li>Announcement Makefile README.configure config.layout icons </li></ul><ul><li>INSTALL Makefile.tmpl WARNING-NT.TXT config.status logs </li></ul><ul><li>KEYS README cgi-bin configure src </li></ul><ul><li>iti% ls -al </li></ul><ul><li>total 272 </li></ul><ul><li>drwx------ 8 chrisjur users 4096 Oct 15 20:21 . </li></ul><ul><li>drwx------ 13 chrisjur users 4096 Oct 15 21:10 .. </li></ul><ul><li>-rw------- 1 chrisjur users 12957 Mar 31 1999 ABOUT_APACHE </li></ul><ul><li>-rw------- 1 chrisjur users 2922 Feb 23 2000 Announcement </li></ul><ul><li>-rw------- 1 chrisjur users 27964 Dec 21 1999 INSTALL </li></ul><ul><li>-rw------- 1 chrisjur users 35773 Aug 20 1999 KEYS </li></ul><ul><li>-rw------- 1 chrisjur users 2848 Jan 1 1999 LICENSE </li></ul><ul><li>-rw------- 1 chrisjur users 26929 Oct 15 20:20 Makefile </li></ul><ul><li>-rw------- 1 chrisjur users 26758 Jan 11 2000 Makefile.tmpl </li></ul><ul><li>-rw------- 1 chrisjur users 2046 Apr 1 1998 README </li></ul><ul><li>-rw------- 1 chrisjur users 3132 Mar 19 1999 README.NT </li></ul><ul><li>-rw------- 1 chrisjur users 11176 Dec 20 1999 README.configure </li></ul><ul><li>-rw------- 1 chrisjur users 331 Sep 21 1998 WARNING-NT.TXT </li></ul><ul><li>drwx------ 2 chrisjur users 4096 Feb 23 2000 cgi-bin </li></ul><ul><li>drwx------ 2 chrisjur users 4096 Feb 23 2000 conf </li></ul><ul><li>-rw------- 1 chrisjur users 5909 Dec 28 1999 config.layout </li></ul><ul><li>-rwx--x--x 1 chrisjur users 312 Oct 15 20:20 config.status </li></ul><ul><li>-rwx------ 1 chrisjur users 56062 Feb 5 2000 configure </li></ul><ul><li>drwx------ 3 chrisjur users 4096 Feb 23 2000 htdocs </li></ul><ul><li>drwx------ 3 chrisjur users 4096 Feb 23 2000 icons </li></ul><ul><li>drwx------ 2 chrisjur users 4096 Feb 23 2000 logs </li></ul><ul><li>drwx------ 11 chrisjur users 4096 Oct 15 20:21 src </li></ul>
  12. 12. Apache Installation: Step 1 <ul><li>Before actually building the Apache binaries, you must run a configure utility, which inspects your system and prepares the distribution for compiling. </li></ul><ul><li>The configure script is located in the directory that was created when you unpacked the Apache source distribution (i.e. /home/itiXXX/apache/apache_1.3.27) </li></ul><ul><li>The included INSTALL file has instructions on how to configure and compile Apache. </li></ul>
  13. 13. Apache Installation: Step 1 con’t. <ul><li>Run the configure script like this: </li></ul><ul><ul><li>./configure --prefix=/home/itiXXX/apache </li></ul></ul><ul><li>The “prefix” flag tells Apache where you actually want to install the software and configuration files. </li></ul><ul><li>It also builds the Apache software so it knows where to look for configuration files </li></ul>
  14. 14. Apache Installation: Step 2 <ul><li>After the configure script runs successfully, you now need to compile the software code into the actual binaries. </li></ul><ul><li>You can start the compile by issuing the make command in the Apache distribution directory, i.e: </li></ul><ul><ul><li>cd /home/itiXXX/apache/apache_1.3.27 </li></ul></ul><ul><ul><li>make </li></ul></ul><ul><li>The compile process will take 2-10 minutes, depending on the speed of your system. </li></ul>
  15. 15. Apache Installation: Step 3 <ul><li>When the compile is complete, you can install the software and configuration files by issuing the make install command. </li></ul><ul><li>This will copy the built binaries and configuration files into the /home/<username>/apache directory you specified when you ran the configuration script. We will now refer to this directory as the Server Root directory. </li></ul>
  16. 16. The Server Root Directory <ul><li>Examine the contents of the Server Root directory. You now have a group of directories Apache uses: </li></ul><ul><ul><li>bin : the location of the actual apache program and other utilities </li></ul></ul><ul><ul><li>conf : location of the configuration files </li></ul></ul><ul><ul><li>htdocs : the directory where web pages and and associated files are kept </li></ul></ul><ul><ul><li>logs : where apache keeps log files </li></ul></ul><ul><ul><li>man : UNIX man pages for apache </li></ul></ul><ul><ul><li>cgi-bin : the directory where CGI scripts are kept </li></ul></ul>
  17. 17. Apache and Privileged Ports <ul><li>Any TCP/IP port <1024 is considered a privileged port. </li></ul><ul><li>Privileged Ports can only be accessed by applications started by the root (system admin) user. </li></ul><ul><li>Therefore, since you are not the root user on this system, you must configure Apache to use a port >1024. </li></ul>
  18. 18. Quickstart: Change the Port Number your Apache Server Uses <ul><li>“ cd” to the Apache conf directory (/home/itiXXX/apache/conf) </li></ul><ul><li>Use a text editor to open the httpd.conf file, which is the main Apache configuration file. </li></ul><ul><li>Find the line that says “Port XX”. Your file may say “Port 8080” or some other number. </li></ul>
  19. 19. Change your Apache Port, con’t. <ul><li>Replace the number next to the “Port” directive to a number that corresponds to you. </li></ul><ul><li>Use the numeric portion of your blender.rutgers.edu username. For example, if your username is iti2345 , use port 2345 as your port number. </li></ul><ul><li>Exit your editor and save the file. </li></ul>
  20. 20. Getting Ready to Run Apache for the First Time… <ul><li>Apache is configured to look for web documents in the htdocs directory under the server root (/home/itiXXX/apache/htdocs). </li></ul><ul><ul><li>This directory is known as the “ Document Root ” </li></ul></ul><ul><li>Be default, a page called “index.html” is the first page of a the website returned to clients. </li></ul><ul><li>Create an index.html file in your htdocs directory that contains the text “Hello World. My name is <Your Name>” </li></ul>
  21. 21. Starting Apache: The “Hard” Way <ul><li>The actual Apache binary is called httpd and it resides in the Apache /bin directory. </li></ul><ul><li>You can start Apache by simply executing the httpd command </li></ul><ul><ul><li>cd apache/bin </li></ul></ul><ul><ul><li>./httpd </li></ul></ul><ul><li>Apache is now started! </li></ul>
  22. 22. Verify that Your Instance of Apache is Working <ul><li>Point a web browser to http:// blender.rutgers.edu :<PORT > </li></ul><ul><ul><li>(recall, you configured the port number in the httpd.conf file to be the numeric portion of your iti username) </li></ul></ul><ul><li>You should see your default web page appear (the contents of the htdocs/index.html document we created at earlier) </li></ul>
  23. 23. Stopping Apache: The “Hard” Way <ul><li>Remember, every time you execute a program on a UNIX operating system, a process is created </li></ul><ul><li>Apache creates a file called httpd.pid in its logs directory. This file contains the parent process ID of the Apache process. </li></ul><ul><li>You can kill the process by using the kill command </li></ul><ul><li>You can kill Apache by issuing the following commend: </li></ul><ul><ul><li>kill –TERM `cat /home/<username>/apache/logs/httpd.pid` </li></ul></ul>
  24. 24. Starting and Stopping Apache: The “Easy” Way with apachectl <ul><li>A script called apachectl is included in the apache/bin directory. </li></ul><ul><li>You can use apachectl to start, stop and restart the Apache server – very simple to use: </li></ul><ul><ul><li>cd /home/<username>/apache/bin/ </li></ul></ul><ul><ul><li>./apachectl {start|stop|restart} </li></ul></ul>
  25. 25. Apache Configuration Files <ul><li>Configuration files are placed in the conf/ directory and include: </li></ul><ul><ul><li>httpd.conf – master configuration file </li></ul></ul><ul><ul><li>access.conf and srm.conf – no longer used </li></ul></ul><ul><li>Since version 1.3.4, all you configuration is done in the httpd.conf file – the srm.conf and access.conf files are no longer needed. </li></ul><ul><li>Apache needs to know location of httpd.conf file to start. If httpd.conf needs to move after initial install need to specify location with –f option when starting server. </li></ul><ul><ul><li>httpd –f /path/to/httpd/.conf </li></ul></ul>
  26. 26. httpd.conf: IP address and Port <ul><li>The BindAddress and Port directives in the httpd.conf tell Apache which IP addresses and ports to listen on. Usage: </li></ul><ul><li>Tells Apache to use the default IP address for this system: </li></ul><ul><ul><li>BindAddress * </li></ul></ul><ul><li>Tells Apache to “listen” for web requests on Port 80: </li></ul><ul><ul><li>Port 80 </li></ul></ul>
  27. 27. Tell Apache to Listen To Additional Ports and IP addresses <ul><li>The Listen directive in the httpd.conf tells Apache to listen to additional Ports and/or Port/IP address combinations. </li></ul><ul><li>Usage: </li></ul><ul><ul><li>Listen <Port Number> or </li></ul></ul><ul><ul><li>Listen <IP>:<Port Number> </li></ul></ul><ul><li>These IP/Ports are used in addition to the IP and Port specified in the BindAddress and Port directive described earlier. </li></ul>
  28. 28. httpd.conf: Basic Configuration Directives <ul><li>ServerName blender.rutgers.edu – The name of this server we use to respond to web clients with. If the server does not have a real internet name, use the IP address instead. </li></ul><ul><li>ServerType standalone - We always set this to standalone. </li></ul>
  29. 29. httpd.conf: Basic Configuration Directives <ul><li>User nobody, Group nobody - For security reasons, we usually run Apache assumes the identity of a non-root user and group on the system. A lot of times we run Apache as the nobody user/group. </li></ul><ul><li>ServerAdmin itiXXX@blender.rutgers.edu - A contact address to report problems – returned to the web client when an error occurs. </li></ul>
  30. 30. httpd.conf: Basic Configuration <ul><li>ServerRoot /home/<username>/apache - Where Apache keeps all its essential files. </li></ul><ul><li>DocumentRoot /usr/local/apache/htdocs - Where the actual Web pages reside. </li></ul><ul><li>ErrorLog /home/<username>/apache/logs/error_log – The location of the Apache error log </li></ul><ul><li>PidFile /home/<username>/apache/logs/httpd.pid -Process id for the Apache parent process. Used with the kill command to stop Apache. </li></ul>
  31. 31. httpd.conf: Virtual Directories <ul><li>Sometime you want to create a Virtual Directory , where a document directory may not exist under your htdocs directory, but you want web clients to have access to it. </li></ul><ul><li>This is configured using the Alias directive in the httpd.conf, usage: </li></ul><ul><ul><li>Alias <virtualdirectory> <real directory> </li></ul></ul>
  32. 32. Virtual Directories, con’t. <ul><li>For example, if your Document Root is the default htdocs directory and you want web client to access a directory that contains Icons (/home/<username>/apache/icons), you can create a Virtual Virtual Directory called myicons like this: </li></ul><ul><ul><li>Alias /myicons /home/<username>/apache/icons </li></ul></ul><ul><li>Now web clients can access this virtual directory by going to http:// blender.rutgers.edu:XXXX/myicons to view the files in the icons directory. </li></ul>
  33. 33. httpd.conf: Redirects <ul><li>The Redirect directive allows web clients to access a URL on your system and be re-directed to a remote URL somewhere else. </li></ul><ul><li>Usage: </li></ul><ul><li>Redirect /localpath http://remote-url </li></ul><ul><li>Example: </li></ul><ul><li>Redirect /photos http://members.yahoo.com/user/photos </li></ul><ul><li>Redirects all request to http://yoursite.com/photos to http://members.yahoo.com/user/photos </li></ul><ul><li>Useful when you move portions of a webpage </li></ul>
  34. 34. Giving Web Access to Users on the System <ul><li>Individual users on your system may wan the ability to post web content. </li></ul><ul><li>The UserDir Apache directive, allows each user on the system to create an special directory used to contain web content. </li></ul><ul><li>Usage: UserDir public_html </li></ul><ul><li>Now system users can place all of their web documents in a directory called public_html under their home directory. These documents can be accessed via the URL http://systemname/~username. </li></ul>
  35. 35. Access Control Files <ul><li>Per directory configuration files can be used to supplement or override settings set on the server level. Most commonly used to password-protect a directory. </li></ul><ul><li>Allows for “on-the-fly” changes. No need to restart the server. </li></ul><ul><li>Generally referred to as .htaccess files even though the actual name of the file can be set in httpd.conf: AccessFileName .htaccess </li></ul>
  36. 36. Access Control Files, con’t. <ul><li>Level of overrides allowed should also be set in httpd.conf: </li></ul><ul><li>AllowOverride None|All|Options|Indexes| FileInfo|AuthConfig|Limit </li></ul><ul><li>Default is “All”. </li></ul><ul><li>Access control file is placed in root of directory for which configuration is being modified. </li></ul>
  37. 37. Access Restrictions by Location <ul><li>Access to directory contents can be granted or denied by IP address, network, hostname or name. </li></ul><ul><li><Directory /home/apache/apache/htdocs/restricted> </li></ul><ul><li>order deny,allow deny from all allow from 165.230.30.68 .rutgers.edu internet.rutgers.edu </li></ul><ul><li></Directory> </li></ul><ul><li>Best to control access by IP address rather than hostname to avoid require DNS lookups for every attempted connection. </li></ul><ul><li>You can place these blocks access control blocks in the httpd.conf file or in an .htaccess file. </li></ul>
  38. 38. The Index File <ul><li>When a web browser points to a directory, rather than a particular file (e.g. http://www.internet.rutgers.edu/II/ITI520 vs. http://www.internet.rutgers.edu/II/ITI520/index.html ), Apache looks for an index file , which is the default web page for a particular directory. </li></ul><ul><li>You can specify the name of acceptable index files by using the DirectoryIndex directive in the httpd.conf file. </li></ul><ul><li>Usage: DirectoryIndex filename filename… </li></ul><ul><li>Apache will look for the index file names specified when a request is made to a directory. </li></ul>
  39. 39. Indexing <ul><li>What happens if you type a URL into a browser that points to a directory rather than a specific file? </li></ul><ul><ul><li>Will load the index file if directory includes any of the files specified with DirectoryIndex in httpd.conf: DirectoryIndex index.html index.htm </li></ul></ul><ul><li>If no index file exists and indexing has been enabled, will get a directory listing. </li></ul><ul><li>If no index file exists and indexing has been disabled, will get an error message. </li></ul><ul><li>Advisable to leave indexing disabled for security reasons unless there is a specific need for it. </li></ul>
  40. 40. Indexing, con’t. <ul><li>To enable indexing in httpd.conf: </li></ul><ul><ul><li>Options Indexes </li></ul></ul><ul><li>Fancy indexing generates listing that includes representative icon, name, last modified, size, and description: </li></ul><ul><ul><li>IndexOptions FancyIndexing </li></ul></ul><ul><li>Indexing requires module mod_autoindex, which is installed by default. </li></ul>

×