How Do You Comment out a Line in PHP?

Problem scenario
You want to try some .php scripts or web pages without certain lines of code.  How do you comment out an individual line?

Solution
Use this at the beginning of a line of code: //

Example:  //this text will do nothing in the .php script

To comment out multiple lines, use this at the beginning of the first line: /*
Then conclude the multi-line comment with this:  */

Example:

/*
   echo "                                                       ";
   $db = pg_connect( "$host $port $dbname $credentials"  );
   if(!$db){
      echo "Error : Unable to open database\n";
   } else {

EVERYTHING between the first forward slash and asterisk and the second asterisk and forward slash have been commented out.

*/

How Do You Troubleshoot Connecting to a Postgres Database When You Get the Error “FATAL: Ident Authentication Failed”?

Problem scenario
You are trying to establish a connection with a username and password to a Postgres database using PHP.  You have a PHP file like this:  

<?php
   $host        = "host=127.0.0.1";
   $port        = "port=5432";
   $dbname      = "dbname=contint";
   $credentials = "user=contint password=excellent";

   $db = pg_connect( "$host $port $dbname $credentials"  );
   if(!$db){
      echo "Error : Unable to open database\n";
   } else {
      echo "Opened database successfully\n";
   }
?>

Every time you run this above file, we'll call foo.php, you get an error.  You run this:

php foo.php

But this results in an error like this:

'PHP Warning:  pg_connect(): Unable to connect to PostgreSQL server: FATAL:  Ident authentication failed for user "contint" in /tmp/contint.php on line 7
Error : Unable to open database'

Your pg_hba.conf file has a stanza like this:

host     all    all    127.0.0.1/32    md5

You therefore think that because you are passing a username and password, the authentication should be successful.  The database's owner is the role (or username) that you are using.  You restarted Postgresql services.  Why do you keep getting this error?

Solution
Look in the /var/lib/pgsql/data/pg_hba.conf file.  You may find this stanza above the stanza with the "md5":

host    all    all    127.0.0.1/32    ident

Comment out the above line with "ident" using a # at the far left.  Try running the PHP script again.

The Latest News on The Law and Technology

The news below is focused on the legal issues of computing, intellectual property (copyrights, patents and trademarks), science and technology.  The external links are to reputable websites.

How Do You Troubleshoot Mounting a Vboxsf Folder Share on a Linux Guest Running via Oracle VirtualBox on a Windows Host?

Problem scenario:  You are trying to mount a file share using Oracle VirtualBox.  You have a Windows host and a Linux CentOS guest.  (For complete directions on how to set up a folder share for this scenario, see this link.) 

You are trying to run this command:  "mount -t vboxsf contint /mnt/windows-share"
# where "contint" is the name of the folder share in the Oracle VirtualBox GUI.  

But you get this error:

"/sbin/mount.vboxsf: mounting failed with the error: Protocol error"

How do you solve this apparent "Protocol" problem?

Solution
Verify the name of the folder share by going to the GUI for the guest VM.  Then go to Devices -> Shared Folders -> Shared Folder Settings.  In the window that pops up, see the "Name" column on the left.

Replace "contint" in the command with the name of the folder share as seen in the "Name" column.  The command should now work.

How Do You Get the Apache Web Service to Start after a Cold Reboot?

Problem scenario
You want the Apache web service to start automatically after a Linux server is rebooted.  You want it to start automatically when you turn on a Linux server (after being off completely).  On Linux CentOS you have this entry in /etc/crontab:

@reboot            root         apachectl start

You notice that on reboots (warm or soft) it works.  But when you turn on your server after it has been off, this entry does not start Apache web server.  You tried creating a Bash script (making it executable too) in /etc/init.d with this command: "apachectl start".  Despite these things, the Apache web service does not reliably start when you reboot or turn the server on.

How do you get Apache web server to automatically start when the CentOS server is turned on (after a cold or hard reboot)?

Possible Solution #1
As root, issue this command:  chkconfig httpd on

This solution will start the Apache web service automatically when either of the following two things occur: one, when the server is turned on from being off completely (hard or cold reboot).  Two, when the server was warmly (aka softly) rebooted.  

Possible Solution #2
It may be preferable to use "sudo chkconfig httpd on" without being root.  Test it to see if it works on your system.

How Do You Get Apache Web Service to Start Automatically after a Reboot of a CentOS Linux Server?

Problem scenario  
You have to manually start Apache web server every time you do reboot the server.  You want the Apache web service to start automatically.

Solution
1.  Edit /etc/crontab.  Add the lowest line of these two (the line above is for reference):

# *  *  *  *  * user-name  command to be executed
@reboot         root       apachectl start

2.  Save the changes.  You are done.

This solution only works if you are doing a warm (or soft) reboot.  A start up from a turned-off machine will not have the Apache web service running because of this crontab entry.  A crontab would not be needed if your solution could allow the Apache web service to start automatically after a cold (or hard) boot up and a warm (or soft) reboot.  For a solution like this, see this link.

How Do You Fix a PHP Web Page when the Page Is Completely Blank?

Problem scenario
Using a web browser you go to a PHP web page.  There are no errors, but the page is blank.  It is just all white, but you expect content to be rendered (e.g., text should be visible).  The WSOD (white screen of death) is a common problem to troubleshoot in a web browser.  What do you do to see output you want it to display?  

Solution
1.  Did you forget a semicolon ";"?  Some tags or HTML sections can make even a careful programmer's brain skip over a line that needs a semicolon.  Go to the source .php file.  Look for a missing semi-colon at the end of a line.  Omitting a closing semi-colon can make the page render just white.  Add the semi-colon on the line that needs it.  Save the file.  Go back to the browser and refresh the page.  Remember that a semi-colon may appear at the end of a line, but if it is after a closing brace "}", you may need a semi-colon before the terminating close brace.  If you accidentally forgot a semicolon or commented one out, this could cause the page to be blank.

2.  Did you forget a closing brace?  With conditional statements (e.g., iffor, or while), there needs to be a closing brace.  If you accidentally forgot one or commented one out, this could cause the page to be blank.

3.  See if there is an extra <?php in your code.  An unclosed <?php string (with no corresponding ?>) can render a PHP page blank or white.

4.  See if there is an extra */ in your code.  An unopened */ two-character string (with no corresponding /*) can render a PHP page blank or white.  Alternatively, an unclosed multi-line comment opener /* can also cause this problem.

5.  If you are using pg_query commands, are you using a variable?  If so, the variable expansion of the SQL query should have no quotes in the variable itself.  Normally you'll see something like this:

pg_query("select * from goodtable;");

The above works.  However, if you want to have a variable for your pg_query, it should not have double quotes.  It should be like this:

$query = 'select * from goodtable;';
pg_query($query);

6.  
Are you using session_start(), session_set(), or $_SESSION in your code?  These can be used improperly to cause a page to appear blank.  If you are using these functions, see this link.

7.  Did you forget to use session_start?  If variables are referenced later on that relied on this function call, your PHP page may be blank.

8.  The PHP variables (e.g., $varname) involved in the display were not assigned a variable (because of a typo in the code or either because of the result of a deterministic or non-deterministic algorithm).  If you tried to concatenate a variable but forgot to place a period ".", this can cause the entire page to be blank.  If you have a space where there should be a period, this variable assignment may cause the entire PHP page to appear white with no content.  If you have complex lines that you suspect are causing the problem, try commenting out specific lines to see if some content comes back (i.e., put "//" (with no quotes) before the line of PHP code.  This can help you narrow down a seemingly elusive problem.

9.  The page could be blank by design. Are you sure it is not supposed to be blank? Some PHP pages have no HTML to be presented. Examine the code and see if the intended rendering is actually not viewable. Maybe the web page (via the PHP code) is supposed to be blank as it is coded. If your PHP is showing the underlying code in a way that you do not expect (e.g., you see text or raw PHP code when you want to see a publicly presentable and beautifully-rendered web page), see this posting.

10. Is your PHP program using Linux Bash commands? If so, see this posting.

11. Try this link for more suggestions.

How Do You Place a Postgres Database on a Flash Drive on a Windows Host Running Oracle VirtualBox with a Linux Guest VM?

Problem scenario
You have Postgres installed on the Linux guest of Oracle VirtualBox.  You have storage capacity on the Windows host.  You can interactively work with smbclient to share files between the Linux guest and the Windows host.   You want to share files between the two servers without the interactive smb commands.  You want the Postgres database to reside on the Windows host.  This way your Linux guest hard disk does not have to be expanded but can run Postgres commands from your Linux guest.

How do you place a large Postgres database on a flash drive (or USB stick) on a shared folder on a Windows host running Oracle VirtualBox with a Linux guest VM?

Solution
There may be no definitive "best practice" way of doing this, but if there is insufficient space on the Linux guest running Oracle VirtualBox, you may want to configure the entire Linux guest to be on the flash drive itself.  In short, it may be advisable to create a new VM making sure that its files are on this USB stick.  This way the Postgres databases can be on the USB stick.

vboxsf is an Oracle VirtualBox technology that can present Windows folder shares for regular Linux operations.  However, mounting vboxsf file shares in Linux will not allow you to change the permissions of the directory as it is seen in Linux.  Postgres requires a data directory to have specific permissions.  Therefore it seems impossible as of February 2017 to have a data directory to reside on a Windows file share and work with Postgres that is installed on a Linux guest running on Oracle VirtualBox on a Windows host.  

When creating a new VM, do not accept the default location of the virtual hard disk.  Make sure the virtual hard disk is on the USB stick.  Warning:  installing even the minimal version of CentOS will take hours even if you are using USB 3.0 technology.  The I/O is slower with having a virtual disk on a USB stick.  But it is not unusable.  Installing the OS may be the most noticeable part.

How Do You Troubleshoot an Apache Web Service Problem when from a Web Browser You Receive the Error “The Address Is Restricted”?

Problem scenario
You are using Oracle VirtualBox on a Windows host.  You are using a Linux guest that is running Apache web server.  The Apache httpd service is running on the guest Linux server.  But when you are on the Windows host, you try to access the website, you get an error in the web browser.  This is the error you receive:

"This address is restricted
This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection."

What do you do to view the web page running on the Linux guest when you are on the Windows host?

Solution
Go to the back end.  Specifically go to the Oracle VirtualBox window for the server with the Apache service.  Go to Devices -> Network -> Network Settings -> Advanced -> Port Forwarding.  

Make sure that there is a rule that involves guest port 80 (or whatever non-standard port Apache web server is configured to use on the guest) and host port 80.  If you do not use host port 80 in your "Port Forwarding Rules", Firefox and Chrome will restrict the address. 

How Do You View the Website That Your Oracle VirtualBox Guest Server Is Presenting with a Web Browser on Your Windows Host?

Problem scenario:  You have a Linux VM guest running on Oracle VirtualBox.  You installed Apache web server on this server.  How do you browse to its website from your Windows host machine?

Solution

#1  Determine the host IP address as configured for the guest.  In Oracle VirtualBox go to Devices -> Network -> Network Settings.  For Adapter1 go to "Advanced" and click the button for "Port Forwarding." The host IP address may be 127.0.1.1.

#2  Open a web browser.  Go to the web page (e.g., http://127.0.1.1/index.html).  

Troubleshooting:  If you are still having trouble, review the steps below.

1.  Verify the file exists in the location you expect it to be. On the back end of the Linux server, use "find / -name httpd.conf"  The "DocumentRoot" stanza will show you which directory path on the Linux server to find the files.

2.  Use this command to see if the Apache web server is running: "ps -ef | grep httpd"
If you do not see a process running, try this command:

apachectl start

3.  Verify no firewall is blocking the connection between your Oracle VirtualBox client and host.  If you are not sure how to do this, you could use a PowerShell command or script on the host.  This posting can help you with that.  You could install nmap on the guest of the Linux server and use that.