March 12, 2008

CSS and Javascript files not showing up when running Apache under Ubuntu on a flash drive? Read on

home server
I hate to reveal the extent of my geekiness, but would like to spare others the hours I spent debugging a problem I ran into last night running Apache 2 under Ubuntu from a flash drive. I run a number of web applications on a home server I have set up that uses a flash or pen drive for its filesystem, an unusual configuration, but one that gives me a silent fan-less server that can run 24/7 in my home office, which also doubles as our guest bedroom.

This week I decided to upgrade the server from an ancient version of Knoppix running Apache 1.3 and PHP4 to Ubuntu 7.10 running Apache 2.2 with PHP5. I followed the excellent directions at PenDrive Linux, and had the new system up and running in about an hour.

However, when I started upgrading my applications and installing them on the new system, I started running into problems where CSS stylesheets and Javascript files were not applied to pages. When I tried to load the CSS stylesheets directly into the browser, Firefox would display a blank page. IE would offer to download them, but then download nothing. I checked the error and access logs, but didn't see anything unusual. I tried a google search, but didn't find anything that seemed on topic. I thought of permission problems, which I always run afoul of in Linux, but after messing around with that for an hour or so, I concluded that wasn't it. Then I thought it might be different line endings, but that turned out not to be the case. Then I thought it might be Apache 2 configuration, which is significantly different with Apache 2 on Ubuntu than it was with the Apache 1.3 that I am used to, so I messed with that a while, without any luck. I did learn new information about permissions, line endings, and Apache 2 configuration, so it wasn't totally wasted time, but it was pretty frustrating.

I finally spent an hour googling around, running into my fellow Berkeley web geek Scot Hacker reporting a simular problem (but no solution) in 2004 with Apache 2.0 with Mandrake Linux. I finally ran across this post on a forum:

OK success! I upped the loglevel to "debug" in httpd.conf. When trying to access images the following messages appeared in error_log:

(38)Function not implemented: core_output_filter: writing data to the network

A google search later and I found the following explanation of this error:

"Apache uses the sendfile syscall on platforms where it is available in order to speed sending of responses. Unfortunately, on some systems, Apache will detect the presence of sendfile at compile-time, even when it does not work properly. This happens most frequently when using network or other non-standard file-system. Symptoms of this problem include the above message in the error log and zero-length responses to non-zero-sized files. The problem generally occurs only for static files, since dynamic content usually does not make use of sendfile. To fix this problem, simply use the EnableSendfile directive to disable sendfile for all or part of your server. Also see the EnableMMAP, which can help with similar problems."

After setting "EnableSendfile off" in httpd.conf and restarting httpd it works as it should.

Following that post lead me the Apache doc about sendfile and more useful information on the Apache Wiki, with this wonderful quote:

Regrettably, there are occasions where sendfile will be found at compile time but not work when Apache tries to use it. This happens, in particular, when serving files from certain network file-systems (NFS or SMB, for example) or other non-standard file-systems.

I guessed that my flash drive might be one of those "regrettable" non-standard filesystems, so I added "EnableSendfile off" to my Apache2.conf file. Bingo, all my stylesheets were applied. Problem solved.

Lessons learned:


  • When debugging, never be afraid to increase the depth of reports in the logfiles. If I had seen the "Function not implemented" error in the logfiles, I would have been able to find the solution in minutes.

  • Google is your friend. Spending more time at the beginning trying to refine my search, which is what I eventually did, might have found me the solution a lot earlier.

  • If you have an unusual configuration, expect to run across unusual problems. That is part of the price of doing things differently.

  • Linux and DIY are about learning. While this is not how I planned on spending 4-6 hours, I now know a lot more about the internal workings of Ubuntu and Apache than I did yesterday.

  • I am a geek. But you knew that.

Posted by tbishop61 at March 12, 2008 11:09 PM | TrackBack