Lab 9a - Basic Web Server Configuration

Aims

1. To configure a Linux machine to act as a web server using Apache

Task 1: Verify installation and start the web server

Task 1 Specification and Explantions

The Apache web server should be installed, but it is probably not running. Check the status with: systemctl status httpd

Also check that mod_ssl is installed (we need this for the next lab): rpm -qa | grep mod_ssl

If either of them are not installed, use dnf to install as previously.

Verify installation packages for web server – mod_ssl and httpd

Linux# systemctl status httpd //to check the status of httpd if running or not//

Linux# rpm -qa | grep mod_ssl

Check to see what files were installed (hint: rpm –qs httpd and rpm -qs httpd-filesystem). The main web pages are installed in /var/www and the configuration files are in /etc/httpd.

# rpm -qs httpd

# rpm -qs httpd-filesystem

# ls /var/www

//list the www directory//

# ls /etc/httpd

Use systemctl to start your httpd daemon now, and also use systemctl to enable your httpd daemon at boot time.

# systemctl start httpd

// to start httpd daemon//

# systemctl enable httpd

//to start httpd when the system reboot//

Test the server by opening Firefox and trying http://localhost You should see the default Apache startup page.

Open a browser (Firefox)

On the search bar type: localhost


Task 2: Basic web server functionality

Explanation and Requirements


First, make sure your DNS is working for your domain (e.g. it.netserv.edu.au). If you didn’t previously, you may also like to add an entry to the DNS for www.it.netserv.edu.au whose IP address is that of your virtual machine. As noted in previous labs, make sure that there in consistency in what IP address appears in your zone file, and the IP address currently on Ethernet interface ens37. Also, make sure that the top “nameserver” line in the /etc/resolv.conf points to your nameserver. If your DNS needs fixing, refer to the earlier DNS lab. You need DNS working for the web server configuration below.

Edit the /etc/httpd/conf/httpd.conf file. To start with, you should modify ServerName, and note down the DocumentRoot directory. DocumentRoot is where the HTML documents for your web site should be placed. Restart your web server: systemctl restart httpd

You can test your web server by using the http://www.it.netserv.edu.au (or whatever you set up) in the browser.

You can create a file named index.html in your DocumentRoot directory. By default your DocumentRoot is

/var/www/html, unless you changed it when you edited the httpd.conf file.

Common problems:

When you attempt to start/restart the httpd daemon, if you get a message about unable to bind to port 80, this is probably because you need to be root to start the web server!

Cannot view my index.html? eg: 404 error or 403 error? Check that the file exists in the correct DocumentRoot and/or the file has public read permission and directory has have public read/execute permissions.

Try executing ps -ef | grep httpd. Note that the web service runs under the userid apache. Hence all files in the /var/www directory need to be able to be read by userid apache.

Getting a FAILED error on startup, or an error 500 from the browser. This is usually a configuration error. Use apachectl –t to check your config.

Task 2 – Steps:

Lets check the current setting for dns server first

# systemctl is-active named

//should display active which means our dns server is running//

# dig @localhost www.it.netserv.edu.au

Check the dns resolve

# cat /etc/resolv.conf

Make modification to ens37 config file

# vim /etc/sysconfig/network-scripts/ifcfg-ens37

IPADDR=10.0.2.3

DNS1=10.0.2.3

DOMAIN=it.netserv.edu.au

IPV4_DNS_PRIORITY=5

:wq


Restart the en337

# nmcli con reload ens37

# nmcli con up ens37

Verify

# ifconfig ens37

# cat /etc/resolve.conf

Dig the local host

# dig www.it.netserv.edu.au

// check the answer section if it’s not zero then means everyting is find//

# ping www.it.netserv.edu.au

// should be successful//

Our dns setting is correctly configured verified.

Next we Go to httpd server setting to change ServerName and DocumentRoot:

# vim /etc/httpd/conf/httpd.conf

ServerName www.it.netserv.edu.au:80

DocumentRoot “/var/www/html”

//DocumentRoot is the location where the index are saved//

:wq

Next create index file the DocumentRoot directory.

# cd /var/www/html/

# touch index.html

Write something inside the index.html file

# vim index.html

This is a test page for www.it.netserv.edu.au

:wq

Next Go to the browser

On search bar type: locathost or www.it.netserv.edu.au

Should display index.html file contents.