I did this exercise with:
HP Pavilion 15-aw022no
AMD A9-9410 (2.9GHz, 2 Cores)
8GB DDR4-SDRAM 2133MHz (2 x 4)
AMD Radeon R7 M440 (2GB, GDDR3)
Ubuntu 7.2.0 (Live USB)
Instructions for exercises from: http://terokarvinen.com/2017/aikataulu
(EDIT: 12.1.2018 00:58 NOTICED THAT ONLY 4 EXERCISES ON THIS POST CRUD TEST ADDED ON NEXT BLOG POST!!)
a) Install Apache and make users homepage work (http://example.com/~matias) . Test it.
Command setxkbmap fi to enable familiar keyboard configuration.
To install apache I typed command sudo apt-get install apache2. Do you want to continue (y/n), I answered y. To test it I gave command firefox “http://localhost”. It directed me to Apache2 default page.
Apache is working.
Next I created user homepage.
First enabled Userdir on server with command sudo a2enmod userdir. To enable changes, Apache2 server must be restarted with command sudo systemctl restart apache2.service.
Then I created a folder for public html files, mkdir public_html.
To test can I see changes on the web page I checked my username with command whoami.
My username is xubuntu, so I need to visit page localhost/~xubuntu to see the changes.
b) Surf on your web pages and find examples of successful and unsuccessful logs from Apache’s logs. Analyze the logs.
log found from /var/log/apache2 folder with command tail -f access.log
This log was recorded as I visited localhost/~xubuntu with Firefox webbrowser.
127.0.0.1 – – [04/Feb/2018:22:08:47 +0000] “GET /icons/back.gif HTTP/1.1” 304 179 “http://localhost/~xubuntu/” “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0″
127.0.0.1 →IP address of the client
— → These two hyphens indicates that requested information is not avaible.
First hyphen should PROBABLYbe RFC 1413 identity of the client. Second hyphen should be user ID of the person requesting the document.
[04/Feb/2018:22:08:47 +0000] → day, month, year, hour, minute, second, time zone.
“GET /icons/back.gif HTTP/1.1” →Get indicates the method used by the client.iconsback.gif indicates requested resource by client. HTTP/1.1 indicates
protocol used by client.
304 →This indicates status code that the server sends back to the client.
179→ This indicates the size of the object returned to the client.
“http://localhost/~xubuntu/” →HTTP request header.
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0″ →This is information of the client’s browser.
Overall view from this log is that client visited http://localhost/~xubuntu/at
22:08:47 on 4.2.2018 (+0000 timezone)
Log found from /var/log/apache2 folder with command tail -f error.log
This log was recorded before I issued command sudo a2enmod userdir and
I tried to visit localhost/~xubuntu with Firefox web browser.
[Sun Feb 04 22:00:40.335807 2018] [mpm_event:notice] [pid 7098:tid
140475917810624] AH00491: caught SIGTERM, shutting down
[Sun Feb 04 22:00:40.403289 2018] [mpm_event:notice] [pid 8090:tid 139870138825664] AH00489: Apache/2.4.27 (Ubuntu) configured — resuming normal operations
[Sun Feb 04 22:00:40.403529 2018] [core:notice] [pid 8090:tid 139870138825664] AH00094: Command line: ‘/usr/sbin/apache2’
[Sun Feb 04 22:00:40.335807 2018] →Date and time
[mpm_event:notice] →Module producing the message and severity of message
[pid 7098:tid 140475917810624] →Process ID and thread ID
AH00491: caught SIGTERM, shutting down →Error message
First line means process with process ID 7098 has shut down.
Second line probably means that earlier process is now functioning normally.
I didn’t find any information about the third line.
c)Make an error to a code line on your website, find it from the log and analyze it.
First I made a text file a.txt in the public_html folder. Then I realized that I haven’t installed PHP, so I gave command sudo apt-get update && sudo apt-get -y install apache2 mysql-client mysql-server libapache2-mod-php php-mysql curl lynx. I found this line from our teacher’s web page http://terokarvinen.com. I searched for a basic code lines from Internet and copied it in the a.txt.
It didn’t show the results which I assumed (just a “Hello World!”).
I forgot that the text file must be in right format. I renamed a.txt to a.php with command mv a.txt a.php.
Now it is working. Next I needed to get a error message, so I erased a question mark from the PHP code line. This does not cause a error log to /var/log/apache2/error.log. I erased h1> from the header line but this didn’t show up in the apache’s error log either.
Yesterday when I was trying to get the log events, Libreoffice Writer crashed.
When I restarted the Writer, it tried automatically restore my unsaved report.
I clicked ok but it just quickly showed the Libreoffice logo and went back to this window in the picture above. I tried this many times but without success. Then I started to google if I could find the unsaved report from some kind of temporary folder or something alike.
I found instructions how to recover the file but at this time I realized that I can’t open Libreoffice Writer at all, because it couldn’t get past the recover window shown above. I wasn’t able to proceed with these instructions but I followed the folder path told in these instructions on the file manager. Path was /home/xubuntu/.config/libreoffice/4/user/backup. And there it was, my report. But still I wasn’t able to open the file with Libreoffice Writer because the previous problem. I tried to open the file with multiple applications like Notes and Document viewer but with no success. I also tried to open it with command nano untitled1.odt but it didn’t open it. And just a reminder, I was working with live USB so I couldn’t just restart my computer.
I couldn’t figure out other ways and it was getting pretty late, so I copied the report to my USB drive. I restarted computer with my installed Xubuntu OS and prayed that report wasn’t corrupt or anything and could be opened. My report opened with Libreoffice Writer normally and my work was saved. Unfortunately I didn’t remember copy images to USB drive so they were lost during this tragedy.
Now that my live USB session doesn’t exist anymore, I have to begin
from the start. I’m going to eat something and then follow the exact same path as earlier and going to report only if any problems occur.
Now I am at the same point as earlier. So remembered that i need to allow PHP by changing the PHP.7.1 file. To edit this config file I gave command sudoedit /etc/apache2/mods-available/php7.1.conf and then commented out lines below. Put a hashtag in front of the line to make it a comment.
Then i changed a.php file name to index.php so it shows directly the wanted web page instead of folders. Then I restarted Apache with command sudo systemctl restart apache2.system
Then i edited index.php with few code lines with the needed error for this exercise. Error is the missing ) after calculation!
This was noted in Apache’s error log. Command tail -f error.log in the /var/log/apache2 folder to follow the log in real time.
[Mon Feb 05 12:42:41.962804 2018] [php7:emerg] [pid 16875] [client 127.0.0.1:35672] PHP Parse error: syntax error, unexpected ‘?>’ in /home/xubuntu/public_html/index.php on line 7
This log indicates that php7 module has a emergency. Process ID 16875. I think that this means the client’s IPv4 address is 127.0.0.1 but i don’t know what this :35672 means. Error message says that there is a syntax error on line 7 with the code from /home/xubuntu/public_html/index.php file.
f) Make a application which runs on your server.
I made a calculator which calculates if you are going to get a ticket for speeding and how much it is going to be in euros. Prices and speeds are made up and not real. Here is the end result.
Some test examples:
drivingSpeed = 120, speedLimit = 120 -> No speeding, no fine drivingSpeed = 65, speedLimit = 60 -> Infraction fine is 85 euros. drivingSpeed = 77, speedLimit = 60 -> Infraction fine is 115 euros. drivingSpeed = 105, speedLimit = 100 -> Infraction fine is 70 euros. drivingSpeed = 117, speedLimit = 100 -> Infraction fine is 100 euros. drivingSpeed = 121, speedLimit = 100 -> Income-based unit fines.
And here is the code.