Two More Apache Tweaks Required After Ubuntu 10.04 Upgrade

While I was troubleshooting why Apache stopped serving php apps from my home directory, I ran into two more annoyances that required attention. I figured I’d share them as well in case you run into them yourself.

Here’s what I saw when I reloaded Apache:

jkendall@san-diego:/etc/apache2$ sudo /etc/init.d/apache2 reload
  * Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri Apr 30 13:47:38 2010] [warn] NameVirtualHost *:80 has no VirtualHosts
                                                                                    [ OK ]

As you can see, Apache reloaded fine, but I don’t like seeing anything other than [ OK ] when I’m reloading my web server. Let’s tackle these one at a time.

Could not reliably determine the server’s fully qualified domain name

Why is Apache all of a sudden complaining about what’s worked for so long? I’m not sure exactly, but thankfully the fix was simple and easy. Simply adding “ServerName localhost” to /etc/apache2/httpd.conf took care of the first complaint (Big thanks to Mohamed Aslam for his clear instructions on how to get this fixed.).

NameVirtualHost *:80 has no VirtualHosts

The problem boiled down to having NameVirtualHost defined in more than one place. In my case, NameVirtualHost was defined both in /ect/apache2/ports.conf and /etc/apache2/sites-available/default. Commenting out the NameVirtualHost *:80 line in /etc/apache2/sites-available/default did the trick (Thanks to the guys in this Server Fault thread, especially to Ivan, for providing the necessary clues to track this one down.).

After making the above changes, reloading Apache didn’t throw any more warnings. w00t!

Upgrading to Ubuntu 10.04 Breaks Serving php from Home Directories

I upgraded to Ubuntu 10.04 this morning and immediately noticed I could no longer serve php applications from my home directory. When I tried to visit one of my projects, http://test.local for example, Firefox opened a download dialog with a message similar to “You have chosen to open index.phtml . . .”

After quite a bit of googling and forum searching, I went to Twitter asking for help. Many thanks to @sypherNL for helping me resolve this one.

It seems that something has changed in /etc/apache2/mods-enabled/php5.conf. If you’re experiencing this same issue, check your php5.conf and see if it matches mine.

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

If your php5.conf file looks like the one above, simply comment out the

<IfModule mod_userdir.c>

lines as instructed. Once that’s done, restart apache with the following command:

sudo /etc/init.d/apache2 reload

Clear your browser’s cache and try to visit your site again. I didn’t think the fix took at first, but after clearing cache everything worked just fine.

Related Links

DIY Network Monitoring and Logging with Perl

The Problem

I’ve been having trouble with my AT&T DSL installation here at the new place. My internet connection will come and go, seemingly at random, and for random amounts of time. I tweeted about it once already, hoping that sharing my frustration with the world might make me feel a little better. Nope. Didn’t work.

I’ve had this problem before with AT&T, when I got DSL installed at my last place. Things were rough for a while, and then somehow they seemed to straighten out on their own. I’m not crossing my fingers that I’ll have such luck again.

What’s Really Going On?

I decided to try and log the bounces so that I could get a better feel for what was going on. I couldn’t find exactly what I wanted online (and I couldn’t always get online), so I whipped up a Perl script to keep an eye on my connection for me.

#!/usr/bin/perl
 
#
# Test AT&T DSL connectivity. If network is down, log to file
# Will use log info as ammo when I call tech support.
#
 
use warnings;
use strict;
use Log::Handler;
use Net::Ping;
use Sys::HostIP;
 
my $log = Log::Handler->new();
 
$log->add(
    file => {
        filename => "/var/log/testNetwork.log",
        mode     => "append",
        maxlevel => "info",
        minlevel => "warning",
    }
);
 
my $ipAddress          = Sys::HostIP->ip; 
my $matchHomeNetworkIp = ($ipAddress =~ /^192\.168\.10\.\d{1,3}$/);
 
if (!$matchHomeNetworkIp) {
    $log->debug("Current IP $ipAddress does not appear to be on your home network. Exiting");
    exit;
}
 
my $router = "192.168.10.1";
my $modem  = "192.168.1.254";
my $host   = "www.yahoo.com";
 
my $p = Net::Ping->new("icmp");
 
if (!$p->ping($router)) {
    $log->warning("Router $router is unreachable. Exiting.");
    exit;
}
 
if (!$p->ping($modem)) {
    $log->warning("Modem $modem is unreachable. Exiting.");
    exit;
}
 
if ($p->ping($host, 2)) {
    $log->info("$host is reachable");
} else {
    $log->warning("$host is NOT reachable");
}
 
$p->close();

Code Review

While the code is simple, there are a couple of things to note. First, you’ll notice I’ve baked my router’s IP range into a regex that will tell me if I can even get that far. If not, there’s no point in checking anything else, so I exit.

Next I fire up Net::Ping. While there are six different options for Net::Ping->new(), the only one that worked for me was icmp. Icmp requires root privileges to run, so keep that in mind.

Next I ping important parts of the home network. I want to be sure that my wireless router and the DSL modem are both online before I try and ping an external site.

If everything looks good on the inside, I’ll ping an external site and see if I get anything back. You’ll notice that I’ve added a second parameter to ping this time. That’s the number of seconds I’ll wait for a response before failing (of course, it is possible that Yahoo! won’t respond to a ping request here and there, making it appear as if the network is down, but I’m not so worried about a false positive or two).

Implementation

Now that I’ve got this nifty script to tell me about the health of my network, I need a way to run it on a regular basis. It’s important to run it as root because of the icmp ping. Cron was the obvious solution, as it’s purpose is to run commands on a predetermined schedule. As long as I add the script to root’s cron file, it’ll run with root permissions. Sweet!

Adding my script to the root cron file was as easy as issuing

sudo crontab -e

and adding the following line:

*/1 * * * * perl /home/jkendall/dev/perl/util/testNetwork.pl

With my cron file in place, my script fires off every minute. As long as I’m on my home network, I’ll get a log entry telling me whether or not the network is up.

Keeping an Eye on the Results

Now that my script is actually doing something, I need to be able to parse the results. A quick

tail -f /var/log/testNetwork.log

allows me to keep track of the results as they come in. I’m also using grep to pull all of the “NOT reachable” lines out of the log file with

grep -n --color "NOT reachable" /var/log/testNetwork.log

I could always just open the log file and read through it from top to bottom, but what fun is that? A decent tool to parse the fail log is going to be necessary, but I haven’t whipped it up yet.

Teh Suck

As I’ve been writing this blog post, I’ve been running this script in the background. Here are the results of an hour or so of logging (all times are CDT):

Oct 27 21:03:33 [INFO] www.yahoo.com is reachable
Oct 27 21:04:03 [WARNING] Router 192.168.10.1 is unreachable. Exiting.
Oct 27 21:05:02 [INFO] www.yahoo.com is reachable
Oct 27 21:06:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:07:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:08:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:09:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:10:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:11:02 [INFO] www.yahoo.com is reachable
Oct 27 21:12:01 [INFO] www.yahoo.com is reachable
Oct 27 21:13:01 [INFO] www.yahoo.com is reachable
Oct 27 21:14:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:15:32 [INFO] www.yahoo.com is reachable
Oct 27 21:16:01 [INFO] www.yahoo.com is reachable
Oct 27 21:17:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:18:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:19:11 [INFO] www.yahoo.com is reachable
Oct 27 21:20:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:21:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:22:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:23:03 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:24:01 [INFO] www.yahoo.com is reachable
Oct 27 21:25:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:26:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:27:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:28:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:29:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:30:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:31:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:32:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:33:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:34:21 [INFO] www.yahoo.com is reachable
Oct 27 21:35:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:36:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:37:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:38:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:39:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:40:12 [INFO] www.yahoo.com is reachable
Oct 27 21:41:01 [INFO] www.yahoo.com is reachable
Oct 27 21:42:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:43:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:44:31 [INFO] www.yahoo.com is reachable
Oct 27 21:45:01 [INFO] www.yahoo.com is reachable
Oct 27 21:46:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:47:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:48:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:49:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:50:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:51:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:52:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:53:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:54:01 [INFO] www.yahoo.com is reachable

Weak sauce, man. Weak sauce.

Wrapping Up

Having this script handy doesn’t make the fail any better, but at least I know a little more about what’s happening. I’d like to think it’ll give me some leverage when I try to get this worked out with AT&T, but who knows. I’ll let you know how it goes.

[Update: post title change to better reflect content]

My Contribution to the History Meme

From my work machine:

jkendall@ventura:~$ uname -a
Linux ventura 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686 GNU/Linux
jkendall@ventura:~$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
83 exit
70 clear
58 cd
47 ls
44 ps
35 svn
32 tail
32 jgrep
23 kill
11 sshdev

jgrep is a bash alias for 'grep --color -r -n --exclude=\*.svn\*', while sshdev is a bash alias that gets me to the dev box at work without having to type too much.

See more examples here, here, here, and here.

Dell 1420n Ubuntu Wireless Issue Resolved

A few months ago I picked up a Dell 1420n loaded with Ubuntu 7.10. I’ve really enjoyed the laptop, but I’ve experienced ongoing issues with my wireless connectivity. The laptop will connect to my wireless router without any problems. Staying connected to the wireless router was the problem.

After using the laptop for anywhere from 5 minutes to 36 hours, the wireless connection would drop. The only way to reconnect was to reboot the laptop. That got old fast, but being a new Linux user I had no idea how to troubleshoot the issue. I finally Googled the problem and, via this thread on the excellent Ubuntu Forums, I found the DellLinuxWiki and the answer to my problem.

The issue has something to do with the ipw3945 wireless module. The DellLinuxWiki entry suggests using the network module iwl3945 instead, and provides simple step-by-step instructions as to how to disable the ipw3945 module and how to enable the iwl3945 module.

The resolution works like a charm, and I haven’t had a wireless connectivity issue since.

IEs4Linux Blank Screen Bug and Installation Issues

If you want / need to install Internet Explorer in Linux, I highly recommend IEs4Linux by Sérgio Lopes.

IEs4Linux is the simpler way to have Microsoft Internet Explorer running on Linux (or any OS running Wine).

I recently purchased a new Dell 1420n with Ubuntu 7.10 pre-installed. One of the first things I wanted to do was install all of my development tools, including IEs4Linux. What should have been an easy installation turned into a nightmare. I kept running into python errors that aborted the install. Once I finally got the application to install it was unusable. The IE toolbar was missing, including the address bar, the application would frequently crash, and I experienced maddening display bugs.

Apparently the blank screen bug has been a widespread issue. Sérgio has addressed it on his blog and pushed an emergency release of IEs4Linux, version 2.99.0.1, to resolve this issue only.

That’s all well and good, but I still had the python issues to deal with. What finally worked for me was to install IEs4Linux with the –no-gui flag, like so:

$ ./ies4linux --no-gui

For more information on installing IEs4Linux, including IE versions 5 and 5.5, visit the IEs4Linux installation page.

Mail Notification 5.0 with SSL in Ubuntu

The Problem

We recently began using SSL to connect to IMAP at work. Prior to switching to SSL I had been using the excellent Mail Notification to let me know if I had any messages in my inbox. As soon as we switched over to SSL, Mail Notification quit alerting me to the presence of new email.

I figured that all I had to do was change my preferences in Mail Notification and select SSL. Turns out I was right, except I couldn’t select SSL – all of the “SSL/TSL” options were grayed out. Why in the world would that be? After some research I discovered that:

  • SSL isn’t available if the package was built without SSL support (makes sense)
  • The OpenSSL license conflicts with the Debian license

Mail Notification is available in the Ubuntu repository, but without SSL support. Bummer.

Build it Yourself

The resolution is to build Mail Notification with SSL support enabled, but I quickly discovered that building Mail Notification was not as easy as I thought it would be. Although the installation is well documented in the INSTALL file, I still ran into a lot of problems with dependencies.

Dependencies Required

After a lot of troubleshooting and not a little frustration, I came up with a list of dependencies that I needed installed in order to configure and make Mail Notification 5.0 on Ubuntu Gutsy:

  • build-essential
  • gnome-core-devel
  • libnotify-dev
  • libgnome2-dev
  • libgmime-2.0-2-dev
  • libssl-dev

I used the Synaptic Package Manager to install each of these dependencies. Read on if you’re looking to troubleshoot a specific error that you’re running into.

Errors and Troubleshooting

The first time I ran

$ ./configure

I got this error:

checking for C compiler default output file name... 
configure: error: C compiler cannot create executables
See `config.log' for more details.

Installing build-essential took care of the C compiler issue, but I found a new one the next time I ran configure:

Error: checking for GNOME... no
configure: error: unable to find the GNOME libraries

This one drove me a little batty. What does it mean it can’t find the GNOME libraries? I’m running GNOME for Pete’s sake! After a decent amount of hair pulling and a seemingly endless amount of Googling, I finally found that gnome-core-devel, libnotify-dev, and libgnome2-dev resolved the

unable to find the GNOME libraries

error.

Next up was the GMIME error:

checking for GMIME... configure: error: Package requirements (gmime-2.0 >= 2.1.0) were not met:
 
No package 'gmime-2.0' found

At least by now I was making it most of the way through the

configure

process. I found that installing libgmime-2.0-2-dev resolved the issue, finally allowing me to complete the configuration.

Of course, the whole point was to build Mail Notify with SSL support. What do you think I found when configure finally ran all of the way through? Down at the bottom of the options list, I saw this:

--enable-ssl                 no (OpenSSL not found)

By now, I had started seeing a pattern: look up the dependencies, find their dev libraries, install their dev libraries, and voila, on to the next issue. With that in mind, I installed libssl-dev and ran

$ ./configure

one last time. Mail Notify configured without errors and with SSL support. A quick

make

and

make install

later and I had a Mail Notify 5.0 installation complete with SSL support.

Other Options

There seem to be a lot of different ways to skin this particular cat. The solution above is what worked for me, your mileage may vary. You may find it useful to refer to the discussion in this related bug report for background.

For another way to resolve this issue, you might try “How to make a small change to a Debian tool and repackage it.” I didn’t find this article until after I had resolved the issue myself, but it looks like it might be a lot simpler.