Today there was a poignant posting about I.T. certifications. Consider donating to money when you go to cyberciti.biz or the nixCraft Patreon website. The content has helped many professionals over the years.
How Do You Configure Two Linux Guest Servers Running on Oracle VirtualBox to Have Network Connectivity with Each Other?
Problem scenario: On a Windows host you have Oracle VirtualBox. You want to establish TCP/IP connectivity with the two guest CentOS Linux virtual servers. When you try to ping one from the other, you get "destination host unreachable." The servers have Internet connectivity. How do you get them to communicate with each other via a networking protocol?
Solution
On each guest server, do the following:
1. Using the GUI of the Oracle VirtualBox guest server, go to Devices -> Network Settings.
a. Changed the drop down for "Attached to:" to be "Internal Network."
b. Make sure "Promiscuous Mode" is set to "Allow VMs" or "Allow all"
c. Click "OK."
2. Back up this file on both guest servers: /etc/sysconfig/network-scripts/ifcfg-enp0s3
3. Modify /etc/sysconfig/network-scripts/ifcfg-enp0s3
a) Make sure the "BOOTPROTO=" stanza is "BOOTPROTO=static"
b) This is just an example to get the two Linux guests to work. Other IP addresses may work.
For one guest, use the following entries underneath "BOOTPROTO=static":
IPADDR=10.0.2.15
NETMASK=255.255.255.0
GATEWAY=10.0.2.2
For the other guest, use the following entries underneath "BOOTPROTO=static":
IPADDR=10.0.2.17
NETMASK=255.255.255.0
GATEWAY=10.0.2.2
4. After you modify the file, issue this from the command line: service network restart
5. Now one guest should be able to ping or ssh to the other via the 10.0.2.1x IP address configured above.
Optional reading
How Do You Connect to a VM in Oracle VirtualBox from a Desktop?
How Do You Find the Amount of RAM Your Linux Server Has in GB?
Problem scenario
You want to find the total RAM a Linux server has. You do not want the number to be in kilobytes. You want human-readable output. What do you do?
Solution
Run this command:
free -g | grep Mem | awk '{print $2 " gigabytes of RAM total (sum of in use and available combined)"}'
If the amount of GB is less than 0.5, the result of the above command will show as 0 GB of memory. In that case, you can find out how many megabytes of memory the server has with this command:
free -m | grep Mem | awk '{print $2 " megabytes of RAM total (sum of in use and available combined)"}'
How Do You Install PostgreSQL on an EC2 SUSE (AWS Instance of Linux SUSE)?
Problem scenario
You want to install Postgres on Linux SUSE. This AWS server is in a security group with the ability to get to the Internet. How do you install PostgreSQL on it?
Solution
1. Log into the SUSE server with the default ec2-user. The default user for AWS SUSE instances used to be root. But now it is ec2-user.
2. Run these five commands (taken from https://wiki.postgresql.org/wiki/Zypper_Installation):
zypper addrepo -t YUM http://packages.2ndquadrant.com/postgresql-z-suse/zypper/sles-11sp3-s390x pg
zypper refresh
zypper addrepo -t YUM http://packages.2ndquadrant.com/postgresql-z-suse/zypper/sles-11sp3 pgsrc
zypper refresh
zypper install postgresql94-server
3. Now you are ready to start the Postgres service. Run this command:
/sbin/service postgresql start
4. You are done. For future knowledge, AWS security group rules have a "PostgreSQL" type that allow connections to servers over port 5432. If you are configuring a SQL front end from a Windows desktop to your SUSE instance, this rule in your security group is necessary.
How Do You Write a Backend PHP Script to Query Postgres and Create a Database Name “foobar”?
Problem scenario
You are running Ubuntu Linux, and you want to create a .php script to be ran at the command prompt like this:
php good.php
You want this to open a PosgreSQL connection and issue a DDL command to create a database. This is not a PHP web page.
Solution
This solution is only slightly more complicated than using PHP to run a basic SQL query in a Postgres database.
1. Go to the command prompt of PSQL. These commands may help you:
sudo -i -u postgres
psql
2. Create a role from the psql command prompt. Here is an example:
create role orangeuser;
3. Alter the role to have the login trait and superuser attribute.
alter role orangeuser login superuser;
\q
4. Install php5-pgsql or php7.0-pgsql. It depends on your version of PHP. Use this command to find out what version of PHP you have: php --version
To install the php pgsql package on Ubuntu, you should run a command like one of these as root: apt-get install php5-pgsql
apt-get install php7.0-pgsql
5. Create a .php file (e.g., cool.php) with the following as the content:
/* This assumes your server with PHP has access to the server with Postgres. The IP address in the script is the local loopback. You may have to change the IP address for this to work. Naturally you will have to change the database name, the user and password in the PHP script to the credentials for your Postgres instance. */
<?php
$host = "host=127.0.0.1";
$port = "port=5432";
$dbname = "dbname=contint";
$credentials = "user=jdoe password=softpassword";
$db = pg_connect( "$host $port $dbname $credentials" );
pg_query("CREATE DATABASE foobar");
?>
6. Run it like this: php cool.php
If you want to write a front-end web page to execute a SQL command, see this posting:
How Can You Accept User Input with PHP and Use It in a SQL Command?
How Can PHP Accept Data from a Form and Assign It to Variables for Future Retrieval?
Problem scenario
You want a web page to request user input. After the user clicks "Submit" you want the values to be assigned to variables for future usage (e.g., an algorithm could retrieve the values to manipulate them). How do you use PHP to assign input from a web page to be variables on the back end?
Solution
You need two files. The first one will be a form to obtain data from an external source (user-entered data). You need a PHP web page like this (cool.php) to obtain data passed in:
<form action="contint.php" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="text" name="password" /><br />
<input type="submit" name="submit" value="Submit me!" />
</form>
//Change contint.php to the name of the second .php file you will use.
Here is the content of the second .php file you will use (e.g., contint.php)
<?php
if ($_POST) {
echo '<pre>';
$var1 = $_POST["username"];
$var2 = $_POST["password"];
echo '</pre>';
}
?>
//Now $var1 is the value the user entered in "Username."
//Now $var2 is the value the password entered in "Password."
How Do You Troubleshoot the PHP Error “role is not permitted to log in” So Your Script Can Log into a Postgres Database?
Problem scenario
You are trying to use a .php script on the back end to connect to your PostgreSQL database. However, you get an error like this when you try to run it:
'PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: role "funuser" is not permitted to log in in /tmp/d.php on line 7'
How can your .php script log into the Postgres database?
Solution
The user must have the ability to log in. Log into the PostgreSQL database. Run this command (where "funuser" is the database role that is hardcoded in the PHP script for the login to work):
alter role funuser login;
How Do You Troubleshoot a PHP Error “call to undefined function pg_connect()” So Your Script Can Log into a Postgres Database?
Problem scenario
You are trying to use a .php script on the back end to connect to your PostgreSQL database. However, you get an error like this when you try to run it: 'PHP Fatal error: Call to undefined function pg_connect() in '
Solution
Install php5-pgsql. For Ubuntu you would run a command like this: sudo apt-get install php5-pgsql
How Do You Fix “Scanning Plug and Play compliant hardware” Message That Does Not Go Away?
Problem scenario
Flash drives and USB ports are not working properly in Windows. You are not able to use a variety of working USB sticks. These flash drives have files that you need. When you go to Device Manager and right click "Universal Serial Bus controllers" or other sub-devices, you see this error "Scanning Plug and Play compliant hardware." It never goes away. The Device Manager window becomes stuck.
How do you get your USB devices to work properly?
Solution
1. Physically remove USB devices from your computer.
2. In Windows, go to Device Manager and expand "Universal Serial Bus controllers"
3. For each device you see under "Universal Serial Bus controllers," right click each one and go to "Uninstall." After they have all been uninstalled there will be no "Universal Serial Bus controllers" option in Device Manager. This is what you want.
4. Reboot your computer. You are done.
Advertising
When computers are malfunctioning, they remind you of the importance of backing up data. Click on this for a USB stick that is great for travel. Click on this for an external USB hard drive.
Could you use a new USB device? We can provide some ideas. If you want a USB splitter, buy this USB 3.0 version here. Click on this for a camera. Click on this for an iPod. Click on this for a scanner. Click on this for a printer. This keyboard is great for travel, and it is compatible with Windows 7, 8, and 10. You may want the white version because it could be easier to see in a suitcase. Click here for a lightweight wireless mouse. You may want to browse affordable, mid-level, or expensive laptops on Amazon. You may want a new desktop computer; for an affordable option, see this one. For a very high end desktop, you may want to click on this link.
How Do You Find the PID when You only Know It by the Task Name in the Task Manager?
Problem scenario
You have an application (in Windows) running, and you want to terminate it with PowerShell. You want to find running program's PID. But you only know its name in Task Manager.
How do you obtain the Process ID (identification number) of a program (or application) in Windows when you only know the Task Manager name of the program (or application)?
Solution
1. Open Task Manager (e.g., Ctrl-Shift-Escape)
2. Right click the name of the Task as you see it in the "Applications" tab. Click "Go to Process."
3. You will now be highlighting the process. Go to View -> Select Columns and check the "PID (Process Identifier)" option.
4. Now you should see the "PID."
5. If you want to terminate this application, open PowerShell as Administrator.
6. Issue this command from the PowerShell command prompt: kill xxxx
(where xxxx is the PID)