Web Server using Apache - Heng Sovannarith · •Apache HTTP Server is an open-source HTTP server...

17
Web Server using Apache Heng Sovannarith [email protected]

Transcript of Web Server using Apache - Heng Sovannarith · •Apache HTTP Server is an open-source HTTP server...

Web Server using Apache

Heng Sovannarith

[email protected]

Introduction

• The term web server can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver web content that can be accessed through the Internet.

• The most common use of web servers is to host websites, but there are other uses such as gaming, data storage or running enterprise applications

Introduction (cont.)

• Apache HTTP Server is an open-source HTTP server for modern operating systems including UNIX and Windows NT.

• "Apache" is the name of a foundation that write open-source software. Apache HTTPD is a web server written in portable C (when people say "Apache", they usually mean Apache HTTPD.)

• It serve either also serve static and dynamic content written in Perl, PHP, Python, Ruby, or other languages.

Installation

• Install Apache HTTP Server

#yum install httpd

• Note: This is typically installed with CentOS by default

• Set the apache service to start on boot#chkconfig --levels 235 httpd on

Installation (cont.)

• Enable name-based virtual hosting on port 801. Open the httpd configuration file located at

/etc/httpd/conf/httpd.conf

2. Un-comment the line containing the text

NameVirtualHost *:80

3. Save the file

4. Restart the Apache HTTP Server daemonservice httpd restartNote: Ignore the "NameVirtualHost *:80 has no VirtualHosts" warning for now.

Installation (cont.)

• Visit localhost in your web browser. You should see an Apache Test Page.

Configuration file

• Apache's default document root is /var/www/html on CentOS,

• and the configuration file is /etc/httpd/conf/httpd.conf.

Virtual Host

• Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers).

• This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name.

• There are two main types of virtual hosting, name-based and IP-based (and Port-based).

Set Up Apache Virtual Hosts

• Create a New Directory

#mkdir -p /var/www/example.com/public_html

• Grant Permissions#chown -R root.apache /var/www/example.com/public_html

#chmod 755 /var/www

Create the Page

• We need to create a new file called index.html within our configurations directory.

#vi /var/www/example.com/public_html/index.html

• We can add some text to the file.<html>

<head>

<title>www.example.com</title>

</head>

<body>

<h1>Success: You Have Set Up a Virtual Host</h1>

</body>

</html>

Turn on Virtual Hosts

• The next step is to enter into the apache configuration file itself.

#vi /etc/httpd/conf/httpd.conf

• Make sure that your text matches what you see below.

Turn on Virtual Hosts (cont.)

• Scroll down to the very bottom of the document to the section called Virtual Hosts.

Turn on Virtual Hosts (cont.)

• Configuration:

– Document Root : location of webpages

– Server Name is another important piece of information, containing the virtual host’s domain name (eg. www.example.com).

– ServerAlias is a new line in the config file that is not there by default. Adding it will allow you to list a few variants of the domain name, for example without the www in the front.

Turn on Virtual Hosts (cont.)

– Server admin asks for the webmaster’s email.

– The Error Logs and Custom Logs keep track of any issues with the server. The error log covers issues that arise while maintaining the server, and the custom log tracks server requests.

• Restart the Apache Service

#service httpd restart

Adding More Virtual Hosts (cont.)

• To create additional virtual hosts, you can just repeat the process above, being careful to set up a new document root with the appropriate new domain name each time.

Adding More Virtual Hosts

How to install PHP

• PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

• Run the yum install command

#yum install php

Configuration file of php is in /etc/php.ini