Category: Apache

Information And Howtos About The Apache Web Server

Apache is an open source web server that runs on a variety of platforms including various UNIX flavours, Novell Netware and Microsoft Windows. It is used to run more websites on the Internet than any other webserver and has done so since 1996, as reported by the Netcraft Webserver Survey. The Apache webserver can be downloaded in binary and source form from the Apache website.

Force reload of updated CSS and Javascript files with unique filenames

When a CSS or Javascript file is changed the visitor’s browser needs to get the latest copy of the file to reflect the changes, but it will have been cached and may cause rendering or functionality issues depending on the changes. To force reloading of the CSS and Javascript file the files should be renamed each time they are changed; this can be automated by using PHP to add the timestamp of the file into the filename.

Read More »

Seg fault or similar nasty error detected in the parent process

One of the servers I manage runs CentOS 5.0 with Apache 2.2 and PHP 5.1.6, and uses PHP’s APC 3.0.14 (Alternative PHP Cache). We process the logs using AWStats every 15 minutes, and rotate the logs on a daily basis. However, after two or three days of working correctly, Apache would crash and we’d get the following in the log files: “seg fault or similar nasty error detected in the parent process”

After some amount of searching on the Internet, the only thing I could come up with was that there was a bug in the PCRE extension in older versions of PHP that would cause the same message to occur in the error logs. One of the posts indicated that this particular message is also a symptom for lots of other memory-type bugs in Apache, so I can only assume that it’s the use of APC which is causing the error.

The interesting thing is that if Apache is reloaded or reloaded with “graceful” a few minutes later, then there aren’t any segfaults. Again, I can only guess that the memory issue causing the segfault is due to issues with the memory caching over time.

The script that processes the logs with AWStats, and also rolls the logs on a daily basis is as follows:

#!/bin/bash
 
 if [ `date +%H%M` == 0600 ]
 then
 mydate=`date +%Y%m%d`
 cd /var/log/httpd
 mv mylog.log mylog.log.$mydate
 /sbin/service httpd reload
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig -LogFile=mylog.log.$mydate > /dev/null
 bzip2 mylog.log.$mydate
 else
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig > /dev/null
 fi

A quick summary of what this is: if it’s 6am in the morning, the current log file is renamed with the current day’s date (eg mylog.log.20070921), processed using AWStats, and then compressed with bzip2. At all other times during the day, just AWStats is called.

The error message that I got in the log files was as follows:

[Fri Sep 21 06:00:03 2007] [notice] SIGHUP received. ?Attempting to restart
 [Fri Sep 21 06:00:03 2007] [notice] seg fault or similar nasty error detected in the parent process

After the attempt to reload Apache and getting this error message, Apache failed to start up again. Calling “service httpd start” got it running again.

The solution I have found is to stop and start Apache. There may be some other way of sorting this memory issue with APC out but I was unable to find a solution for it. So the script now looks like this:

#!/bin/bash
 
 if [ `date +%H%M` == 0600 ]
 then
 mydate=`date +%Y%m%d`
 cd /var/log/httpd
 mv mylog.log mylog.log.$mydate
 /sbin/service httpd stop
 /sbin/service httpd start
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig -LogFile=mylog.log.$mydate > /dev/null
 bzip2 mylog.log.$mydate
 else
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig > /dev/null
 fi

Since changing it, I have had no further segfaulting issues.

Read More »

Apache – Permission denied: Failed to acquire SSL session cache lock

I’ve set up a CentOS 5 Apache web server for a customer where we run the web server as user different from the default user "apache" (often "nobody" is used as well). The application runs through SSL using mod_ssl, and when accessing SSL secured pages errors like these would appear in the error log:

"[Wed Nov 14 11:16:49 2007] [warn] (13)Permission denied: Failed to acquire SSL session cache lock
[Wed Nov 14 11:16:49 2007] [warn] (13)Permission denied: Failed to release SSL session cache lock"

Read More »

Overriding the AWStats LogFile Configuration Option

I run AWStats on one of my servers and it copies files over from some of the other servers I manage every 15 minutes and processes them. However, I had a server issue yesterday with the machine that AWStats runs on, and it meant the auto process which copies the files over and runs AWStats stopped running for about 12 hours. The end result was some lost information and needing to regenerate stats for the month to date. I needed to override the AWStats LogFile configuration directive on the command line to be able to do this.

Read More »

Installing mod_ssl on Apache on CentOS 5

I was moving a customer’s website from its old dedicated web server to a shiny new one, installing CentOS 5 on it with Apache 2.2 and MySQL 5.0. They already had a secure certificate running on the old site, so I copied the certificate files over and the secure server settings into the appropriate configuration file.

Read More »

PHP Error Class ‘SoapClient’ not found

I’ve often found that something gets left out or forgotten when moving a website from an old server to a new install. I’ve just finished migrating one of my customer’s sites to a new CentOS 5.0 install with Apache 2.2 and PHP 5.1.6, and there’s one single PHP script in the site which uses the SoapClient class.

Naturally I’d forgotten to test this particular function until after the migration was complete, and was wondering why the script had failed. A quick look in the Apache error log file revealed the following error message: PHP Fatal error: "Class ‘SoapClient’ not found"

Read More »

Installing AWStats on CentOS

AWStats provides a useful overview of website statistics from your Apache log files. There is no automatic way to install AWStats on CentOS using yum, so this article looks at how to install AWStats on CentOS. The instructions below should also work on other Linux distributions that do not have an automatic way of installing AWStats.

Read More »

Use of www in website addresses

Tim Berners-Lee is the creator of the "World Wide Web" and the www prefix used in so many website addresses was his "fault" 🙂 It made sense at the time to have a different prefix for domains for different services such as ftp, email, websites and more. However, websites came to use both the www and non-www prefix for accessing them (eg www.example.com and example.com) and the www part has therefore become somewhat redundant.

This article looks at why I use the www version of the domain name as the primary domain name for my websites, and redirect traffic from the non-www version to the www version.

Read More »

Changing Apache log rotation behaviour on CentOS / RHEL

On a default install of CentOS or Red Hat Enterprise Linux, the log rotation script will automatically rotate the Apache log file each day and then reload the httpd service. This post looks at how to prevent this action from occuring automatically, or to change the behaviour to rotate the log files if your naming convention for log files is different from the default.

Read More »