Linux Operations and Administration Chapter Ten Apache Web

Linux Operations and Administration Chapter Ten Apache Web Server

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 Linux Operations and Administration 2

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 Linux Operations and Administration 3

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 Linux Operations and Administration 4

Installing Apache Web Server (cont’d. ) • Apache version 2. 2 – Included with open. SUSE – Not installed by default – Configured to run “out of the box” with no further modifications needed Linux Operations and Administration 5

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 Linux Operations and Administration 6

Installing Apache Web Server (cont’d. ) • Options to install Apache Web Server – yast command – Ya. ST Software Management module • Activity 10 -1: Installing Apache Web Server – Install Apache Web Server and other Web-related packages Linux Operations and Administration 7

Starting and Stopping Apache • To start apache 2 service using Ya. ST: – Open Ya. ST – Select System Services (Runlevel) – Search for apache 2 and enable the service Linux Operations and Administration 8

Starting and Stopping Apache (cont’d. ) • To start apache 2 service at the command line: – rcapache 2 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 apache 2 service • Table 10 -1 – Describes common options used with rcapache 2 command Linux Operations and Administration 9

Starting and Stopping Apache (cont’d. ) Table 10 -1 Common options used with rcapache 2 Linux Operations and Administration 10

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 Apache. Web Server – Check the status of an Apache Web server, stop and start the apache 2 service, and test an Apache. Web server at the command line and with a GUI tool Linux Operations and Administration 11

Starting and Stopping Apache (cont’d. ) Figure 10 -1 The Apache test page © Cengage Learning 2013 Linux Operations and Administration 12

Configuring Apache Web Server • Methods to configure Apache Web server – Use the graphical Ya. ST module (yast 2 -httpserver) • 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 Linux Operations and Administration 13

Apache Configuration with HTTPServer • HTTP-Server – A Ya. ST module for configuring Apache – Package name: yast 2 -http-server – Can be installed from Ya. ST Software Management • To begin the Apache configuration process in HTTP -Server: – Use yast 2 http-server command Linux Operations and Administration 14

Apache Configuration with HTTPServer (cont’d. ) Figure 10 -2 The HTTP Server Wizard © Cengage Learning 2013 Linux Operations and Administration 15

Apache Configuration with HTTPServer (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 Linux Operations and Administration 16

Apache Configuration with HTTPServer (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 Linux Operations and Administration 17

Apache Configuration with HTTPServer (cont’d. ) Figure 10 -3 Configuring the default host © Cengage Learning 2013 Linux Operations and Administration 18

Apache Configuration with HTTPServer (cont’d. ) • You can set the following for a Web server in Apache: – – – Document. Root Alias Script. Alias Include Server Name Server Administrator E-Mail Linux Operations and Administration 19

Apache Configuration with HTTPServer (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 Linux Operations and Administration 20

Apache Configuration with HTTPServer (cont’d. ) Figure 10 -4 Expert mode in the HTTP Server Wizard © Cengage Learning 2013 Linux Operations and Administration 21

Manual Apache Configuration • Can configure an Apache Web server manually – Edit configuration files in /etc/apache 2/ 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 Linux Operations and Administration 22

Manual Apache Configuration (cont’d. ) Table 10 -2 Apache configuration files Linux Operations and Administration 23

Manual Apache Configuration (cont’d. ) • apache 2 ctl -t command – Verifies that configuration files have no syntax errors • Activity 10 -4: Using Apache Configuration Files – Explore common Apache configuration files Linux Operations and Administration 24

Manual Apache Configuration (cont’d. ) Figure 10 -5 Contents of an Apache configuration file © Cengage Learning 2013 Linux Operations and Administration 25

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 Linux Operations and Administration 26

Name-Based Virtual Hosts • Ways to create name-based virtual hosts: – Editing httpd. conf file – Virtual host configuration files • Name. Virtual. Host directive – Specifies the IP address to use for name-based virtual hosts Linux Operations and Administration 27

Name-Based Virtual Hosts (cont’d. ) • An httpd. conf file that has been modified to support two virtual hosts: Linux Operations and Administration 28

Name-Based Virtual Hosts (cont’d. ) • Server. Name 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 Linux Operations and Administration 29

Name-Based Virtual Hosts (cont’d. ) • Server. Alias 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 Linux Operations and Administration 30

Name-Based Virtual Hosts (cont’d. ) • Another way to create virtual hosts is to create a virtual host configuration file in /etc/apache 2/vhosts. d directory • Virtual host template (vhost. template) – You can copy it and rename • A virtual host configuration file must have a. conf extension Linux Operations and Administration 31

Name-Based Virtual Hosts (cont’d. ) • Server. Admin directive – Lists the Apache administrator’s e-mail account • The only directives you must change: – Server. Name directive – Document. Root 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 Linux Operations and Administration 32

Name-Based Virtual Hosts (cont’d. ) • After creating a virtual host configuration file, define Name. Virtual. Host directive in /etc/apache 2/listen. conf file • Activity 10 -5: Creating Virtual Hosts – Use a template to create virtual Apache Web servers Linux Operations and Administration 33

Name-Based Virtual Hosts (cont’d. ) Figure 10 -7 Defining the Name. Virtual. Host directive in the listen. conf file © Cengage Learning 2013 Linux Operations and Administration 34

Creating a Web Page • Document. Root 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><h 1>It works!</h 1></body></html> Linux Operations and Administration 35

Creating a Web Page (cont’d. ) Figure 10 -8 A URL requesting a directory © Cengage Learning 2013 Linux Operations and Administration 36

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 Linux Operations and Administration 37

Creating a Web Page (cont’d. ) Figure 10 -9 Placing HTML tags on separate lines © Cengage Learning 2013 Linux Operations and Administration 38

Creating a Web Page (cont’d. ) Table 10 -3 Common HTML tags Linux Operations and Administration 39

Creating a Web Page (cont’d. ) • To create a Web page in open. SUSE Linux: – You must use a text editor • Activity 10 -6: Creating Web Pages with HTML – Create a basic HTML Web page Linux Operations and Administration 40

Summary • Apache Web Server – Web server software that can be downloaded free – Available with the latest version of open. SUSE • rcapache 2 command can be used to: – Check status of Apache Web server – Start, stop, and restart the server • HTTP-Server is a Ya. ST application module for configuring Apache • Manual Apache configuration: modifying directives (instructions) in Apache configuration files Linux Operations and Administration 41

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 Document. Root, Directory, and Server. Name Linux Operations and Administration 42
- Slides: 42