G.PULLAIAH COLLEGE OF ENGINEERING & TECHNOLOGY KURNOOL.
SUB: WEB TECHNOLOGIES (R09)
Introduction to web servers:
What is web?
A collection of cross-linked “websites” which uses URI.
The consistent use of URIs to represent resources.
HTTP, HTML, and everything built around them(web)
Which provides to invoke the data across universally over the net
What is server?
A server is a computer or device on a network that manages network resources.
Most servers are dedicated. This means that they perform only one task rather than multiple tasks on multiprocessing operating systems, however, a single computer can execute several programs at once
What is web server?
A Web server is a program that generates and transmits responses to client requests for Web resources.
Handling a client request consists of several key steps:
Parsing the request message
Checking that the request is authorized
Associating the URL in the request with a file name
Constructing the response message
Transmitting the response message to the requesting client
The server can generate the response message in a variety of ways:
The server simply retrieves the file associated with the URL and returns the contents to the client.
The server may invoke a script that communicates with other servers or a back-end database to construct the response message.
Web Site versus Web Server?
Web site and Web server are different:
A Web site consists of a collection of Web pages associated with a particular hostname.
A Web server is a program to satisfy client requests for Web resources.
Types Of Web Servers:
1. Apache Web Server
- IIS Server
- Xampp Server
- WAMP Server
Apache Web Server:
Apache Web server is the most commonly used http server today. About 80% of all websites and Intranets use Apache web server to deliver their content to requesting Browsers.
Server side programming languages such as PHP, Perl, Python, Java and many others
The name "Apache" derives from the word "patchy" that the Apache developers used to describe early versions of their software.
The Apache Web server provides a full range of Web server features, including CGI, SSL, and virtual domains. Apache also supports plug-in modules for extensibility. Apache is reliable, free, and relatively easy to configure.
Apache is free software distributed by the Apache Software Foundation. The Apache Software Foundation promotes various free and open source advanced Web technologies.
It can be downloaded and used completely free of cost. The first version of Apache web server, based on the NCSA httpd Web server, was developed in 1995.
Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.
The Internet’s Request / Response Way Of Working
Here’s the Internet’s Request / Response paradigm works.
Whenever a Browser makes an http request such as:http://www.google.com/index.html
the following happens:
This is the protocol used for communication between the Browser and the Web server. Since the Browser initiated the communication it has the privilege of setting the communication protocol.
This is a separator that separates the protocol from the URL.
This will be translated into a name:value pair i.e. ip:URL
Download Apache Web Server:
The latest stable build of Apache http server can be downloaded from URLhttp://httpd.apache.org/download.cgi
Downloading the Apache web server
Open a browser window and enter http://www.google.com in the address bar and hit GO.
Installing the Apache web server
I recommend to run the Apache HTTP server as a service. This way it is always running and you don't need to start it manually. If you consider manually start and stop because of security issues, then reconsider and use a firewall, preferable one running on an external device like a router.
The next step allows you to select the install type of the Apache web server. The default (Typical program features) is probably right for your situation, so press Next.
Next, you can select the destination folder of the installation. Unless you prefer to use a different folder for some or all of the software you install, I recommend to use the default setting: C:\Program Files\Apache Group\
Finally, after clicking on the Next button you can start the actual installation by pressing the Install button. A few windows pop up and go automatically, and then a Windows Security Alert window appears asking if you want to keep blocking this (Apache HTTP server) program.
Windows Security Alert for the Apache HTTP server.
The download process of the Apache Web Server setup file is successfully finished.
Testing the Apache HTTP server installation
In order to test your Apache web server installation, open a browser and enter http://localhost/ into the address bar (unless you used a different value then localhost in the Apache server information step). The Test Page for Apache installation should be displayed into your browser.
Part of the Apache HTTP server test page in Mozilla Firefox
Understanding the Apache server folder structure
The bin folder
The bin folder contains amongst other files the server executable: Apache.exe and a program to control the Apache HTTP server when ran as service: ApacheMonitor.exe. Also contained in this folder are htpasswd.exe and htdigest.exe for making parts of your site(s) restricted.
The cgi-bin folder
The cgi-bin folder has one CGI program written in Perl, printenv.pl, which you can use to test if your Perl installation is working in combination with the Apache HTTP server. If you get a "500 Internal Server Error" when you enter
http://localhost/cgi-bin/printenv.pl in the address bar of your browser, you either have Perl not installed, or the configuration of the web server is not right. You might want to check the error.log file in the logs folder in the latter case.
The conf folder
This folder holds the configuration files used by the Apache web server. Of each file used by the server there is a copy which has .default in its name, e.g.
httpd.default.conf. The access.conf and srm.conf files are empty (except for comments) by default, and I recommend to not use those files for configuring the server. The httpd.conf file has already been updated by the installation process. I list some of those modified settings below, including a short description and the line number (which might differ with your version).
- Listen 80 - The port the Apache server is using. If you have already a web server running, for example as part of Microsoft Internet Information Services (IIS), you might want to change the number to something different (line 120).
- ServerAdmin admin@localhost - The email address of the server administrator, which is used on, for example, error pages generated by the server (line 198).
- ServerName localhost:80 - The hostname and port the server uses (line 212).
Some of the other settings are omitted since they will be overridden by the name-based virtual hosting set up discussed below.
This folder contains the default HTML page you see when you visit http://localhost/ with your web browser. Don't start adding your HTML documents and related files to this folder, but read on.
This folder contains the Apache HTTP server documentation, available as http://localhost/manual/. Note that this folder shows up under the document root thanks to the AliasMatch directive in the httpd.conf server configuration file (line 491).
This folder contains (amongst others) the access.log and error.log files. If anything goes wrong, for example the notorious 500 Internal Server Error, make sure that you check the error.log file. With virtual hosting you can give each site its own log file (discussed below), so be sure to check the right file(s).
Setting up virtual Hosting
To make the configuration of virtual hosts as easy as possible I decided to store the configuration settings into a separate file instead of adding those settings to the Apache server configuration file httpd.conf.
Login to the computer with Administrator rights, and create an empty file named
virtual-hosts.conf inside the conf folder of the Apache HTTP server. The default location of this folder after installation is
C:\Program Files\Apache Group\Apache2\conf\.
Note: in an earlier version of this article I stored the virtual hosts file inside a folder with limted user rights which implied that this file has the same rights. Since this file is interpreted by the Apache web server this is a security risk if this limited user account is compromised.
Adding the domains to the hosts file
For each website you want to have running locally you have to think up a domain name with great care. I use the same domain name as the real site with lc. added to the front (hence a subdomain) since I am very sure that this subdomain isn't used on the Internet in my case.
Add each domain name to the hosts file used by Windows XP, which is located in the C:\WINDOWS\system32\drivers\etc folder for a default installation. An example configuration might be (comments on top not included for brevity):
127.0.0.1 lc.johnbokma.com # my personal site
127.0.0.1 lc.castleamber.com # my company's site
Note that everything after the # character is regarded as a comment. You can use this to add useful comments. The IP address, 127.0.0.1, means "this computer" (localhost). If you want to use the web server in a local network, you have to use an IP address that can be contacted by other computers in the network. Also, you either have to modify all hosts files on each and every computer, or set up a name server.
Including the virtual-hosts.conf file
Add the following line to the end of the httpd.conf file in the C:\Program Files\Apache Group\Apache2\conf folder in order to include the virtual-hosts.conf file and make it part of the configuration of the web server:
Since the ServerRoot in the default install is set to the folder that contains the conf folder we can use the short relative notation as given above. Note: where filenames are specified, you must use forward slashes instead of backslashes (e.g.
conf/virtual-hosts.conf instead of
Stopping and starting Apache
After changes have been made to the httpd.conf file and/or the virtual-hosts file, Apache has to be restarted. If you are logged in with Administrator rights the easiest way to do this is by using the Apache monitor which is started when you log in and available via the system tray. Click the right mouse (context menu) button on the red feather icon in the system tray and select the Open Apache Monitor menu entry. You can restart the Apache HTTP server with a single mouse click on the Restart button.
The Apache service monitor.
Note that during installation of the Apache web server a short cut to the Apache service monitor is created in the Startup folder of "All Users" (i.e. C:\Documents and Settings\All Users\Start Menu\Programs\Startup) which is quite useless. Users with limited access rights are not able to control the Apache service but will get the Apache monitor running in their system tray anyway. You might want to move the short cut to the Startup folder of a user with Administrator rights.
Another way to restart Apache is by entering in a command prompt window
NET STOP APACHE2 followed by enter, followed by
NET START APACHE2 to stop and start the Apache service:
NET STOP APACHE2
The Apache2 service is stopping.
The Apache2 service was stopped successfully.
NET START APACHE2
The Apache2 service is starting.
The Apache2 service was started successfully
Creating virtual hosts on Apache 2.2
This tutorial is intended for use only in a local testing environment on Windows. For a production server, please refer to the official documentation on the Apache site.
ü Apache 2.2 adopts a modular approach to its main configuration file,
httpd.conf. Although you can still put everything in the one big file, it's more efficient to use external files, and include only those that you need to implement. Consequently, it's no longer recommended to define virtual hosts at the bottom of
httpd.conf. Instead, you include an external file called
ü The other change is that Apache 2.2 imposes stricter permissions than previous series, so you need to add an extra command to the virtual hosts definition to prevent getting the following message when accessing a virtual host:
You don't have permission to access /index.php on this server.
Because of the permissions issue, I recommend creating a top-level folder to hold all virtual hosts in your local development environment. The following instructions assume that all virtual hosts are located in a folder called
NOTE: Security restrictions on Windows Vista and Windows 7 prevent you from saving edits to the files referred to in these instructions, even if you are logged in as an administrator. To get around this restriction, open Notepad or your script editor from the Start menu by right-clicking the program name and selecting "Run as Administrator" from the context menu. Then open the relevant files by using File > Open inside the program you have just launched. By default, Notepad shows only files with a
.txt file name extension, so you need to select the option to view All Files (*.*) in the Open dialog box. You can then save the files normally after editing them. (If you're using XAMPP, this restriction applies only to steps 2–4.)
1. Create a subfolder inside
C:\vhosts for each virtual host that you want to add to your Apache server.
C:\WINDOWS\system32\drivers\etc\hosts in Notepad or a script editor. Look for the following line at the bottom:
3. On a separate line, enter
127.0.0.1, followed by some space and the name of the virtual host you want to register. For instance, to set up a virtual host called
phpdw, enter the following:
4. Add any further virtual hosts, each one on a separate line and pointing to the same IP address (
127.0.0.1). Save the
hosts file, and close it.
C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.confin a text editor. If you're using XAMPP, the file is located at
C:\xampp\apache\conf\httpd.conf. Scroll down to the Supplemental configuration section at the end, and locate the following section (around line 460):
7. Remove the # from the second line so the section now looks like this:
httpd.conf and close it.
C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf in Notepad or a text editor. If you're using XAMPP, the location is
C:\xampp\apache\conf\extra\httpd-vhosts.conf. The main section looks like this:
Note: In XAMPP, all lines are commented out. You must remove the hash mark from the beginning of the line that contains the following directive:
11. Position your cursor in the blank space shown on line 15 in the preceding screenshot, and insert the following four lines of code:
Allow from all
This sets the correct permissions for the folder that contains the sites you want to treat as virtual hosts. If you chose a location other than
C:\vhosts as the top-level folder, replace the pathname in the first line. The pathname must use forward slashes in place of the Windows convention of backward slashes. Also surround the pathname in quotes if it contains any spaces.
As long as all your virtual hosts are in subfolders of this top-level folder, this directive sets the correct permissions for all of them. However, if they are in different top-level folders, create a separate
<Directory> directive for each one.
15. The code shown on lines 27 through 42 in the preceding screenshot shows examples of how to define virtual hosts (in XAMPP, they're commented out). It shows all the commands that can be used, but only
ServerName are required.
ü When you enable virtual hosting, Apache disables the main server root, so the first definition needs to reproduce the original server root. You then add each new virtual host within a pair of
<VirtualHost> tags, using the location of the site’s web files as the value for
DocumentRoot, and the name of the virtual host for
ServerName. Again, use forward slashes, and if the path contains any spaces, enclose the whole path in quotes. If your server root is located, like mine, at
C:\htdocs, and you are adding
phpdw as a virtual host in
C:\vhosts, change the code shown on lines 27 through 42 so they look like this (in XAMPP, just add these new directives at the bottom of the file, and set the
httpd-vhosts.conf, and restart your computer. All sites in the server root will continue to be accessible through
http://localhost/sitename/. Anything in a virtual host will be accessible through a direct address, such as
17. If you still have difficulty accessing your virtual hosts, make sure that you have added
index.php to the
DirectoryIndex directive in
To create a virtual directory on a machine running Apache Web server software:
Note: The Apache Web server uses the term alias instead of virtual directory.
1. Locate the conf/httpd.conf file in the Apache install directory.
2. Add an entry near the end of the file that looks like this. Be careful that it is not in the middle of some other entry:
Alias /site_name "C:\pathname_to_site\your_site_directory"
Options Indexes FollowSymLinks MultiViews ExecCGI
Allow from all
3. In the entry added in step 2, replace site_name with the alias for your site and replace C:\pathname_to_site\your_site_directory with the actual file path name to your site's root directory. If the server is running on Linux, the format of the path name would be a UNIX path name rather than the Windows-style pathname shown in the example.
4. Restart the Apache server to have the change take effect.
Setting Up a WAMP Server
ü A WAMP Server is a Windows Machine that has Apache, MySQL, and PHP on it (WAMP – Windows, Apache, MySQL, PHP) To install these before you would have to get the installs and binaries and configure them yourself and set everything up which can be a tedious task as well as very time consuming.
ü Now, thanks to sourceforge, you can get this functionality by simply installing an application. Once you are finished with this tutorial you will be able to follow our web-based tutorials without having a domain name and/or server. Let’s get started. First we need to download our software from wampserver.com.
Once on that site look for the above box to appear and click on Download WAMP Server 2.0
Save the file somewhere that you will be able to get to once it is finished completing. It is approximately 20 Megabytes, so depending on your connection; it may take a few minutes.
You should now see this icon wherever you chose to save the file. Double-click on it to start the installation.
Select to run the file if you are prompted to do so.
You will be prompted to not install this version over WAMP5 1.x. Click yes to continue with the installation.
This first install window simply welcomes you to the installer for this application. Click next to continue.
This window contains the GNU GENERAL PUBLIC LICENSE that will allow you to use this software. Once you review this click the I Accepts radial button and click next to continue.
This box let’s you pick where you would like to install all of the files. You can change this if you like but if you do, bear in mind that you should put it in a folder that does not contain any spaces as some browsers/servers have issues handling spaces in file names. This is also where your web files will be stored under a directory called ‘www’. If you are unsure, leave this default.
This window will allow you to create the desktop icon and the quick launch icon to start the server by the click of a button.
This window just reviews all installation options. Verify the settings are correct and click next to start installing the application.
This is installing the software.
You will get the above prompt to configure FireFox as your default browser for the WAMP Server if you would like, otherwise it will use Internet Explorer.
This window will allow you to configure your server to forward any e-mail that your php creates to a proper server and e-mail account so that they will go to the right person once you are using it. If you don’t know these values or have the ability to use them, just leave them default.
This is the completion window. You have the ability to launch the server automatically after closing this window if you would like. Click Finish to start the application.
Once the server is running, you will see the above icon and the taskbar for the WAMP Server.
INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP
About XAMPP and Installation Requirements XAMPP is a small and light Apache distribution containing the most common web development technologies in a single package.
Its contents, small size, and portability make it the ideal tool for students developing and testing applications in PHP and MySQL. XAMPP is available as a free download in two specific packages: full and lite.
While the full package download provides a wide array of development tools, this article will focus on using XAMPP Lite which contains the necessary technologies that meet the Ontario Skills Competition standards. As the name implies, the light version is a small package containing Apache HTTP Server, PHP, MySQL, phpMyAdmin, Openssl, and SQLite. For more details on the packaging and versions
Obtaining and Installing XAMPP
As previously mentioned, XAMPP is a free package available for download and use for various web development tasks.
All XAMPP packages and add-ons are distributed through the Apache Friends website at the address: http://www.apachefriends.org/. Once on the website, navigate and find the Windows version of XAMPP Lite and download the self-extracting ZIP archive.
After downloading the archive, run and extract its contents into the root path of a hard disk or USB drive.
For example, the extract path for a local Windows installation would simply be C:\. If extracted properly you will notice a new xampplite directory in the root of your installation disk. In order to test that everything has been installed correctly, first start the Apache HTTP Server by navigating to the xampplite directory and run the apache_start.bat batch file.