Web Server Development Windows, Ubuntu, Fedora

Enter few characters in search field (or nothing for all users)

$conn = new PDO($dsn, $user_name, $password...'; } catch ( Exception $e ) { // If the DB connection fails, output the error die ( $e->getMessage() ); } $sql = "select user_id, user_name from users where user_name like '%$find_fld%'"; echo "

"; foreach ($conn->query($sql) as $row) { print $row['user_id'] . "\t"; print $row['user_name'] . "
"; } echo"

"; //$result->close(); //$conn->close(); //mysqli_close($conn); ?>
select_db($db); //mysqli_select_db($db); if ($result = $conn->query("SELECT DATABASE()")) { $row = $result->fetch_row(); printf("Default database is %s.\n", $row[0]); $result->close(); } $sql = "select user_id, user_name from users where user_name like '%$find_fld%'"; // "SELECT Name FROM City LIMIT 10" if ($result = $conn->query($sql)) { printf("
Select returned %d rows.", $result->num_rows); // free result set //$result->close(); } //$result = mysqli_query($sql); echo "

"; while ($row = mysqli_fetch_array($result)) { echo "$row[user_id], $row[user_name]
"; } echo"

"; $result->close(); $conn->close(); //mysqli_close($conn); ?>


URLs on LAN :

http://sspc1:8083/fwphp/aplw/glomodul/help/Web%20Server%20Development%20Windows,%20Ubuntu,%20Fedora.php
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "<p style=\"font-size:24px; color: green; text-align: center\">Your IP address is $ip</p>";
?>
outputs     : Your IP address is $ip"; ?>  
same hardcoded: Your IP address is fe80::e4fc:46ba:1d30:393d

http://phporacle.mooo.com.localtest.me:8083/fwphp/aplw/glomodul/help/Web%20Server%20Development%20Windows,%20Ubuntu,%20Fedora.php
outputs : Your IP address is 127.0.0.1 - this sees DDNS whith localtest.me

or URL on inet :
http://tools.pingdom.com. At the Test Now text field, enter the DDNS URL :
http://phporacle.mooo.com:8083/fwphp/aplw/glomodul/help/Web%20Server%20Development%20Windows,%20Ubuntu,%20Fedora.php
outputs two output above IP address displayed is the IP address of the remote online tool so :
Your IP address is 5.178.78.78 (213.191.136.167 Zagreb)
Your IP address is 127.0.0.1 - this sees DDNS whith localtest.me

 

Why? Do I need a full-fledged Web server for my home or office?

  1.  Set up and maintain a Web site in order to avoid the expense of hiring someone else.
  2.  More advanced than a free Web hosting site will allow. Eg :
    database queries or to show input from a Web camera.
  3.  You wish to learn more about the Internet-related technology by following a hands-on approach.

What to do?

  1.  Turn (even old) computer into a Web server using free Open Source programs.

  2.  Configure your Operating System (OS) network layer to support Web Server service :
    providing the appropriate (static) IP address and open TCP port numbers.
    Lubuntu 14.04.2, based on minimal desktop LXDE (Lightweight X11 Desktop Environment), fast performing and energy-saving and a selection of light applications - very low hardware requirements. http://lubuntu.net/ - burn an ISO image in Windows 7 - right-click on an ISO image and choose Burn disc image (Windows Disc Image Burner). Lubuntu was founded by Mario Behling and has been grown for many years by Julien Lavergne.
    Fedora 20 – is also covered in the appendix.

    Cherokee is an open-source cross-platform web server that runs on Linux, BSD variants, Solaris, Mac OS X, NOT on Microsoft Windows. Graphical tool for administration cherokee-admin and a modular light-weight design.  http://www.cherokee-project.com/

  3. Configure router (eg Level One FBR-1161 ADSL2+ router) to make your Web server available for the entire Internet. Using Virtual Servers service provided by your router, you will redirect HTTP requests destined to the router’s sole public IP address to the private IP address of your server -  HTTP request destined for the router public IP adress is  forwarded by the router to web server.

    Eg web server is a host of LAN 192.168.1.0 and has been assigned
    the private IP address (=PC on whish is installed web server) 192.168.1.101. The Web server will be accessible in the Internet by using the public IP address of the router, IP address 94.69.219.68. The router has the private
    IP address 102.168.1.1, which allows the router to be reachable from inside the LAN.

    Computer 192.168.1.101 must use a static private IP address. You must therefore disable DHCP for your web server and must  manually configure the server’s static IP address, along with the Netmask, Gateway, and DNS servers parameters.

  4. Use a DDNS (Dynamic Domain Name Service) to obtain a free name.ddns_provider.com eg webserver.dynu.com :
    1. Find your inet provider's nonstatic public IP adress eg 213.191.136.167 eg here: https://www.yougetsignal.com/ - Port Forwarding Tester to determine if a specific port on the server is open
    2. Register (sign up) eg here: https://freedns.afraid.org/ for free or payed DDNS account
    3. Send your public IP adress eg 213.191.136.167 to DDNS provider so :
      https://freedns.afraid.org/nic/update?hostname=phporacle.mooo.com&myip=213.191.136.167
      (asks user name and password aquired in register step)

    Domain Name for your site on your LAN :
    http://phporacle.mooo.com.localtest.me:8083/
    (you need an external computer - localtest.me - to see how your site looks from outside your LAN)

    To test your site with the new domain name obtained from  DDNS provider, go to http://tools.pingdom.com. At the Test Now text field, enter the new DDNS URL for your site http://phporacle.mooo.com:8083/

    or from any PC on inet :
    http://phporacle.mooo.com:8083/
    By registering your domain name with a Dynamic DNS (DDNS) service, you will map your router’s public IP address to a domain name.

  5. Utilize online network tools for checking site connectivity, performance, status, return visitor's IP address.
    Start multiple Virtual Servers (this is unrelated to the router’s Virtual Servers service) that will run in parallel, dispatching different content according to a set of rules that you configure.
    Simple administrative tasks; read log files, view graphs that show
    the server’s activities, etc.
    Use online network tools to ensure that the site behaves from outside your Local Area Network (LAN) as expected.
    Find your inet provider's nonstatic public IP adress eg 213.191.136.167 eg here: https://www.yougetsignal.com/ - Port Forwarding Tester to determine if a specific port on the server is open
    or http://tools.pingdom.com - determine download speeds from various countries and determine which ports are closed
    or http://www.webpagetest.org/ -  to select servers (that simulate web clients) from many different countries  and also different browsers for each server

    Wireshark packet sniffer to inspect the client’s HTTP request when it arrives at the server’s computer capturing packets sent and received by the server’s computer.

    When port forwarding is enabled, port forwarding server alters the Host field as sent by client and  replaces it with the public IP address of the router concatenated with port number, e.g.:
    Host: 87.202.110.63:8080
    In that case Host field does not indicate the server’s domain name and you cannot use the Mach Nickname matching option in Cherokee web server to separate the two virtual servers based on domain name.
    Therefore, to use the Match Nickname option, we must disable Port Forwarding for domains registered for the two virtual servers.

    When using the HTTP Viewer network tool eg web-sniffer.net, the tool acts as a Web client and queries the DDNS server to resolve your Web server’s domain name to an IP address and then sends a request to the Web server. It’s recommended to use the tool twice – once with the port forwarding service enabled and once with the port forwarding service disabled.

                      1.  Online network tool eg web-sniffer recieves URL http://phporacle.mooo.com:8083/
                         queries         sends                  sends
                         ^ IPadr         | connRequest     |Request
                         | DN            v                          v
    1. DDNS server              INTERNET             3. web server
                                            |
                                            v
                            2. Port Forwarding server

    2. DDNS server, contacted by 1. Online network tool, resolves URL http://phporacle.mooo.com:8083/ to the IP address 192.168.5.1 (=my home PC router) of 2. Port Forwarding server.
    1. Online network tool acts as a client and sends connection request to 2. Port Forwarding Server, which redirects client to the IP address 192.168.5.1 of the router of the Web server’s LAN.
    Redirected address includes the appropriate port (e.g., port 8083) and, in this case, new address becomes <router’s public IP address>:8083.
    Client 1.  Online network tool then connects to router and with the Virtual Servers router configuration, the client eventually connects to 3. Web Server IP address 192.168.5.101.

    With port-forwarding disabled DDNS system (1) resolves the Web server’s domain name to the public IP address of the Web server’s router 192.168.5.1 and router, with its Virtual Servers service, redirects the request to 3. Web Server.
    In this case, a Port Forwarding server was not interfered with and the Host field in packet remained unchanged.

    Test page network tool (e.g., tools.pingdom.com) acts as a client to request a page from Web server. When Web server receives the request, a sniffer (e.g., Wireshark) can be used to grab the packet from the LAN segment on which the Web server is attached. It’s recommended to run Wireshark twice: with port forwarding enabled and with port forwarding disabled.

    When port forwarding is enabled, the Host field in the packet captured by Wireshark has already been altered by the Port Forwarding server of the DDNS system. The server’s domain name has been replaced by the public IP address of the server’s router. The Match Nickname option of the Cherokee Host Match tab cannot be used in this case to match the virtual server because the Host field of the packet does not contain the server’s domain name (e.g., webserver.dynu.com) but instead contains the <router’s public IP address>: <port forwarding number> pair.

    We’ll use http://www.webpagetest.org to view the HTML pages from both virtual servers.
    Recall that we are not using the Port Forwarding server; therefore, we must include port numbers in the URLs:  http://phporacle.mooo.com:8083/



    To examine the headers of the HTTP protocol online network tool HTTP Viewer is no more available:
    http://www.rexswain.com/httpview.html   - 10 December 2017: Due to abuse reported by the National Cybersecurity & Communications Integration Center (NCCIC), my ISP has disabled my HTTP Viewer. Thanks a lot, hackers!

  6. Build Web sites : static HTML or dynamic PHP content and DB (eg MySQL). Online tutorials : http://www.w3.orghttp://www.w3schools.com...
    PHP page we create here is online network tool to display IP address of the visitor.

    Document Root directory is /var/www or /usr/local/var/www for Ubuntu but this value can be changed. Eg page placed in docs subdirectory of /var/www and therefore accessed with relative (to the document root) name docs/page1.html :
    <A HREF=“docs/page1.html” style=“font-size:200%”>About Cherokee</A>
    Image link external to the site is placed in the images subdirectory and is referred to with the relative name images/cherokee.png :
    <A HREF=“http://cherokee-project.com/”>
    <img src=“images/cherokee.png”>
    </A>

    C:\WINDOWS\system32>j:
    J:\>cd J:\zwamp64\vdrive\.sys\mysql\bin
    mysql -u root -p
    Enter password: ****
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 15
    Server version: 5.7.16 MySQL Community Server (GPL)
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql>
                create database bookstore;
                create table books(book_id int auto_increment primary key, title varchar(255) not null, author varchar(255) not null);
                or
                create table books(book_id int auto_increment, title varchar(255) not null, author varchar(255) not null, primary key(book_id));

    use tema
    show tables;
    +----------------+
    | Tables_in_tema |
    +----------------+
    | admins         |
    | events         |
    | pages          |
    | song           |
    | subjects       |
    | users          |
    +----------------+
    6 rows in set (0.00 sec)

    desc admins;
    +-----------------+--------------+------+-----+---------+----------------+
    | Field           | Type         | Null | Key | Default | Extra          |
    +-----------------+--------------+------+-----+---------+----------------+
    | id              | int(11)      | NO   | PRI | NULL    | auto_increment |
    | first_name      | varchar(255) | YES  |     | NULL    |                |
    | last_name       | varchar(255) | YES  |     | NULL    |                |
    | email           | varchar(255) | YES  |     | NULL    |                |
    | username        | varchar(255) | YES  | MUL | NULL    |                |
    | hashed_password | varchar(255) | YES  |     | NULL    |                |
    +-----------------+--------------+------+-----+---------+----------------+
    6 rows in set (0.00 sec)
    insert into books (title, author) values (‘Waving The Web’, ‘Tim Berners Lee’);
    insert into books (title, author) values (‘Just for Fun’, ‘Linus Torvalds’);
    insert into books (title, author) values (‘How the Web was Born’, ‘Gillies & Cailliau’);

    select * from users;
    select user_id, user_name from users where user_name like “%%”;

    To exit MySQL enter:
    mysql> \c
    and then:
    mysql> exit