Linux-palvelimet ICT4TN021-7 linux server course assignment 3

This assignment is part of linux server course ICT4TN021-7, undertaken at Haaga-Helia UAS.

 

A) Install Apache, get user’s homepages (http://example.com/~tero) working. Test with example home page.

I installed apache via terminal:

sudo apt-get install apache2

I enabled userdir for user homepages:

sudo a2enmod userdir

I restarted apache2:

systemctl restart apache2

I created a directory for user homepage (in home directory):

mkdir public_html

I checked my username:

whoami

Then i entered “http://localhost/~xubuntu/” in Firefox.

Screenshot_2018-02-05_00-56-40.png

I was greeted by this screen.

Next, i created a sample home page. I moved to “public_html” directory.

cd public_html

I created an html file with nano:

nano index.html

Screenshot_2018-02-05_01-05-55

I wrote a simple html page, then pressed ctrl+x to exit and y to save.

Screenshot_2018-02-05_01-07-39

http://localhost/~xubuntu/” now looked like this after i refreshed the page.

 

B) Surf on the webpages of your own server. Find examples for successful (200 ok) and unsuccessful (for example 404 not found) page loads from Apache logs. Analyze lines.

I wiewed 2 latest log entries from apache:

sudo tail -2 /var/log/apache2/access.log

Screenshot_2018-02-05_01-23-23.png

127.0.0.1 – – [05/Feb/2018:01:20:20 +0000] “GET /~ubuntu/ HTTP/1.1” 404 498 “-” “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0”

The first entry tells IP address of the sender of http request, date and time, the http request in which user home page of user “ubuntu” is being accessed, 404 (not found) because user “ubuntu” does not exist. The software of http request sender is listed in the end (browser, operating system, kernel, processor architecture, browser engine, browser version.).

127.0.0.1 – – [05/Feb/2018:01:20:28 +0000] “GET /~xubuntu/ HTTP/1.1” 200 452 “-” “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0”

Second entry lists the same except now homepage being accessed is one of user “xubuntu” and as this user homepage exists, it is loaded and “200” displayed as an indication of a successful request, instead of “404”.

 

C) Make an error in code that is being run on the web server (for example PHP or python)

I installed PHP:

sudo apt-get install libapache2-mod-php

I allowed PHP:

sudoedit /etc/apache2/mods-available/php7.1.conf

Screenshot_2018-02-05_01-50-58

I commented out all the lines above.

I restarted apache2:

systemctl restart apache2

I created file index.php in public_html:

xubuntu@xubuntu:~/public_html$ nano /home/xubuntu/public_html/index.php

I wrote “<?php printt 4; ?>” with an intentional typo. I entered “http://localhost/~xubuntu/index.php&#8221; in Firefox’s search field, and received a blank page. I looked at last log entry:

tail -1 /var/log/apache2/error.log

I received:

[Mon Feb 05 02:21:30.039883 2018] [php7:emerg] [pid 11141] [client 127.0.0.1:56102] PHP Parse error: syntax error, unexpected ‘4’ (T_LNUMBER) in /home/xubuntu/public_html/index.php on line 1

It lists date and time, php version, process id, client ip, error type and error location in code.

 

D) Make a mistake in some of Apache’s configuration files. Find and analyze that line. Suitable in looking for it are for example Apache’s own logs, syslog and ‘apache2ctl configtest’.

I found information about apache config file locations here.

I commented out several lines in apache2.conf:

#User ${APACHE_RUN_USER}
#Group ${APACHE_RUN_GROUP}

#HostnameLookups Off

#IncludeOptional mods-enabled/*.load
#IncludeOptional mods-enabled/*.conf

I saved and restarted apache2:

systemctl restart apache2

My homepage would not load anymore. I looked at syslog:

sudo tail -5 /var/log/syslog

Feb 5 02:52:14 xubuntu systemd[1]: Failed to start The Apache HTTP Server.
Feb 5 02:52:14 xubuntu systemd[1]: apache2.service: Unit entered failed state.
Feb 5 02:52:14 xubuntu systemd[1]: apache2.service: Failed with result ‘exit-code’.
Feb 5 02:54:27 xubuntu wpa_supplicant[1702]: wlp36s0: WPA: Group rekeying completed with e4:18:6b:32:21:09 [GTK=CCMP]

Log entries tell that Apache failed to start.

 

I) How many different HTTP Statuses can you cause to logs? Explain, how you got them and analyze one line per one status.

127.0.0.1 – – [05/Feb/2018:01:20:20 +0000] “GET /~ubuntu/ HTTP/1.1” 404 498 “-” “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0”

I got this when trying to access a page that doesn’t exist, analyzed in B).

127.0.0.1 – – [05/Feb/2018:01:20:28 +0000] “GET /~xubuntu/ HTTP/1.1” 200 452 “-” “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0”

This is a successful page load, analyzed in B).

I tried to cause a status 403 by adding following lines to apache2.conf:

<RequireAll>
Require all denied
Require not ip 10.252.46.165
</RequireAll>

By adding these, i was not able to access my homepage anymore, but attempts to access it didn’t cause any new log entries in /var/log/apache2/access.log.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s