Linux-palvelimet ICT4TN021-7 linux server course assignment 7

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


A) Solve an old graded lab exercise of this course. (Can be found via DuckDuckGo, Google or links on this page).

I chose this exercise.

1. We want to make PHP-homepages remotely.

Our workers are named Jorma Mähkylä, Pekka Hurme, Ronaldo Smith, Håkan Petersson, Einari Mikkonen, Einari Vähäkäähkä, Eija Vähäkäähkä. Make HTML5-example homepages for them so that the owner’s name is in the heading of every page.

I installed apache via terminal:

sudo apt-get install apache2

I enabled userdir for user homepages:

sudo a2enmod userdir

I restarted apache2:

service apache2 restart

I found information about generating passwords here. I generated a 10-character password for every user with command:

date +%s | sha256sum | base64 | head -c 10 ; echo

I created user accounts with:

sudo adduser jmahkyla

And repeated for every user, typing in every user’s respective password. For last two users i created accounts named evahakaahka and evahakaahka1.

I logged in as jmahkyla:

su – jmahkyla

I created directories for user’s homepages (in home directories):

mkdir public_html

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



I repeated the same for all other users:



2. Maija Virtanen will continue administration, make a sudo-account for her. Maija wants username “maija”.

sudo adduser maija

I generated a password like for all former users i added. Then i added maija to “sudo”, “adm” and “admin” groups.

sudo adduser maija sudo

sudo adduser maija adm

sudo adduser maija admin


3. Pekka Hurme starts learning LAMP. Make a database for Pekka, and change his PHP-example page to show information from a database (“hello world” of databases).

I installed PHP:

sudo apt-get install libapache2-mod-php

I allowed PHP:

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

I commented out:

#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>

I restarted apache2:

service apache2 restart

I created file index.php in public_html:

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

I found some PHP code to show data from databases here.


I installed MySQL:

sudo apt-get -y install mysql-server mysql-client

I generated a password for MySQL root. Then i logged into MySQL:

mysql -u root -p

I created a database and an user for phurme:


GRANT ALL ON phurme.* TO phurme@localhost IDENTIFIED BY ‘MDI3YWZjNj’;

I exited mysql and logged in with the newly created user:

mysql –user=phurme –password

I selected database and created an example table:

USE phurme


I inserted data into the table:

INSERT INTO taulu(name) VALUES (“Nimi”);


Next i installed php-mysql library:

sudo apt-get install libapache2-mod-php php-mysql curl lynx

Then i tried to load the php page, but got a blank page. I looked at logs:

tail /var/log/apache2/error.log

And found out that the reported problem was missing driver. I ran:

service apache2 restart

So that it would recognize the php-mysql driver i had already installed before. Then i tried again and success:



4. Jorma wants to develop a new page Set Jorma’s homepage to show also from this address. You can simulate name server’s operation with the hosts-file.

I found a tutorial here:

I added the following line to etc/hosts:



5. Protect the computer with a firewall.



6. Make a new command ‘wowstats’, which shows information about the state of the system.

I found info here.

I created a bash script in my /usr/bin folder:

sudo nano wowstats


sudo chmod +x wowstats

sudo cp wowstats /usr/bin/





Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s