Post on 24-Dec-2015
Linux Operations and Administration
Chapter TenApache Web Server
Linux Operations and Administration
Objectives
• Install Apache Web Server along with additional Apache modules
• Configure an Apache Web server with a GUI utility and by modifying Apache configuration files
• Create a Web page by writing an HTML script
2
Linux Operations and Administration
Installing Apache Web Server
• Web server– A network computer with the primary role of serving
Web pages to clients on request– Can also host a Web site along with images, style
sheets, and other content• Clients (Web browsers) can access the Web pages
– Receives data from clients
3
Linux Operations and Administration
Installing Apache Web Server (cont’d.)
• Apache Web Server– Open-source– Free– Developed by Apache Software Foundation (ASF)– Designed to run on a wide variety of operating
systems
4
Linux Operations and Administration
Installing Apache Web Server (cont’d.)
• Apache version 2.2– Included with openSUSE– Not installed by default– Configured to run “out of the box” with no further
modifications needed
5
Linux Operations and Administration
Installing Apache Web Server (cont’d.)
• Apache software is mostly modular
• PHP module– A poplar module– PHP
• A server-side scripting language
• Commonly used to create dynamic Web pages
6
Linux Operations and Administration
Installing Apache Web Server (cont’d.)
• Options to install Apache Web Server– yast command– YaST Software Management module
• Activity 10-1: Installing Apache Web Server– Install Apache Web Server and other Web-related
packages
7
Linux Operations and Administration
Starting and Stopping Apache
• To start apache2 service using YaST:– Open YaST– Select System Services (Runlevel)– Search for apache2 and enable the service
8
Linux Operations and Administration
Starting and Stopping Apache (cont’d.)
• To start apache2 service at the command line:– rcapache2 command
• Can be used only by the root user
• Is a link to a startup script in /etc/init.d directory
• Used to start, stop, and restart apache2 service
• Table 10-1– Describes common options used with rcapache2
command
9
Linux Operations and Administration
Starting and Stopping Apache (cont’d.)
10
Table 10-1 Common options used with rcapache2
Linux Operations and Administration
Starting and Stopping Apache (cont’d.)
• To test an Apache Web server:– Start Firefox– Enter http://localhost in address bar
• Activity 10-2: Starting and Testing an ApacheWeb Server– Check the status of an Apache Web server, stop and
start the apache2 service, and test an ApacheWeb server at the command line and with a GUI tool
11
Linux Operations and Administration
Starting and Stopping Apache (cont’d.)
12
Figure 10-1 The Apache test page© Cengage Learning 2013
Linux Operations and Administration
Configuring Apache Web Server
• Methods to configure Apache Web server– Use the graphical YaST module (yast2-http-server)
• Advantages: convenient and easy to use
– Modify Apache configuration files• httpd.conf
– Main configuration file
– Contains directives (instructions that tell Apache how to run)
• Advantage: can make more detailed changes
13
Linux Operations and Administration
Apache Configuration with HTTP-Server
• HTTP-Server– A YaST module for configuring Apache– Package name: yast2-http-server– Can be installed from YaST Software Management
• To begin the Apache configuration process in HTTP-Server:– Use yast2 http-server command
14
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
15
Figure 10-2 The HTTP Server Wizard© Cengage Learning 2013
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
• HTTP Server Wizard– Five steps– Can choose network interface and ports that Apache
listens on• Port
– An interface for connecting a hardware device, such as a disk drive or printer
– In networking, it’s a data connection established for communication between hosts
– Port number identifies the type of function assigned to it
16
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
• HTTP Server Wizard allows you to enable scripting languages– Such as PHP and Perl
• Web server’s default host– First declared virtual host in the configuration file
• Virtual host– Makes it possible to run multiple domains on one
physical machine
• You can add virtual hosts as needed with HTTP Server Wizard
17
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
18
Figure 10-3 Configuring the default host© Cengage Learning 2013
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
• You can set the following for a Web server in Apache:– DocumentRoot– Alias– ScriptAlias– Include– Server Name– Server Administrator E-Mail
19
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
• Activity 10-3: Using the HTTP Server Wizard– Configure an Apache Web server with the HTTP
Server Wizard
• Expert mode– Enables you to adjust more settings than in the
wizard
20
Linux Operations and Administration
Apache Configuration with HTTP-Server (cont’d.)
21
Figure 10-4 Expert mode in the HTTP Server Wizard© Cengage Learning 2013
Linux Operations and Administration
Manual Apache Configuration
• Can configure an Apache Web server manually– Edit configuration files in /etc/apache2/ directory
• Table 10-2– Describes common configuration files stored in this
directory
• Apache configuration files follow the syntax:– One directive per line– # symbols indicate comments
22
Linux Operations and Administration
Manual Apache Configuration (cont’d.)
23
Table 10-2 Apache configuration files
Linux Operations and Administration
Manual Apache Configuration (cont’d.)
• apache2ctl -t command– Verifies that configuration files have no syntax errors
• Activity 10-4: Using Apache Configuration Files– Explore common Apache configuration files
24
Linux Operations and Administration
Manual Apache Configuration (cont’d.)
25
Figure 10-5 Contents of an Apache configuration file© Cengage Learning 2013
Linux Operations and Administration
Virtual Hosts
• Virtual hosts can be used to support multiple Web sites on one physical server
• By default, Apache is configured with a default host and no virtual host
• Apache supports:– Name-based virtual hosts
• Multiple Web sites share the same IP address
– IP-based virtual hosts• Multiple IP addresses for a single machine
26
Linux Operations and Administration
Name-Based Virtual Hosts
• Ways to create name-based virtual hosts:– Editing httpd.conf file– Virtual host configuration files
• NameVirtualHost directive– Specifies the IP address to use for name-based
virtual hosts
27
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
• An httpd.conf file that has been modified to support two virtual hosts:
28
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
• ServerName directive– Specifies name of the server– Apache uses it to determine which virtual host is
displayed
• All virtual hosts you create must have their server name resolved on the network
29
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
• ServerAlias directive– Can be used to define multiple names for a virtual
host
• Order, Allow, and Deny directives– Enable you to define which hosts can access files in
a particular directory and which hosts can’t– Order directive
• Tells Apache which filter (allow or deny) should be run first
30
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
• Another way to create virtual hosts is to create a virtual host configuration file in /etc/apache2/vhosts.d directory
• Virtual host template (vhost.template)– You can copy it and rename
• A virtual host configuration file must have a .conf extension
31
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
• ServerAdmin directive– Lists the Apache administrator’s e-mail account
• The only directives you must change:– ServerName directive– DocumentRoot directive
• Defines the directory path Apache uses to serve files for this host
– Directory directive• Applies only to the named file system directory and
subdirectories and their contents
32
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
• After creating a virtual host configuration file, define NameVirtualHost directive in /etc/apache2/listen.conf file
• Activity 10-5: Creating Virtual Hosts– Use a template to create virtual Apache Web servers
33
Linux Operations and Administration
Name-Based Virtual Hosts (cont’d.)
34
Figure 10-7 Defining the NameVirtualHost directive in the listen.conf file© Cengage Learning 2013
Linux Operations and Administration
Creating a Web Page
• DocumentRoot directive– Defines the directory Apache uses to serve Web
pages to clients
• Uniform Resource Locator (URL)– An address to a resource on the Internet
• index.html file– Main Web page – Default content in HTML markup:<html><body><h1>It works!</h1></body></html>
35
Linux Operations and Administration
Creating a Web Page (cont’d.)
36
Figure 10-8 A URL requesting a directory© Cengage Learning 2013
Linux Operations and Administration
Creating a Web Page (cont’d.)
• Hypertext Markup Language (HTML)– Hypertext
• Contains references or links to access other files or text
– Markup language• Consists of instructions called tags that define how
text is displayed
37
Linux Operations and Administration
Creating a Web Page (cont’d.)
38
Figure 10-9 Placing HTML tags on separate lines© Cengage Learning 2013
Linux Operations and Administration
Creating a Web Page (cont’d.)
39
Table 10-3 Common HTML tags
Linux Operations and Administration
Creating a Web Page (cont’d.)
• To create a Web page in openSUSE Linux:– You must use a text editor
• Activity 10-6: Creating Web Pages with HTML– Create a basic HTML Web page
40
Linux Operations and Administration
Summary
• Apache Web Server– Web server software that can be downloaded free– Available with the latest version of openSUSE
• rcapache2 command can be used to:– Check status of Apache Web server– Start, stop, and restart the server
• HTTP-Server is a YaST application module for configuring Apache
• Manual Apache configuration: modifying directives (instructions) in Apache configuration files
41
Linux Operations and Administration
Summary (cont’d.)
• With virtual hosts in Apache Web Server, you can run multiple Web sites on one physical machine
• Apache Web Server supports two types of virtual hosts:– Name-based virtual hosts– IP-based virtual hosts
• A number of directives can be configured on an Apache Web server– Includes the mandatory DocumentRoot, Directory,
and ServerName
42