Tuesday, July 28, 2020

Virtual or Web Hosting on Ubuntu 18.04 LTS (Bionic Beaver)

The following virtual or web hosting setup intends to:

• Make the Apache2 home directory for the virtual hosts in "/home"
• Virtual hosts will be located in their own directory (e.g., user "rasul" will be located in "/home/rasul") and accessible via remote SSH
• Web pages of each virtual host (e.g., user "rasul") will be located in "/home/rasul/www/html"
• Error pages of Apache2 will be located in "/home/rasul/www/error"
• Access log pages of Apache2 will be located in "/home/rasul/www/access"


My preferred editor in here is "joe", a WordStar-like text editor, but you can use your own preferred editor like "vi", "vim", or "nano". This also assumes that you have made the relevant DNS entries for the web host and pointed to the IP address of the Apache webserver.
Step 1: Edit the "apache2.conf" configuration file and add the following entries that will allow apache2 to enter the "/home" directory:

# cd /etc/apache2
# joe apache2.conf

< Directory /home/ >
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
< Directory >



Step 2: Edit the "000-default.conf" in the subdirectory "/etc/apache2/sites-available" and enter the following entries that will define the web pages directory, error pages, and access logs:

# cd /etc/apache2/sites-available
# joe 000-default.conf

< VirtualHost *:80 >
ServerName www.rasul.ph
ServerAdmin webmaster@rasul.ph
DocumentRoot /home/rasul/www/html
ErrorLog /home/rasul/www/error/error.log
CustomLog /home/rasul/www/log/access.log combined
< VirtualHost >



Step 3: Create the virtual host "username" and the corresponing directories, subdirectories, and files:

# adduser rasul
# mkdir /home/rasul/www
# mkdir /home/rasul/www/html
# mkdir /home/rasul/www/error
# mkdir /home/rasul/www/log
# touch /home/rasul/www/error/error.log
# touch /home/rasul/www/log/access.log


Step 4: Change group of the virtual hosts into "www-data". Ubuntu's Apache uses the username "www-data" and group "www-data".

# cd /home
# chown -R rasul.www-data rasul

Listing the directory should display as:

# ls -l
drwxr-xr-x 2 rasul www-data 4096 Jul 29 10:37 rasul




Step 5: Restart the Apache webserver to load the virtual hosts settings

# systemctl restart apache2

Step 6: Check to see by placing a sample webpage in the html directory of the virtual hosts and viewing it in your browser.

Saturday, July 25, 2020

Installing Apache Webserver with PHP scripting, and MySQL and PostgreSQL PHP connection driver under Ubuntu 18.04 LTS (Bionic Beaver)

Clement L. Rasul 1.  Download and install the Apache webserver software

# apt-get install apache2

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install apache2


2.  Download and install the PHP scripting language

# apt-get install php

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php libapache2-mod-php

3.  Download and install the MySQL database server PHP connection driver.

# apt-get install php-mysql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-mysql


4.  Download and install the PostgreSQL database server PHP connection driver as follows:

# apt-get install php-pgsql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-pgsql



5.  By default, the Apache webserver should be running after installation.  You should restart the Apache webserver in order to load the PHP, MySQL and PostgreSQL support.  Issue the command:

# systemctl restart apache2.service


6. To check if the Apache process is running, issue the command

# ps ax | grep apache2

This should produce a display similar to this if it is running:

23263 ?        Ss     0:00 /usr/sbin/apache2 -k start
23265 ?        S      0:00 /usr/sbin/apache2 -k start
23266 ?        S      0:00 /usr/sbin/apache2 -k start
23267 ?        S      0:00 /usr/sbin/apache2 -k start
23268 ?        S      0:00 /usr/sbin/apache2 -k start
23269 ?        S      0:00 /usr/sbin/apache2 -k start
25621 pts/0    S+     0:00 grep --color=auto apache2

If the apache2 process is not running, the display should just produce this entry:

6433 pts/0    S+     0:00 grep --color=auto apache2

7.  To test if the Apache webserver is running using an Internet browser, type the address where the webserver is running.  On the local machine, the address is 127.0.0.1 (also known as the loopback address).  This should display a page similar to this.


This is the default page of the Apache web server.


8.  To change the default page of the Apache webserver, remove the "index.html" file in the subdirectory "/var/www/html" and create a sample HTML file called "index.html" as follows:

# cd /var/www/html
# rm index.html
# vi index.html


< html >
< head >
< title > My First HTML Page < /title >
< /head >
< body >
Hello World!< /body >
< /html >

My assumption here is, you are familiar with using the vi text editor in Linux.  You may use your own preferred text editor to create the HTML file.  After refreshing your browser, the display should look like this.




9.  To test if the Apache webserver has PHP scripting support, create the following "test.php" file and place it in the subdirectory "/var/www/html".

# cd /var/www/html
# vi test.php

< ?php 
phpinfo();
? >

Type in the address bar of the browser "http://127.0.0.1/test.php", the browser should display a page similar to this.




10.  To know if the MySQL database PHP connection driver is installed, you should see and entry in the PHP test page similar to this:




11.  Likewise, to know if the PostgreSQL database PHP connection driver is installed, you should see an entry in the PHP test page similar to this:



12.  Should there be a need to uninstall the Apache webserver, shut down the running apache2 process first before uninstalling.

# systemctl stop apache2.service
# apt-get remove apache2



Installation and Configuration of Master and Caching DNS Server on Ubuntu 18.04 LTS (Bionic Beaver)

1.  Download and install BIND9 software

#apt-get install bind9

By default, the BIND9 software will start running after a successful installation.  If your objective is just to set up a "Caching DNS Server," then your installation is complete already and you can proceed to testing the functionality of the DNS server in Step No. 5.  The succeeding steps below will configure the BIND9 software as a "Master DNS Server".


2.  Configure file "/etc/bind/named.conf.local" by adding the following entries:

//forward
zone "rasul.ph" IN { // Domain name
     type master; // Primary DNS
     file "/etc/bind/forward.rasul.ph.db"; // Forward lookup file
     allow-update { none; }; // Since this is the primary DNS, it should be none.
};

//reverse
zone "0.16.172.in-addr.arpa" IN { //Reverse lookup name, should match your network in reverse order
     type master; // Primary DNS
     file "/etc/bind/reverse.rasul.ph.db"; //Reverse lookup file
     allow-update { none; }; //Since this is the primary DNS, it should be none.
};


3.  Create entries in the zone and reverse lookup files (Forward & Reverse)


3.1  Create the following entries in the Zone lookup file "/etc/bind/forward.rasul.ph.db"

$TTL    604800
@       IN      SOA     ns1.rasul.ph. root.rasul.ph. (
                              3         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
;@      IN      NS      localhost.
;@      IN      A       127.0.0.1
;@      IN      AAAA    ::1

;Name Server Information
@        IN      NS      ns1.rasul.ph.

;IP address of Name Server
ns1     IN      A       172.16.0.1

;Mail Exchanger
rasul.ph.   IN     MX   10   mail.rasul.ph.

;A – Record HostName To Ip Address

www     IN       A      172.16.0.1
mail    IN       A      172.16.0.2

clem    IN      A       172.16.0.2
mike    IN      A       172.16.0.1

rasul.ph.       IN      A       172.16.0.1

;CNAME record
;ftp     IN      CNAME   www.rasul.ph.


3.2  Create and add entries in the Reverse lookup file "/etc/bind/reverse.rasul.ph.db"

$TTL    604800
@       IN      SOA     rasul.ph. root.rasul.ph. (
                              3         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
;@      IN      NS      localhost.
;1.0.0  IN      PTR     localhost.

;Name Server Information

@       IN      NS     ns1.rasul.ph.

;Reverse lookup for Name Server
;1      IN      PTR    ns1.rasul.ph.

;PTR Record IP address to HostName

1     IN      PTR    www.rasul.ph.
2     IN      PTR    mail.rasul.ph.


4.  Check bind configuration syntax by issuing the command

# named-checkconf


5.  Test the DNS response from a client utility using nslookup or host as follows:


5.1  On the client computer, make changes to the name resolution resolver file "/etc/resolv.conf"

# cd /etc
# vi resolv.conf

nameserver 172.16.0.1

172.16.0.1 is the IP address of the nameserver where BIND9 is installed


5.2  Test the name resolution using nslookup

$nslookup www.rasul.ph

The response should indicate 172.16.0.1

$ nslookup 172.16.0.1

The response should indicate www.rasul.ph


5.3  Alternatively, you can also test name resolution using host command

$ host www.rasul.ph

The response should indicate 172.16.0.1

$ host 172.16.0.1

The response should indicate www.rasul.ph

At this point, your master DNS server installation is complete. 


6.  On occasions, there may be a need for you to restart, stop and start the BIND9 software.  This can be achieved by issuing the following command:

To restart the server, issue the command

# systemctl restart bind9.service


To stop the server, issue the command

# systemctl stop bind9.service


To start the server, issue the command

# systemctl start bind9.service


7.  The BIND9 software runs under the process called "named".  To see if the process is running, issue the command

# ps ax | grep named

You should be able to see the "named" process as running as follows:

11305 ?        Ssl    0:00 /usr/sbin/named -f -u bind
11313 pts/0    S+     0:00 grep --color=auto named


If the process is not running, display will just be as follows:

11219 pts/0    S+     0:00 grep --color=auto named


8.  Should there be a need for you to uninstall the BIND9 software, issue the command after stopping the BIND9 service as follows:

# systemctl stop bind9.service
# apt-get remove bind9

This will uninstall the BIND9 software.