Browse Source

H3: Update text

master
Pekka Helenius 5 years ago
committed by GitHub
parent
commit
e534e725d2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 30 deletions
  1. +32
    -30
      exercises/h3.md

+ 32
- 30
exercises/h3.md View File

@ -151,16 +151,16 @@ xdg-open http://example.com/~$(whoami)/
```
**b)** Browse and explore the websites on your local host. Find out any hints of successful (200 ok) website load events and failed load events (for example, 404 not found). Analyse the relevant lines.
**b)** Browse and explore the websites on your local host. Find out any hints of successful (200 ok) website load events and failed load events (for instance, 404 not found). Analyse the relevant lines.
--------------
**Answer:**
**NOTE!** My detailed answer to this assignment is in the previous exercise 2, section a) (successful & failed event + analysing them). Link: [Exercise 2](https://github.com/Fincer/linux_server_setup/blob/master/exercises/h2.md)
In my answer I have analysed Apache web server log lines. The logic is exactly same than required in this assignment. Apache logs each event when a client (web browser, for example) try to access a file or location in server.
In my answer I have analysed Apache web server log lines. The logic is exactly same than required in this assignment. Apache logs each event when a client (web browser, for instance) try to access a file or location in server.
**c)** Create a purposeful error in any code line which is executed by Apache web server (PHP or Python, for example). Find out any relevant log lines and analyse them in detail.
**c)** Create a purposeful error in any code line which is executed by Apache web server (PHP or Python, for instance). Find out any relevant log lines and analyse them in detail.
--------------
**Answer:**
@ -206,7 +206,7 @@ if [[ $APT_CHECK -eq 1 ]] && [[ $(id -u) -ne 0 ]] && [[ $(groups | grep -o sudo
# If apache2 is installed in the system, then...
#
if [[ $APACHE2_CHECK -gt 0 ]]; then
############
# install PHP 7.0 and relevant Apache2 PHP 7.0 modules
#
@ -230,13 +230,13 @@ if [[ $APT_CHECK -eq 1 ]] && [[ $(id -u) -ne 0 ]] && [[ $(groups | grep -o sudo
# If command wget is available on the system, then...
#
if [[ $WGET_CHECK -eq 1 ]]; then
############
# Download sample PHP code into directory $HOME/public_html/
# NOTE! Can we trust the downloaded code?
#
echo -e "\nDownloading sample PHP code for testing purposes (requires internet connection, security risk exists! Use local trusted code if system hardening means anything to you...)\n"
#
wget -P $HOME/public_html/ $SAMPLE_CODE
@ -257,7 +257,7 @@ if [[ $APT_CHECK -eq 1 ]] && [[ $(id -u) -ne 0 ]] && [[ $(groups | grep -o sudo
else
echo -e "\nInstall application 'wget' before downloading a sample code"
fi
############
# Packages matching string 'apache2' can't be found in the system by doing the check via Debian package manager
#
@ -269,7 +269,7 @@ fi
```
Apache web server prints out the following error message in _/var/log/apache2/error.log_ while trying to open local website _example.com/~phelenius/calculator_v2.php_:
Apache web server prints out the following error message in `/var/log/apache2/error.log` while trying to open local website `example.com/~phelenius/calculator_v2.php`:
```
[Wed Feb 07 00:20:02.923994 2018] [:error] [pid 14260] [client 127.0.0.1:38430] PHP Parse error: syntax error, unexpected 'case' (T_CASE) in /home/phelenius/public_html/calculator_v2.php on line 20
@ -280,7 +280,7 @@ Apache web server prints out the following error message in _/var/log/apache2/er
[Wed Feb 07 00:20:04.470184 2018] [:error] [pid 14262] [client 127.0.0.1:38440] PHP Parse error: syntax error, unexpected 'case' (T_CASE) in /home/phelenius/public_html/calculator_v2.php on line 20
```
Apache web server complains multiple times about a PHP syntax error in /home/phelenius/public_html/calculator_v2.php file, on line 20.
Apache web server complains multiple times about a PHP syntax error in `/home/phelenius/public_html/calculator_v2.php` file, on line 20.
Mentioned PIDs (Process IDs) belong to apache2 process:
@ -294,9 +294,9 @@ www-data 14262 0.0 0.5 253844 11648 ? S 00:16 0:00 /usr/sbin/apach
www-data 14268 0.0 0.5 253844 11648 ? S 00:16 0:00 /usr/sbin/apache2 -k start
```
IP address 127.0.0.1 refers to local host, numbers 38430, 38432, 38434, 38436, 38438 and 38440 to the ports where the connection has been established from.
IP address `127.0.0.1` refers to local host, numbers `38430`, `38432`, `38434`, `38436`, `38438` and `38440` to the ports where the connection has been established from.
The equivalent log events in _/var/log/apache2/access.log_:
The equivalent log events in `/var/log/apache2/access.log`:
```
127.0.0.1 - - [07/Feb/2018:00:20:02 +0200] "GET /~phelenius/calculator_v2.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3300.0 Iron Safari/537.36"
@ -307,19 +307,19 @@ The equivalent log events in _/var/log/apache2/access.log_:
127.0.0.1 - - [07/Feb/2018:00:20:04 +0200] "GET /~phelenius/calculator_v2.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3300.0 Iron Safari/537.36"
```
- User's client program (address 127.0.0.1/localhost + client is web browser in this case) tries to retrieve server website _/~phelenius/calculator_v2.php_ for which the Apache web server has responded with error code 500 ([HTTP_INTERNAL_SERVER_ERROR](https://ci.apache.org/projects/httpd/trunk/doxygen/group__HTTP__Status.html#ga5d9777e02c26063c2985e39ef71091d2)).
- User's client program (address `127.0.0.1` / `localhost` + client is web browser in this case) tries to retrieve server website `/~phelenius/calculator_v2.php` for which the Apache web server has responded with error code 500 ([HTTP_INTERNAL_SERVER_ERROR](https://ci.apache.org/projects/httpd/trunk/doxygen/group__HTTP__Status.html#ga5d9777e02c26063c2985e39ef71091d2)).
- User ID is simply a line symbol
- Log time is "07/Feb/2018:00:20:04 +0200" etc
- Log time is "07/Feb/2018:00:20:04 +0200" (and similar)
- HTTP method used is [GET](https://www.w3schools.com/tags/ref_httpmethods.asp)
- has [HTTP Referer](https://en.wikipedia.org/wiki/HTTP_referer)
- size of the object is 185 (reported to the client program)
- size of the object is `185` (reported to the client program)
- [User agent header](https://en.wikipedia.org/wiki/User_agent) reported by the client. According to the agent string, client browser has been gecko-based [Epiphany web browser](https://en.wikipedia.org/wiki/Epiphany_(GNOME)), using x86_64 processor architecture. This string can be manipulated in the client end. For example, a desktop client web browser can pretend to be a mobile browser.
- [User agent header](https://en.wikipedia.org/wiki/User_agent) reported by the client. According to the agent string, client browser has been gecko-based [Epiphany web browser](https://en.wikipedia.org/wiki/Epiphany_(GNOME)), using x86_64 processor architecture. This string can be manipulated in the client end. For instance, a desktop client web browser can pretend to be a mobile browser.
Default syntax for Apache log files follow the layout which is described [here](https://httpd.apache.org/docs/2.4/logs.html) under section 'Common Log Format'.
@ -347,18 +347,18 @@ sudo mysql_secure_installation
```
Configuring mysql-server-5.7
While not mandatory, it is highly recommended that you set a password for the MySQL administrative "root" user.
While not mandatory, it is highly recommended that you set a password for the MySQL administrative "root" user.
If this field is left blank, the password will not be changed.
If this field is left blank, the password will not be changed.
New password for the MySQL "root" user:
```
We should choose a strong password ('Hu8aS1n?tI23' or 'Tu$pAR!iMu65' etc. Can be generated with a password generator program _pwgen_ as well). We should use a password which we don't use in other environments.
We should choose a strong password (`Hu8aS1n?tI23` or `Tu$pAR!iMu65` etc. Can be generated with a password generator program `pwgen` as well). We should use a password which we don't use in other environments.
**NOTE!** If unsure, check and configure your keyboard layout so that the password you supply will be correctly set up.
When you have entered your password, press _TAB_ and then press _<Ok>_ (or just _ENTER_). Type the password again and continue.
When you have entered your password, press `TAB` and then press `<Ok>` (or just `ENTER` key). Type the password again and continue.
3. Let's install [phpMyAdmin](https://en.wikipedia.org/wiki/PhpMyAdmin) with its runtime dependencies on Debian-based distribution (Ubuntu 16.04.3 LTS in this case).
@ -381,7 +381,7 @@ Web server to reconfigure automatically:
[] lighttpd
```
Because we assume that you have Apache2 and not lighttpd, we should select apache2. Press _SPACE_ so that option _apache2_ has asterix in the brackets ([*]). After that, press _TAB_ to move the selection to _<Ok>_ and press _ENTER_.
Because we assume that you have Apache2 and not lighttpd, we should select `apache2`. Press `SPACE` key so that option `apache2` will have asterix in the brackets (`[*]`). After that, press `TAB` key to move your current selection to `<Ok>` and press `ENTER` key.
5. The next screen states:
@ -390,25 +390,25 @@ Configuring phpmyadmin
The phpmyadmin package must have a database installed and configured before it can be used. This can be optionally handled with dbconfig-common.
If you are an advanced database administrator and know that you want to perform this configuration manually, or if your database has already been installed and configured, you should refuse this option. Details on what needs to be done should most likely be provided in /usr/share/doc/phpmyadmin.
If you are an advanced database administrator and know that you want to perform this configuration manually, or if your database has already been installed and configured, you should refuse this option. Details on what needs to be done should most likely be provided in /usr/share/doc/phpmyadmin.
Otherwise, you should probably choose this option.
Configure database for phpmyadmin with dbconfig-common?
```
The most common selection in this step is _<Yes>_ (alternative to _<No>_). For choosing a right choice, the following manuals can be used:
The most common selection in this step is `<Yes>` (alternative to `<No>`). For choosing a right choice, the following manuals can be used:
[Configure the database with dbconfig-common](https://docs.openstack.org/ocata/fr/install-guide-debconf/debconf/debconf-dbconfig-common.html)
[dbconfig-common.pdf](https://www.debian.org/doc/manuals/dbconfig-common/dbconfig-common.pdf)
[Stackoverflow - What means dbconfig-common](https://stackoverflow.com/questions/31403273/what-means-dbconfig-common)
Additionally, for example:
Additionally, for instance:
![dbconfig-common_1](https://docs.openstack.org/ocata/fr/install-guide-debconf/_images/dbconfig-common_keep_admin_pass.png)
![dbconfig-common_1](https://docs.openstack.org/ocata/fr/install-guide-debconf/_images/dbconfig-common_used_for_remote_db.png)
Let's choose option _<Yes>_ because we don't have earlier database in our system. More secure, although more troublesome, approach would be selecting _<No>_, according to the material references above.
Let's choose option `<Yes>` because we don't have earlier database in our system. More secure, although more troublesome, approach would be selecting `<No>`, according to the material references above.
**NOTE!** dpkg tool _dpkg-reconfigure_ makes it possible to change package-related configuration in Debian-based systems afterwards (for example, _sudo dpkg-reconfigure phpmyadmin_). However, pay special attention and use extra care if you do any configurations afterwards.
**NOTE!** dpkg tool `dpkg-reconfigure` makes it possible to change package-related configuration in Debian-based systems afterwards (for instance, `sudo dpkg-reconfigure phpmyadmin`). However, pay special attention and use extra care if you do any configurations afterwards.
6. The next screen asks system administrator to set up MySQL database-related password for phpmyadmin MySQL user:
@ -422,7 +422,7 @@ MySQL application password for phpmyadmin:
Let's pick up a strong password for phpmyadmin. Take a look on step 2. for setting up a strong password. Use different password here.
7. If you are not asked to set up a default phpmyadmin username or password, please run _sudo dpkg-reconfigure phpmyadmin_. The default phpmyadmin username is usually 'phpmyadmin' and the login password is the one you write down by executing the command mentioned earlier in this step.
7. If you are not asked to set up a default phpmyadmin username or password, please run `sudo dpkg-reconfigure phpmyadmin`. The default phpmyadmin username is usually `phpmyadmin` and the login password is the one you write down by executing the command mentioned earlier in this step.
8. Let's try accessing phpMyAdmin front page:
@ -435,7 +435,9 @@ If the installation has been successful, the web browser view should look like t
![phpmyadmin-loginpage](https://rootninja.files.wordpress.com/2010/10/image38.png)
9. Log in to phpMyAdmin with the following credentials:
- **user name:** phpmyadmin (or any other defined during phpmyadmin installation)
- **user name:** `phpmyadmin` (or any other defined during phpmyadmin installation)
- **password:** password defined in step 7.
10. If successfully logged in, the web browser view should be as follows (phpMyAdmin - Front page):
@ -446,14 +448,14 @@ phpMyAdmin - Database configuration sample:
![phpmyadmin-dbconfpage](https://github.com/Fincer/linux_server_setup/blob/master/images/phpmyadmin-2-resized.png)
**f)** Create a web application which executes a simple calculation for the user (BMI calculator, for example)
**f)** Create a web application which executes a simple calculation for the user (BMI calculator, for instance)
--------------
**Answer:**
**NOTE!** We assume that the Linux installation has a working Apache HTTP daemon web server with correct PHP support enabled. Apache server has 'userdir' module enabled, and some local user has _public_html_ folder created.
**NOTE!** We assume that the Linux installation has a working Apache HTTP daemon web server with correct PHP support enabled. Apache server has `userdir` module enabled, and some local user has `public_html` folder created in `$HOME` folder.
1. Let's create the following, very simple PHP code and save it to ~/public_html/rainfall.php (current user)
1. Let's create the following, very simple PHP code and save it to `~/public_html/rainfall.php` (current user)
```
<?php


Loading…
Cancel
Save