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

<html>
<head>
<title>
jmahkyla
</title>
</head>
<body>
<h1>jmahkyla</h1>
</body>
</html>

Screenshot_2018-03-11_23-07-57

I repeated the same for all other users:

Screenshot_2018-03-11_23-18-12.png

 

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>
#</IfModule>

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.

Screenshot_2018-03-12_00-07-51.png

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:

CREATE DATABASE phurme CHARACTER SET utf8;

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

CREATE TABLE taulu (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(1024));

I inserted data into the table:

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

Screenshot_2018-03-12_00-01-43.png

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:

Screenshot_2018-03-12_00-13-28.png

 

4. Jorma wants to develop a new page sleep.example.com. 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:

127.0.0.1 sleep.example.com

Screenshot_2018-03-12_00-43-10.png

 

5. Protect the computer with a firewall.

Screenshot_2018-03-12_00-46-55.png

 

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

Screenshot_2018-03-12_00-59-23.png

sudo chmod +x wowstats

sudo cp wowstats /usr/bin/

Screenshot_2018-03-12_01-03-38.png

 

Sources: http://terokarvinen.com/2017/aikataulu-%e2%80%93-linux-palvelimet-ict4tn021-7-ti-ja-6-to-alkukevat-2018-5-op, http://terokarvinen.com/2016/read-mysql-database-with-php-php-pdo, http://terokarvinen.com/2017/arvioitava-laboratorioharjoitus-%e2%80%93-linux-palvelimet-ict4tn021-2-uusi-ops-alkukevaalla-2017-p1, https://smyl.es/modifying-your-hosts-file-to-point-a-domain-at-a-specific-ip-address/, https://unix.stackexchange.com/questions/84686/how-to-create-custom-commands-in-unix-linux, https://www.howtogeek.com/howto/30184/10-ways-to-generate-a-random-password-from-the-command-line/

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