Linux servers ICT4TN021 – H7

In this post I’m reporting Tero Karvinen’s “Linux Palvelimet” -courses assignment 7.[1] This is the last assignment of the course and I’m going to redo everything I’ve learnt so far. Assignment started 08.10.2018 @ 18:89.

What am I working with?

  • Operating system: Xubuntu-18.04.1 64b[2] (Bootable USB)
  • CPU: Intel I5-6600k @ 3.5GHz
  • GPU: Geforce GTX 1070, 8Gb VRAM
  • RAM: 2x 8Gb DDR4 @ 2667MHz
  • MoBo: Asus Maximus VIII Ranger (boot menu F8)


Assignment A)

Rehearsal started @ 18:28 08.10.2018

Solve any old lab rehearsal of your choosing from this course.[1]

I wanted to choose a rehearsal that covers a lot of ground that I’m not too comfortable with and I ended up choosing the latest rehearsal from Spring 2018.[3]


I started by booting the computer using a bootable USB stick. Once my computer had opened I switched my keyboard layout to the Finnish one in terminal by typing:

setxkbmap fi

I also updated the packet repository with:

sudo apt-get update

I opened SSH(22) and HTTP(80) ports and enabled the firewall:

sudo ufw allow 80/tcp
sudo ufw allow 22/tcp
sudo ufw enable

Install a web stack of your choosing. Make an example program using it

I decided to install LAMP (Linux, Apache, MariaDB(or MySQL) and PHP).

I started by installing Apache:

sudo apt-get install -y apache2

Then I rewrote localhost with:

echo hello | sudo tee /var/www/html/index.html 

I enabled user directories and restarted apache2 with:

sudo a2enmod userdir
sudo systemctl restart apache2

I created a directory called public_html under /home/xubuntu and a file called index.html in it with:

mkdir public_html
cd public_html/
nano index.html

I wrote “Hellooo” inside the index.html file and refreshed my localhost page with shift + refresh(top left corner):


Time to install PHP:

sudo apt-get install -y libapache2-mod-php7.2

I renamed my index.html into index.php:

mv index.html index.php

and edited it:





It didn’t post anything so I need to look what’s wrong:

cd /etc/apache2
grep -ir php

Grep gave me the following information and like the 3rd last line says, I need to re-enable PHP by commenting out some lines.

sites-available/default-ssl.conf:		<FilesMatch "\.(cgi|shtml|phtml|php)$">
mods-available/php7.2.load:# Conflicts: php5
mods-available/php7.2.load:LoadModule php7_module /usr/lib/apache2/modules/
mods-available/php7.2.conf:    SetHandler application/x-httpd-php
mods-available/php7.2.conf:<FilesMatch ".+\.phps$">
mods-available/php7.2.conf:    SetHandler application/x-httpd-php-source
mods-available/php7.2.conf:    # Deny access to raw php sources by default
mods-available/php7.2.conf:# Deny access to files without filename (e.g. '.php')
mods-available/php7.2.conf:# Running PHP scripts in user directories is disabled by default
mods-available/php7.2.conf:# To re-enable PHP in user directories comment the following lines
mods-available/php7.2.conf:        php_admin_flag engine Off
mods-available/dir.conf:	DirectoryIndex index.html index.cgi index.php index.xhtml index.html

So I opened mods-available/php7.2.conf with sudoedit:

sudoedit mods-available/php7.2.conf

And I commented them out by putting # infront of every line starting from <Ifmoduele to </Ifmodule>.


Now I only need to restart Apache to see if PHP is working or not:

sudo systemctl restart apache2


Last but not least I have to download MariaDB since MySQL doesn’t work well on Xubuntu 18.04.1, but they are basicly the same programs. Used Tero’s Guide here.[4]

I installed mariadb-client and mariadb-server:

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

Logged in as root in to MariaDB:

sudo mariadb

Created a database:


Created an account that uses the specific database:

GRANT ALL ON cars.* TO cars@localhost IDENTIFIED BY 'XNg`$KdU`JT0-1I';

And configured mariadb to run from the account i had just created:

nano .my.cnf

I wrote this inside the .my.cnf:


Now i should be able to open MariaDB by typing mariadb in terminal.

I created a table called cars and set 3 fields in it:

| Field | Type         | Null | Key | Default           | Extra                       |
| id    | int(11)      | NO   | PRI | NULL              | auto_increment              |
| name  | varchar(255) | YES  |     | NULL              |                             |
| time  | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |

Inserted some information into my database:

MariaDB [cars]> INSERT INTO cars(name) VALUES ('Mustang');
MariaDB [cars]> INSERT INTO cars(name) VALUES ('Nissan Skyline GTR');
MariaDB [cars]> INSERT INTO cars(name) VALUES ('Mazda RX7');
MariaDB [cars]> SELECT * FROM cars;
| id | name               | time                |
|  1 | Mustang            | 2018-10-08 16:40:48 |
|  2 | Nissan Skyline GTR | 2018-10-08 16:41:13 |
|  3 | Mazda RX7          | 2018-10-08 16:41:31 |

Time to make it work through localhost:

First I edited index.php by giving it a working script that uses mariadb:


(script by Tero Karvinen).[4]

Didn’t work, since I hadn’t installed the module that let’s mariadb and php work together:

sudo apt-get -y install php-mysql 
sudo systemctl restart apache2


Now to add some users to server.

I started by creating a directory and file under /etc/skel which are going to be copied to every user that I’m going to create.

sudo mkdir /etc/skel/public_html
sudo nano /etc/skel/public_html/index.html

I created users called

Jorma Mähkylä, Pekka Hurme, Ronaldo Smith, Håkan
Petersson, Einari Mikkonen, Einari Vähäkäähkä, Eija Vähäkäähkä. 


sudo adduser jmahkyla
sudo adduser phurme
sudo adduser rsmith
sudo adduser hpeterss
sudo adduser emikkone
sudo adduser evahakaa
sudo adduser eijavaha

I generated passwords for the users using pwgen:

sudo apt-get -y install pwgen

I tested the users directories with”user”/ and tried that every single one worked.

Creating a command called ipos that shows the computers ip address. Command needs to work on all users.

I started by creating a BASH file:


inside I wrote

hostname -I

and ran the file by typing:


which printed out my ip

Now to make the script public for every user:

I started by putting a sha-bang in the script:


hostname -I

Gave everyone rights to execute the script:

chmod a+x

Then i renamed the file to ipos:

mv ipos

copied it to /usr/local/bin with:

sudo cp ipos /usr/local/bin/

Tested the file using another user:

sudo apt-get -y install ssh
ssh phurme@localhost
phurme@xubuntu:~$ ipos 


Next step is to create Hello world for Pekka using Python, BASH and Nodejs.

I’m not sure which is the right way to do this, to create it using my sudo user credentials, in my own home folder and moving it to Pekka’s folder; or to create it inside Pekka’s folder from the get go.

I used SSH to get on Pekka’s user and created a directory called Scripts under /home/phurme:

mkdir scripts
cd scripts/

I wrote:

print ("Hello world!")

inside the script.

phurme@xubuntu:~/scripts$ python3 
Hello world!

Next up was to create a BASH script.

I created a bash file:


wrote the following inside the file:

echo Hello world!

And it printed out the following in console, once I gave the command:

phurme@xubuntu:~/scripts$ bash
Hello world!

Last Hello world is going to be java. I used Tero’s guide[5] for this part.

I needed to install Java:

sudo apt-get -y install default-jre default-jdk

Then I created a script called


and wrote the following inside:

public class hello
 public static void main(String[] args)
 System.out.println("Hello world!");

(Teros script).[5]

I compiled the script:


and executed it:

phurme@xubuntu:~/scripts$ java hello 
Hello world!


Put the example program(LAMP) to show from your apache frontpage.

I followed Tero’s guide[6] here since I couldn’t quite remember what to do:

I started by creating a new .conf file by:

sudoedit /etc/apache2/sites-available/thomas.conf

Editing the following in it:

## /etc/apache2/sites-enabled/thomas.conf
<VirtualHost *:80>
 DocumentRoot /home/xubuntu/public_html/

 <Directory /home/xubuntu/public_html/>
   Require all granted

Enabling my newly created default page:

sudo a2ensite thomas.conf

and disabling the original default page:

sudo a2dissite 000-default.conf

And by reloading my apache:

sudo systemctl reload apache2.service


Two(2) sites under One(1) IP.

I had never done this part before, so it was super nice to try it out since it seems that it has been in multiple lab rehearsals before. I followed Tero’s guide here.[7]

I started by creating a new conf:

sudoedit /etc/apache2/sites-available/

And pasting the following inside it:

<VirtualHost *:80>

 DocumentRoot /home/xubuntu/publicsites/

 <Directory /home/xubuntu/publicsites/>
   Require all granted

I enabled the site:

sudo a2ensite

And reloaded apache2:

sudo systemctl reload apache2.service

Created a web page using a normal user:

mkdir -p /home/xubuntu/publicsites/

Created a new index.html site that said thomas:

echo thomas > /home/xubuntu/publicsites/

Installed curl:

sudo apt-get install curl

Curled the site:

$ curl -H 'Host:' localhost

And curled my localhost site:

$ curl localhost

<p>1 Mustang</p>
<p>2 Nissan Skyline GTR</p>
<p>3 Mazda RX7</p>

Edited /etc/hosts file:

$ sudoedit /etc/hosts

Wrote the last line inside ( localhost xubuntu

# The following lines are desirable for IPv6 capable hosts

and saved.

Now my ip had 2 different addresses under the same ip.


Lab-rehearsal finished, since I couldn’t do the parts that required me to check logs etc.

Rehearsal finished @ 21:56. This is the last given assignment for the course and all I have left is the real lab-rehearsal on Thursday 11.08.2018. I am definitely going to use Linux outside of this course and in the next course that is going to start right after this one.


[1] Course and it’s assignments:

[2] Operating system (Xubuntu 18.04.1 64b):

[3] Old lab-rehearsal:

[4] MySQL database creation with php:

[5] Javascript:

[6] Userdir page as default page:

[7] Multiple sites in one IP:


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 )

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