Monday, April 5, 2021

Simple Betta Tank Setup Guide

The Siamese Fighting Fish (Betta splendens), also known as the "Betta", is a freshwater fish native to Thailand (formerly Siam) and present in neighboring Cambodia, Laos, Malaysia, Indonesia, and Vietnam. While commonly known and marketed in the global aquarium trade as the "Betta", it is one of 73 species in the genus Betta. Betta fish are among the most popular and widely available aquarium fish in the world, due to their varied and vibrant colours, diverse morphology, and relatively low maintenance.

Betta Fish
Betta Splendens

Betta fish, especially the males, are usually aggressive in nature and are best kept separated from each other by using mesh separators or by keeping only one fish in a nano tank. Sorority tanks are possible with a group of female Betta fish but it requires experience and careful planning of the aquascape, and are not recommended for beginners. This article explores the setup of a simple nano tank with a single male Betta fish.

The Betta is a freshwater fish which thrives in shallow streams and rice paddies in Thailand with temperatures ranging between 75 and 82 degrees Fahrenheit or 24 and 28 degrees Celsius. The water should be clean and dissolved ammonia & nitrates should be as low as possible with the pH ranging between 6.5 and 7.5. The Betta primarily feeds on small insects in the wild and is considered to be carnivorous with regard to its diet. If properly kept, a Betta fish can survive for 5-7 years although, in captivity, it usually survives for 2-3 years only. Unlike most other fish, the Betta fish has a special organ called the labyrinth which allows it to survive by inhaling oxygen from the surface of the water. Although this means that the Betta fish can survive for extended periods of time without a filter, it is not recommended to do so. A filter is highly recommended to keep the water clean and healthy for the Betta. Care must be taken to ensure that the flow rate of the filter is not too high as Bettas like slow moving or stagnant water. A flow rate of 4x-5x the tank size is considered to be good enough for a Betta fish. If the Betta experiences difficulty in swimming due to its extended and flowery fins, we may use natural obstacles such as rocks and/or plants to slow down the flow of water. Bettas are also considered to be good jumpers. Hence, it is necessary to put a lid or net on top of the aquarium. However, if the water quality is good and the fish is not stressed, it is unlikely to jump. A tank size of around 5 gallons is considered to be the minimum necessity for a Betta fish. Bettas can survive in smallers tanks, bowls or vases for a short period of time but it will not lead a happy and healthy life.

betta koi nemo halfmoon plakat
Nemo Candy Plakat

There are several varieties of Betta fish in the aquarium trade, mostly classified on the basis of their tail types, finnage and colour: Veil Tail, Crown Tail, Comb Tail, Double Tail, Spade Tail, Half Moon, Over Half Moon, Delta, Elephant Ear, Plakat, Candy Nemo Plakat, etc. Of these varieites, the Half Moon, Over Half Moon, Delta, Elephant Ear and Plakat varieties are most popular.

Plakats are, in general, more aggressive than the Betta Splendens and should be handled with care. A good diet, clean water and plenty of hiding spots with live plants are absolutely essential for a Betta fish to thrive. In this article, we shall explore the basic setup only, without live plants. The selection and planting of plants in a Betta tank shall be explored in detail in a separate article.

For our setup, we have taken a glass cuboid of the following dimensions: 12 inches in length, 12 inches in breadth and 8 inches in height (5 gallons). Considering the water surface to be an inch below the top edge, this translates to roughly 4.3 gallons or 16 litres of water. Fine black gravel has been chosen as the substrate as it makes the Betta's colour stand out while red lava rocks have been used for the hard scape to create a contrasting view. White vinyl has been used as the background for the tank. Fine black gravel and porous red lava rocks not only create a visually pleasing aquascape but also serve as excellent media for biological filtration. For filtration and aeration, we have used a suitably sized Hang on Back (HOB) filter to keep the water clean through mechanical and biological filtration. A 10 Watt full spectrum LED light provides sufficient illumination for this nano tank.

To kick-start the fishless Nitrogen cycle, we must first add a few pellets of fish food into the tank full of filtered water. Seachem Prime is used to dechlorinate the water in the new tank. Any other fish-safe dechlorinator would work equally well. This is followed by the addition of a one-time recommended dose of suspended bacteria solution such as Seachem Stability or Aquatic Remedies Microlife S2 or Prodibio BioDigest. Any product is fine as long as it is within the expiry date mentioned on the bottle. Care must be taken to ensure that the filter is always kept running as it helps in aeration and colonisation of beneficial bacteria. After 7 days, change 50% of the tank water and replace it with fresh dechlorinated and filtered water. Release the Betta fish into the tank and keep the lights off for the day so as not to stress him in his new environment. Add the recommended dose of suspended bacteria solution to the tank to keep ammonia and nitrites low and also to help the growth of beneficial bacteria in the biological media (filter pad, lava rocks & gravel). For the next 7 days, we must change 30-40% of the tank water daily followed by the addition of fresh dechlorinated water and bacterial suspension. Do not over-feed the Betta. 4 micro pellets of Betta food (Hikari Betta Bio-Gold) twice a day is sufficient to keep the fish healthy and active. By this time, the tank would be 2 weeks old. Reduce the water change frequency to twice a week while ensuring the same precautions; dechlorinated filtered water and bacterial suspension. Continue this for the next 2 weeks.

By the end of 1 month, the tank should be mature and the beneficial bacteria should have colonised the filter media and lava rocks. However, if we do not use any bacterial suspension, it may take 2-3 more weeks for the tank cycling to be complete. When in doubt, test the levels of ammonia, nitrite and nitrate with any available fresh water test kit (API). From the 5th week, we may further reduce the water change frequency to once a week. Adding an Indian Almond Leaf to the tank shall further improve the water quality and make the environment better for the Betta. Indian almond leaves leach tanins which have fantastic medicinal properties and can cure a variety of bacterial and fungal diseases. It also helps to lower the pH of the water which makes dissolved ammonia less harmful for the fish. You can further beautify the tank by adding live plants such as Anubias Nana Petite and Java Moss. Live plants beautify the tank, clean the water by absorbing nitrates and provide shelter and shade for the Betta. We shall explore the choice of plants in greater detail in the next article. The following video shows the full nano setup at a month's maturity.

https://youtu.be/WR2f5Vre6XM

Monday, June 15, 2020

How does job security impact employee performance?

What is job security? Simply put, it may be defined as the probability that an individual will retain his/her job. The higher the job security, the less likely a person is to lose his/her job. In fact, several studies have indicated that job security is directly related to employee satisfaction. Having higher job security means reduced stress about having to arrange for a steady flow of income, which translates to happier and more satisfied employees who enjoy better health and an improved life-style.

Although it sounds really encouraging and promising, it may be worthwhile to explore the impact that job security has on employee performance. It is an important parameter in the socio-economic cycle since employee performance contributes to an organization's success and has a direct bearing on its efficiency and profitability. If the organization is successful and is able to sustain growth and maintain profitability, it will lead to creation of wealth and more employment opportunities. However, if efficiency or profitability declines, it is only a matter of time before the organization wades into a downward spiral which shall not only put existing jobs at risk but may also result in bankruptcy and eventual shutdown. This shall affect not only those who are presently employed by the organization but also those prospective future employees who might have got an opportunity to earn a livelihood if the organization had been able to sustain its profitability.

It is, therefore, imperative to ensure that an organization's efficiency and profitability are not compromised by assuring unfaltering job security to its employees at the cost of efficiency and performance. Rather, job security should be directly tied with employee performance. If an employee is hard-working and performing well, then he/she should be rewarded with adequate job security and compensation. However, if performance degrades, then job security and compensation should be adjusted accordingly. In other words, job security should be based purely on performance and not taken for granted.

Job security leads to complacency which, in turn, gives rise to inefficiency and poor performance. If an individual has the assurance that he shall never lose his job, he shall gradually lose the urge to work, innovate and learn. This behaviour is embedded in human nature. Soon, the employee shall become unproductive and lethargic. A sense of lethargy and a lack of responsibility shall be evident in the ways of working. This shall not only impact the individual's own performance but shall also serve to demotivate his/her colleagues and peers. Productivity shall decline and organizational performance shall be adversely impacted. The truth of this hypothesis lies in the performance of almost all government organizations in India and several other countries. Prominent organizations and government enterprises such as Air India, BSNL, MTNL, DRDO, HAL and SAIL are some glaring examples. The same lackadaisical attitude towards work is evident even in public sector banks, municipal and civic bodies, various government offices and state-run transportation services.

On the contrary, private organizations and multi-national companies are extremely efficient and productive. Individuals are motivated, eager to learn and willing to work hard. The difference is evident in the high efficiency and profitability of these organizations. So what is different? There is no dearth of talent or qualified individuals in India. Why, then, do we see a drastic difference in attitude? Employees working in public sector companies are usually apathetic to their customers. They do not care to offer quality products and services to their customers and do not adhere to committed timelines and budget. They are indifferent to criticism and have no urge to improve. The reason behind this indifference is guaranteed job security. Public sector employees are aware that come what may, they shall never lose their job. This sense of security provides the excuse and opportunity to not perform their duties properly and, as a result, the entire society suffers. Corruption and inefficiency become rampant and these unfortunate but contagious traits of human nature gain root among the masses. What follows is the overall degradation of public services and social responsibility.

It is, therefore, imperative that the concept of unconditional and guaranteed job security be removed from all layers of government and public sector enterprises. This does not, however, mean that large-scale privatization and disinvestment is the only solution. It is necessary to keep key industries, organizations and services under government control for the safety and security of the nation. The probable solution, therefore, would lie in taking away unconditional and assured job security across the board from all levels of government controlled enterprises and organizations. Job security should be directly linked with performance and a continuous feedback process should be adopted to urge individuals to continuously improve their knowledge and performance. Job security should be used as a control parameter to motivate employees and improve their efficiency without violating human rights in the name of productivity.

It is time to revisit our age-old principles of job security and reassess them in the context of global competition, providing better services and sustaining economic growth.

Monday, April 20, 2020

MySQL Database Connection from Host to Guest Virtual Machine

MySQL is a relational database management system which is popularly used in web applications and other light-weight software systems. In this article, we shall walk through the process of connecting to a MySQL database server running on a guest operating system inside a virtual machine.

Install MySQL Workbench on the host machine (Ubuntu 18.04 LTS):

sudo apt install mysql-workbench

Check the Firewall status on the guest virtual machine (Ubuntu Server 18.04 LTS) and verify if port 3306 (default port for MYSQL) is open for accepting connections to the database:

sudo ufw status

sudo ufw allow 3306

Change MySQL configuration on the guest vm:

cd /etc/mysql/mysql.conf.d

sudo vi mysqld.cnf

Comment the following line which allows incoming connections on port 3306 only from the same localhost on which mysql server is installed (guest vm):

#bind-address = 127.0.0.1

Restart the MySQL database service on the guest vm:

sudo /etc/init.d/mysql restart

Associated MySQL Commands:

sudo /etc/init.d/mysql start – Start the MySQL database.

sudo /etc/init.d/mysql stop – Stop the MySQL database.

Launch the MySQL Workbench application on the host machine:

Set up the database connection:

Test the database connection from Workbench.

Error:

Host '192.168.56.1' is not allowed to connect to this MySQL server

Create a new database user which can connect to the database from any host or amend the root user's grants to allow it to connect from any host.

CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password AS '***'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

Test the database connection again from MySQL Workbench.

Monday, March 16, 2020

LEMP Stack Setup Guide with Firewall and FTP Configuration

The Complete LEMP Stack Setup Guide For Beginners (Download PDF)

LEMP Stack Setup

L – Linux (Ubuntu 18.0.4 LTS)

E – NGINX (NGINX 1.14.0)

M – MySQL (MySQL 14.14 Distribution 5.7.29)

P – PHP (PHP7.2)

Pre-requisites

1 VPS Server: 4 GB RAM, 2 vCPU (AWS), 100 GB Hard Disk

OR

1 Virtual Box machine: 4 GB RAM, 100 GB Hard Disk

Virtual Box Installation

Download and install the Virtual Box setp for Ubuntu Linux (64-bit).

virtualbox-6.0_6.0.16-135674~Ubuntu~bionic_amd64.deb

Download and install the Virtual Box extension pack for the corresponding software version.

Oracle_VM_VirtualBox_Extension_Pack-6.0.16.vbox-extpack

Ubuntu (64-bit) OS Installation

Download the iso image file for the preferred version of Ubuntu Linux Server Edition.

ubuntu-18.04.3-live-server-amd64.iso

Note:

  1. The server edition does not have a GUI interface.
  2. Create a new virtual machine. Open its settings and select the storage option.
  3. Click on Controller IDE and add an optical drive (left-most circular button).
  4. Select the Ubuntu iso image file and save all settings.
  5. Start the virtual machine to initiate the installation process.

The iso image shall be automatically unmounted at the end of the installation process.

LEMP Stack Installation

1. Start the VM and login to the server instance.

2. Create a non-root user account (matrix) with sudo privileges.

root user privileges

home directory structure

3. Install the NGINX web server.

In order to display web pages to our site visitors, we are going to employ Nginx, a modern, efficient web server. All of the software used in this procedure will come from Ubuntu’s default package repositories. This means we can use the apt package management suite to complete the necessary installations.

sudo apt update

sudo apt install nginx

On Ubuntu 18.04, Nginx is configured to start running upon installation.

Check if the ufw service is running on the server. ufw is the Ubuntu Firewall system.

ps-ef|grep ufw

sudo ufw status

4. If not enabled, enable ufw as follows:

sudo ufw enable

5. If we have the ufw firewall running, we will need to allow connections to Nginx. Since we have not yet setup SSL on our VM, we only need to allow traffic on port 80.

sudo ufw allow 'Nginx HTTP'

Check the status of ufw.

sudo ufw status

6. Check if the NGINX web server is running by accessing the ipaddress of the Guest OS (VM) from a browser on the Host OS.

ifconfig

OR

ifconfig|grep inet

inet 192.168.1.8 (dynamic ip address of VM)

Type this ip address from a browser installed on the Host OS.

If we see the above page, we have successfully installed Nginx.

Note: Please ensure the VM adapter type under network settings is set to Bridged Adapter.

Select an appropriate adapter name and test by accessing the ip address of the VM.

Set Promiscuous Mode to Allow All. (Not mandatory)

Restart the NGINX server: sudo systemctl restart nginx

Stop the NGINX server: sudo systemctl stop nginx

Start the NGINX server: sudo systemctl start nginx

Check NGINX version: nginx -v

7. Install the MySQL database server.

sudo apt install mysql-server

8. Secure the MySQL installation

sudo mysql_secure_installation

Error encountered.

Fix: Start the MySQL database service.

/etc/init.d/mysql start

Re-run the security script.

Do not activate the component: VALIDATE PASSWORD PLUGIN

Set the database root password: <Specify a strong password>

  • Remove anonymous users.
  • Disallow remote root login.
  • Remove the test database.
  • Reload privilege tables.

Stop the database: /etc/init.d/mysql stop

Check database status: /etc/init.d/mysql status

Check the authentication string.

sudo mysql (logs in without prompting for password)

SELECT user,authentication_string,plugin,host FROM mysql.user;

Default authentication for root is set to auth_socket.

This enables greater security than using a password but may complicate things when using an external program such as phpMyAdmin.

Change the authentication method to mysql_native_password.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<enter password>';

Run FLUSH PRIVILEGES; from the MySQL prompt which tells the server to reload the grant tables and put the new changes into effect.

Sometimes, due to a MySQL bug, the alter user operation may not succeed. In such a scenario, remove the quotes around the ‘root'@'localhost’ string.

https://bugs.mysql.com/bug.php?id=86523

ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY '<enter password>';

(MySQL is case-insensitive. However, on some system and setup tables, case-sensitive commands may be required. In such a situation, run the same command in lower-case alphabets.)

Verify the authentication method after running the flush statement.

sudo mysql shall no longer allow automatic login. We have to login with a password.

mysql -u root -p

9. Install PHP and configure NGINX to use the PHP processor.

We have Nginx installed to serve our pages and MySQL installed to store and manage our data. However, we still do not have anything that can generate dynamic content. This is where PHP comes into play. Since Nginx does not contain native PHP processing like some other web servers, we will need to install php-fpm, which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.

Depending on our cloud provider, we may need to add Ubuntu’s universe repository, which includes free and open-source software maintained by the Ubuntu community, before installing the php-fpm package.

sudo add-apt-repository universe

Install the php-fpm module along with an additional helper package, php-mysql, which will allow PHP to communicate with our database backend. The installation will pull in the necessary PHP core files.

sudo add-apt-repository universe

sudo apt install php-fpm php-mysql

We now have the LEMP stack components installed. However, we need to make a few configuration changes in order to tell Nginx to use the PHP processor for dynamic content.

This is done at the server block level (server blocks are similar to Apache’s virtual hosts). To do this, open a new server block configuration file within the /etc/nginx/sites-available/ directory.

cd /etc/nginx/sites-available/

ls -ltr

Take a back-up of the default configuration file in the home folder of the logged-in user. The default file is the default server block (site) of the NGINX server.

The default root location from where NGINX servers files is /var/www/html.

A symbolic link is present in the sites-enabled folder.

Whatever server block file is available in the sites-enabled folder shall be treated as an active website.

10. Test the configuration by creating a PHP file.

Create a php file called info.php with the following contents:

<?php

phpinfo();

?>

sudo nano info.php

Place it in the /var/www/html folder.

Error: The info.php file is prompted for download instead of showing the php server information.

Check the version of php-fpm running: ps -ef|grep php

Check the status of php7.2-fpm: sudo systemctl status php7.2-fpm

Test the NGINX configuration file for syntax errors: nginx -t

Several errors are listed. Check with: sudo nginx -t

Error: unexpected end of file, expecting ";" or "}" in /etc/nginx/sites-enabled/default:92

Check the NGINX php settings.

cd /etc/php/7.2/fpm

The php.ini file is our concerned file. No change required.

Edit the default server block file: /etc/nginx/sites-available/default

Uncomment the following 4 lines:

location ~ \.php$ {
include snippets/fastcgi-php.conf;

and

fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; // Check version

and

} // This is very critical. Do not miss. It shall throw errors in ‘nginx -t’ command if left uncommented and php shall not work properly.

Restart the NGINX service: sudo systemctl restart nginx.service

OR

sudo systemctl restart nginx

Check nginx config erros again: sudo nginx -t

Check the url: http://192.168.56.102/info.php

PHP is working fine if the above page is displayed. After testing, remove this file as it may provide valuable information about your configuration to unauthorized users who may use it to hack into your system. This file should not be present in Production systems: sudo rm /var/www/html/info.php

Enable Shared Folders between Host and Guest OS

Enabled shared folders. Virtual Box: Devices --> Shared Folders

  • Specify the full directory path to be mounted.
  • Select Auto-mount
  • Select Make Permanent

Auto-Mount through Virtual Box Manager

In case we enabled auto-mounting on creating a shared folder from the Virtual Box Manager those shared folders will automatically be mounted in the guest with mount point /media/sf_<name_of_folder>. To have access to these folders users in the guest need to be a member of the group vboxsf.

sudo usermod -aG vboxsf userName

The guest will need to restart to have the new group added.

Note: In certain cases, the auto-mount feature may not work due to system bugs or version incompatibility. In such situations, please setup and use ftp for file transfer.

Monitor System Usage

top (RAM and CPU utilization)

OR

free -m

OR free -h (h – human readable format)

OR

watch -n 5 free -m (refresh data every 5 seconds)

OR

watch -n 5 free -h

df -k . (Disk space utilization)

Set a static ip adress for the virtual machine (Virtual Box)

Open Virtual Box --> File --> Host Network Manager

Click on Create to add a Host-Only network.

Click on Properties.

Note the Ipv4 and Network Mask addresses.

DHCP Enable check-box is kept unchecked by default. Leave it unchanged. Close the window.

Note: The host computer’s ip address (connected to dyamic ip-based router) shall not match the ip address of the guest virtual machine. The guest ip address may change after every reboot. Hence, we need to set a static ip address of our choice to proceed with the configuration of web and database servers on our virtual machine.

Select the virtual machine in the Virtual Box Manager window. Click on Settings – Network.

Adapter 1 should already be set up. Select Adapter 2.

Fill out the settings as shown below. Here, we specify the host-only adapter that we created earlier.

Enable Network Adapter: Checked

Attached to: Host-only Adapter

Name: vboxnet0 (Created earlier)

Other values should be pre-filled. Leave them unchanged.

Start the virtual machine.

ifconfig -a

This shows the network interfaces and ports. We shall work with the second one: enp0s8

sudo vim /etc/network/interfaces

Quit the file without making any change. In Ubuntu 18.04 (Bionic) we use netplan instead of network interfaces.

cd /etc/netplan/

ls -ltr

check the already existing files.

We need to configure the *.yaml file for a static ip address.

Take a backup of the original file.

Switch to root user: sudo su

cp -rp 50-cloud-init.yaml orig-config.yaml

Check all interfaces.

ip link show

We shall now configure orig-config.yaml and set enp0s8.

vi orig-config.yaml

Make the necessary changes as shown below:

addresses: [192.168.56.102/24] // 102 is the variable part. 24 is the range of ip(s) available.

dhcp4: no

gateway4: 192.168.56.1 // Noted earlier

Save the file and exit. Restart the network service.

sudo netplan apply

Check the changes in ip address.

Test by pinging the guest server from the host machine.

ping 192.168.56.102

Not pinging. Restart the virtual machine and test again.

The virtual machine (guest) can now be successfully pinged from the host machine.

Check if the NGINX web server can be accessed from the host machine by typing the static ip address.

The static ip configuration has been successfully tested.

Setup ftp server on host and guest OS

Check for existing installed ftp processes:

dpkg -l|grep ftp

Install the ftp server:

sudo apt-get install vsftpd

Check sftpd server status after installation:

sudo service vsftpd status

The above screenshot shows the vsftpd service running on the host machine.

If the service is not active, please start it as follows:

sudo service vsftpd start

Test the connection with: ftp localhost

Login should be successful. Perform the same installation steps on the guest os as well.

Check the firewall status in the guest machine and allow ftp access from the host machine to the guest machine.

sudo ufw status

sudo ufw allow ftp

sudo ufw status

Test ftp access from the host machine to the guest machine.

Note: Host-Only adpater is enabled in the Virtual Box network configuration. The specified static ip address may be used to connect to the ftp server.

Enable write access in the guest machine through ftp.

sudo vim /etc/vsftpd.conf

Uncomment the following line: #write_enable=YES

Save and quit the file.

sudo service vsftpd restart

Transfer a file from the host machine to the guest machine.

Common ftp commands:

ls – List the direectory contents in the target ftp server.

cd – Change directory in the target ftp server.

lcd – Change directory in the source (local) server.

(m)put – Write/transfer file(s) to the target ftp server.

(m)get – Read/Transfer file(s) from the target ftp server.

bye – Exit the ftp prompt.

bin – Switch to binary mode; suitable for binary-content transfer.

ascii – Switch to ASCII mode; suitable for text-content transfer.

Check if the file transfer has been successful in the guest machine.

Note: ftp access through the static ip address might not work if the host machine is connected to the wifi router for internet connection in bridged adapter mode. In such a situation, use the other dynamic ip address which is shown by the following command: ifconfig|grep inet

Install phpMyAdmin for LEMP on Ubuntu

phpMyAdmin is a browser based GUI interface to manage and operate MySQL databases.

sudo apt-get update

sudo apt-get install phpmyadmin

Press tab and do not select either Apache or Lighttpd. Select OK and hit enter to continue with the installation.

Select Yes and hit Enter.

Enter the root password for the MySQL database installed earlier.

Re-enter the database root password to confirm and and continue with the installation.

We shall need to create a symbolic link between phpMyAdmin and the site’s root directory. If we are using the NGINX default root directory, use the following command:

sudo ln -s /usr/share/phpmyadmin/ /var/www/html

Test by accessing the url: http://192.168.56.102/phpmyadmin

Error: 403 Forbidden

Check the folder permissions of /usr/share/phpmyadmin/ and /var/www/html/. This should be fine by default and no change is necessary. If not, rectify the same.

cd /etc/nginx/sites-available/

sudo vi default

Add index.php as a supported index in the site config file.

Save the changes and quit. Restart the NGINX web server.

sudo systemctl restart nginx

Test the public-ip-address/phpmyadmin URL again. The phpMyAdmin login page should be displayed.

Login with user id as ‘root’ and the associated password.

Default list of user accounts as visible in phpMyAdmin:

Warning noted in import section of phpMyAdmin.

This warning is usually encountered when an older version of phpMyAdmin is configured with a more recent version of PHP.

Solution:

1) Download the latest version of phpMyAdmin and update the software.

OR

2) Make a small editin a config file to forcibly type cast an array data type with the count function.

File name: /usr/share/phpmyadmin/libraries/plugin_interface.lib.php

Search and find the following line:

if ($options != null && count($options) > 0) {

Change it to the following:

if ($options != null && count((array)$options) > 0) {

Login to phpMyAdmin and test the import option again.

Try to import a database into MySQL through phpMyAdmin.

Error: 413 Request Entity Too Large

We have to edit the NGINX configuration file to allow an upload of larger file size. The following changes shall increase the file upload size for all server blocks.

cd /etc/nginx/

sudo vi nginx.conf

Add the following line in the http section:

client_max_body_size 15M;

Save and quit. Reload the NGINX configuration. Restart is not necessary.

sudo systemctl reload nginx

Login to phpMyAdmin and re-attempt the import operation.

Error:

We now have to change the PHP settings for maximum file upload size.

cd /etc/php/7.2/fpm/

sudo vi php.ini

Update upload_max_filesize to 15M.

Update post_max_size to 15M.

Save and quit. Reload php-fpm.

sudo systemctl reload php7.2-fpm

Re-attempt the database import operation.

Error: 504 Gateway Time-out

This usually happens if the database import file is large in size and can be fixed by suitably increasing the NGINX time-out values.

MySQL database operations

mysql -u root -p

create database knowhowspotdb;

create user ‘khuser’@’localhost’ identified by ‘<enter password>’;

use knowhowspotdb;

grant all privileges on knowhowspotdb.* to ‘khuser’@’localhost’;

exit

cd /home/matrix/ftpbase

sudo apt install unzip

unzip a1034c7b8_knowhowdb_2020-01-24_10-13-50.sql.zip

mysql -u khuser -p knowhowspotdb < a1034c7b8_knowhowdb_2020-01-24_10-13-50.sql

Note: Ensure that the sql dump has been ftp’ed in binary mode and not in ascii mode.

Setup NGINX Server Blocks (Virtual Hosts)

When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server.

Nginx, on Ubuntu 18.04, has one server block enabled by default. It is configured to serve documents out of a directory at /var/www/html. This shall work well for a single site. However, we shall need additional directories if we want to serve multiple sites. We can consider the /var/www/html directory as the default directory that will be served if the client request does not match any of our other sites.

We will create a directory structure within /var/www for each of our sites. The actual web content will be placed in an html directory within these site-specific directories.

sudo mkdir -p /var/www/knowhow.com/html

The -p flag tells mkdir to create any necessary parent directories along the way.

We shall now reassign ownership of the web directories to our normal user account. This will let us write to them without sudo.

Note: Depending on our needs, we may need to adjust the permissions or ownership of the folders again to allow certain access to the www-data user. Dynamic sites will often need this.

sudo chown -R $USER:$USER /var/www/knowhow.com/html

We are using the $USER environmental variable to assign ownership to the account that we are currently signed in (Please ensure that we are not logged in as root). This will allow us to easily create or edit the content in this directory.

Copy the website’s files inside the html folder of the target site.

cd ~/ftpbase

cp -rp knowhowspot.zip /var/www/knowhow.com/html

unzip knowhowspot.zip

Now, we have to create a server block file for knowhow.com. Let us start by creating a copy of the default block file.

cd /etc/nginx/sites-available

sudo cp default knowhow.com

Edit the knowhow.com server block file.

sudo vi knowhow.com

Remove the commented lines.

Remove the default_server tags.

Update the file root path to /var/www/knowhow.com/html.

Update the server_name tag to include knowhow.com and www.knowhow.com.

Save and close the file. The final server block configuration file should look as shown below.

Now that the server block file is created, we have to enable it by creating a symbolic link from this file to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/knowhow.com /etc/nginx/sites-enabled/

The knowhow.com server block shall respond to requests for knowhow.com and www.knowhow.com. We can create more server blocks for multiple and different websites. The default server block shall respond to any request on port 80 that does not match any enabled server block.

In order to avoid a possible hash bucket memory problem that can arise from adding additional server names, we will go ahead and adjust a single value within our /etc/nginx/nginx.conf file.

sudo vi nginx.conf

Within the file, find the server_names_hash_bucket_size directive. Remove the # symbol to uncomment the line:

# server_names_hash_bucket_size 64;

Save and quit the file.

Check for NGINX syntax errors.

Restart NGINX: sudo systemctl restart nginx

Modify the local host’s file for testing. This will not allow other visitors to view our site correctly, but it will give us the ability to reach each site independently and test our configuration.

sudo vi /etc/hosts

Add the following entry in a new line:

192.168.56.102 knowhow.com www.knowhow.com

Save and quit the file.

This will intercept any request for knowhow.com and www.knowhow.com and send them to our server, which is what we want if we do not actually own the domains that we are using for testing purposes.

Test the website by accessing the following url in the browser of the local host machine (outside vm):

http://knowhow.com OR http://www.knowhow.com

Error: 404 Not Found

Edit the server block configuration file for knowhow.com.

In the location block, change the following:

try_files $uri $uri/ =404;

to

try_files $uri $uri/ /index.php?q=$uri&$args;

Save and quit the file. Restart NGINX server.

The first try_files directive means that if a file or directory does not exist, the web server shall throw a 404 error. The second directive redirects all requests to index.php. This is commonly used for software packages such Drupal, Joomla and Wordpress.

Test the website again: http://knowhow.com or http://www.knowhow.com

We can add as many different sites as we want on the same server, subject to performance constraints due to capacity. For each website, we need to create a separate server block file similar to knowhow.com under /etc/nginx/sites-available. For every new server block, amend the root path and server_name to host each website’s files in its separate directory structure.

Example: If we want to host an additional website called kitchen.com, the server block for that website should look something as shown below.

We must also ensure that the necessary symbolic link is created in the /etc/nginx/sites-enabled directory in order to activate the new website.

Restart the NGINX server after the new server block is enabled. For testing purposes, we need to add an additional entry in the /etc/hosts file in the local host machine.

Access the newly configured website from the browser of the local host machine: http://kitchen.com

If configured successfully, the new website should get displayed as shown below.

This completes the LEMP stack setup process on Ubuntu Linux.