Virtual Private Server, IPLookup and creating PHP-homepage!

H4

I did this exercise at home with:
HP Pavilion 15-aw022no
AMD A9-9410 (2.9GHz, 2 Cores)
8GB DDR4-SDRAM 2133MHz (2 x 4)
256GB SSD
AMD Radeon R7 M440 (2GB, GDDR3)
Ubuntu 16.04.3 LTS

Instructions to exercises from: http://terokarvinen.com/2017/aikataulu-%E2%80%93-linux-palvelimet-ict4tn021-7-ti-ja-6-to-alkukevat-2018-5-op

CRUD and phpMyAdmin testing added on this post.

a) Make possible to make web pages on your virtual server with normal user’s rights.

8.2.2018

20:42

At this time I already had Apache2 installed.

I made a folder called public_html with command mkdir public_html and text file called index.html with command nano index.html. Folders location is /Home/ and i wrote only Hello to the index.html. Then to enabled userdir module by giving command sudo a2enmod userdir. This command takes effect only after restarting Apache with command sudo systemctl restart apache2.service. Now web pages can be made with normal user’s rights.

b) Make the file made earlier show as Apache’s default page (without tilde).

First I created a VirtualHost named richterich.me.conf with command sudoedit /etc/apache2/sites-available/richterich.me.conf. This richterich.me.conf text file contains following code line, which i believe, directs certain web site to use certain folder so you can run multiple web on one server?

VirtualHost

 

Then I enabled richterich.me.conf with command sudo a2ensite richterich.me.conf and disabled the (i believe is) default page with command sudo a2dissite 000-default.conf. Then I restarted Apache to enable the changes.

I reloaded my web page and got results what I hoped for. Now the index.html text file from public_html is the default page of the server.

c) Find signs from attemps of breaking in. You can find more information of the IP addresses with commands like ipcalc, geoiplookup and whois.

21:13

These attempts are found from /var/log with command tail -f ufw.log.ufwlog.png

This is why you need to use good passwords.

Feb 8 21:13:47 kurkku kernel: [209511.152571] [UFW BLOCK] IN=eth0 OUT= MAC=ae:9b:1f:da:17:7a:f4:a7:39:d7:82:7d:08:00 SRC=77.72.82.80 DST=174.138.6.58 LEN=40 TOS=0x00 PREC=0x00 TTL=250 ID=29870 PROTO=TCP SPT=55219 DPT=7574 WINDOW=1024 RES=0x00 SYN URGP=0

I picked this one for a closer look. IPv4 address is 77.72.82.80.

With Ipcalc you can see IPv4 address it self, it’s netmask, wildcard mask, and networks range. Left decimal numbering and right binary numbering. You need to install ipcalc before using with command  ipcalc and to calculate ipcalc 77.72.82.80.IPcalc.png

With Whois you can see very detailed information about the owner of the IP address. Install with command sudo apt-get install whois and see information who is 77.72.82.80.

whois.png

I tried to Google street address which is located in UK and it came with some results. It’s a legitimate firm according their web pages called United Protection (UK). Below is their’s home page with a notification that they have been under cyber attack. They weren’t so secure and protective for themselves!! “:D”

unitedprotection

d)Make web pages on your local PC and copy them to the server with scp-command.

9.2.2018

01:37

First I’m going to use the speed ticket calculator which i used in earlier exercise. In my local PC I issued a command scp -r /home/matias/public_html/index.html matias@174.138.6.58:/home/matias/public_html. This command copies from my local PC text file index.html from path /home/matias/public_html to my virtual server’s public_html folder on address 174.138.6.58. I found some help from Youtube video.

This command worked and next it asked my virtual server’s password. After typed it command line showed percentage of copied file (100%), amount of bytes (1374), transfer speed (1.3KB/s) and transfer time (00:00). Then I realized that i had already a text file index.html so i think it did overwrite it. Then i checked on the virtual server, as they were identical files i couldn’t tell if this was successful attempt.

I made three new files on my local PC with names temp.html, salary.html and speedticket.html. My public_html folder doesn’t have other content so I tried to copy whole folder with command scp -r /home/matias/public_html/ matias@174.138.6.58:/home/matias/public_html. Again same information about the transmission.

scp.png

Then I got back to virtual server and checked the results. It copied whole public_html folder with its contents from local PC to virtual server’s publi_hmtl folder. This wasn’t the wanted result as I thought it would copy only the contents, not the whole folder.

After a little digging I found the right command. I deleted all copied files from virtual server and tried again. On local PC with command scp -r /home/matias/public_html/* matias@174.138.6.58:/home/matias/public_html. This time worked just like I wanted!

So after the folder which contents you want to copy, an asterisk mark does the trick!

10.2.2018

16:44

I have been facing a problem lately with my terminal when I am connected with SSH to my server. After some time idling terminal tab with the SSH connection freezes. This has happened few times now and it needed to be fixed. After about 30mins (just a guess) from terminal’s freeze it gave message packet_write_wait: Connection to 174.138.6.58 port 22: Broken pipe and started to function normally. SSH connection was ended.

After a little Googling I found some instructions which I followed.

I edited my virtual server’s ssh_config file from /etc/ssh/ with command sudo nano ssh_config. I added a line ClientAliveInterval 120 as shown in image below.

ssh_config.png

Then I restarted SSH just in case with command sudo systemctl restart ssh.

Now my virtual server should send a keepalive messages to client every 120 second.

(Edit: 11.2.2018 23:18 This didn’t solve the problem.)

(Edit: 9.4.2018 https://unix.stackexchange.com/questions/200239/how-can-i-keep-my-ssh-sessions-from-freezing This worked for me. Problem solved.)

e)Do a simple PHP-page on your server. (AND CRUD TEST WHICH MISSED FROM EARLIER BLOG POST)

First I installed missing application from LAMP, in other words Mysql. With command sudo apt-get -y install apache2 mysql-client mysql-server libapache2-mod-php php-mysql I made sure that nothing is missing. Then I typed a password for Mysql root user.

CRUD test for Mysql.
I tested Mysql by command mysql -u root -p to login as a root user. First I created a database user and database “esimerkki” and password to it with command create database esimerkki character set utf8; and then grant all on esimerkki.* to esimerkki@localhost identified by ‘password’;. Then I tested to login to my new user by issuing exit to logout from root user. Next I tried to login with command mysql -u esimerkki -p and then gave the password.

Once I was logged in as esimerkki, I created a table called esimerkkipöytä. Command use esimerkki to change to database esimerkki, then create table esimerkkipöytä (id int auto_increment primary key, name varchar (1024));. Then I inserted few values  with command insert into esimerkkipöytä(names) values (“esim”); and a second value with similar command insert into esimerkkipöytä(names) values (“obs”);.

Then I tried to read one of them with command select * from esimerkkipöytä where name like ‘e%’;. Result was expected esim. Then I updated the table by naming obs value to huom with command update esimerkkipöytä set name=”huom” where name=”obs”;. Lastly I deleted the obs value with command delete from esimerkkipöytä where name=”huom”;

After this CRUD test I printed this table to my server by editing my index.php file from the public_html folder. I opened it with command nano /home/matias/public_html/index.php and copy pasted a PHP program from our teacher’s website . I had to change only user to esimerkki, password and table to esimerkkipöytä.

phpprogram.png

I added few values to the table just for the photo below with commands used earlier.
I tested if this works by reloading localhost on firefox and yes indeed it works.

esimerkkipöytäfirefox.png

Mysql works as it should.

Next I installed phpMyadmin following instructions found from DigitalOcean’s website. First I issued command sudo apt-get install phpmyadmin php-mbstring php-gettext. As the first prompt appeared, I selected Apache2 as a server by hitting space, tab and then enter. Then I selected yes  when asked wheter to use dbconfig-common or not. I confirmed passwords and then enabled PHP mcrypt and mbstring extensions with commands sudo phpenmod mcrypt and sudo phpenmod mbstring. Lastly restarted Apache, sudo systemctl restart apache2.service. I tried if it works by giving an address localhost/phpmyadmin in firefox. Then I logged in as root. Success.

phpmyadminlocal

Next I started to construct the website following these instructions.

When I had created all necessary files and tried it on my local PC successfully, I copied phpreg folder (which had all .php files) to my virtual server (scp -r /home/matias/public_html/phpreg/ matias@174.138.6.58:/home/matias/public_html on local PC).

Then I logged in to my virtual server via ssh and reconfigured richterich.me.conf file from /etc/apache2/sites-avaible. I changed document path to /hom/matias/public_html/phpreg.

virtualhostphpreg

Then I created Mysql database (with same commands that I used earlier) for the registration process. All codes and file names for are found from these instructions.

I added few links into the index page after login just for fun and excitement. Now after you have created an account you can use these calculators.

richteirhcindex.png

You can check out my website from www.richterich.me. This site is not protected properly, don’t use real phone numbers etc…

Leave a Reply

Your email address will not be published.