Feb 23

Apache Virtual Host (httpd restart – fail)

Tags:

Alas, I had Just created ServerTheory.com and imagine how excited I was!  There were only a few things that I needed to do in order to make this happen.  I needed to register the domain name, create DNS entries, point my new domain name to the correct DNS servers, and make sure all of the files were in place on the server itself. You would think that I had this down after doing it a kagillian times (that’s a lot), but my five minutes of creation turned into about ten minutes of troubleshooting… and here’s my short story  🙂

———– THE PROCESS ———–

  1. Register servertheory.com (check)
  2. Create DNS entries (check)
  3. Change name servers for servertheory.com (check)
  4. Create a new folder /var/www/html/servertheory.com (check)
  5. Change permissions to the folder (check)
  6. Create the log file locations /var/log/httpd/servertheory.com  (optional, but check)
  7. Append the httpd.conf file for the new virtual host (check)
  8. Restart the httpd service …. restart the httpd service … why do I get [failed] instead of [OK]?!?!?!

————- THOUGHT PROCESS ————–

First of all, if I was in a rush to get this up and running, I would be somewhat perturbed that it didn’t work the first time.  Since I was in no rush at all, I enjoyed the thought of being able to troubleshoot and learn… so let’s see what happened.

The first thing that I did was think through what I had just done.  There were eight  steps in the process… any of which I could have screwed up.  But no glaring mistakes stood out in my mind.  Therefore, I switched to the 50/50 method of troubleshooting.  Let’s eliminate half of the things that it could be before moving on to the other half.

In this case, I figured it was the server and not the DNS entries (because it was the httpd process that was broken), so that eliminated the outside factors.  So I move to the localhost.  After configuring the domain for the nameservers, I moved on to creating folders that would house both the webpage itself and the log files associated with it.  Each of these folders that I created were called servertheory.com.

The first folder created was servertheory.com inside of /var/www/html to house the webpage files.  The second was servertheory.com inside of /var/log/httpd to house error_log and access_log.  You can see both of these inside the <VirtualHost> entry of the httpd.conf file.

——————- HTTPD.CONF ———————-

<VirtualHost *:80>

ServerAdmin fitz@servertheory.com
DocumentRoot “/var/www/html/servertheory.com”
ServerName servertheory.com
ServerAlias www.servertheory.com
ErrorLog “logs/servertheory/error_log”
CustomLog “logs/servertheory.com/access_log” common

</VirtualHost>

—————- QUANDRY —————

DO YOU SEE THE MISTAKE?

———————————————-

HERE’S WHAT IT SHOULD LOOK LIKE:

<VirtualHost *:80>

ServerAdmin fitz@servertheory.com
DocumentRoot “/var/www/html/servertheory.com”
ServerName servertheory.com
ServerAlias www.servertheory.com
ErrorLog “logs/servertheory.com/error_log”
CustomLog “logs/servertheory.com/access_log” common

</VirtualHost>

————- THOUGHT PROCESS ————–

STILL CAN’T SEE IT?  If you did, then you have a good eye.  Among all of those letters, sometimes it’s very difficult to see the simplest things.  Before I reveal what it was in this writing, I’ll show you the next thing that I did to confirm what I had suspected all along.  Here is the log file associated with Apache and the httpd service.  NOTE: Don’t confuse this with the log files that were created in the <VirtualHost> entries.

———- LOG FILE: /var/log/httpd/error_log ————

[Sun Feb 24 05:59:12 2013] [notice] caught SIGTERM, shutting down

(2)No such file or directory: httpd: could not open error log file /etc/httpd/logs/servertheory.com/error_log.

Unable to open logs

———– PROBLEM SOLVED / EXPLANATION ———–

Within the <VirtualHost> entry listed above, it was the ErrorLog line. I forgot to put the ‘.com’ after servertheory, so when I restarted the httpd service, I was receiving a [fail] message after looking for /var/log/httpd/servertheory.  The httpd error_log file says that there’s no such file or directory called servertheory.

So in the end, the httpd service was doing exactly what I told it to do.  Put the error_log file in a directory that didn’t exist.  By using the 50/50 method and narrowing the problem down, I was able to quickly determine that I made the mistake, not the computer.

——————————————————————–

I hope you enjoyed this little run down of the problem I had this afternoon.  Remember, in theory, log files are our most important treasure when it comes to server administration.  Know where they are, know how to use them, and know how to read them.  It can save you hours upon hours of troubleshooting!

—————————————–

Always remember… WHAT IF AND WHY NOT?!?