Restarting Apache on Gentoo

Normally, you can restart Apache using the restart command for the init.d script.

/etc/init.d/apache2 restart

However, you may encounter the following error.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Stopping apache2 ...[ ok ]
 * Starting apache2 ...
 * start-stop-daemon: /usr/sbin/apache2 is already running 

This is due to a bug in the init.d script. You can resolve this with a one line change.

vim /etc/init.d/apache2

Change line 105 for the one below (they should look very similar).

while ( test -f "${PIDFILE}" && pgrep -P ${PID} apache2 >/dev/null ) \

Save it and run the restart command again to check it has worked.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Caching service dependencies ...                                                                              [ ok ]
 * Stopping apache2 ...                                                                                          [ ok ]
 * Starting apache2 ...

If you get an output like the above, you’ll know it’s worked.

MaxClients (150) is not an integer multiple

Starting Apache on Gentoo, you may get warnings similar to the following.

chris@server ~/lime $ sudo /etc/init.d/apache2 stop
Password: 
 * Stopping apache2 ...
WARNING: MaxClients (150) is not an integer multiple
 of ThreadsPerChild (35), lowering MaxClients to 140
 for a maximum of 4 child processes,
WARNING: MaxClients (25) must be at least as large
 as ThreadsPerChild (35). Automatically
 increasing MaxClients to 35.                                                                                    [ ok ]
chris@server ~/lime $ sudo /etc/init.d/apache2 start
 * Starting apache2 ...
WARNING: MaxClients (150) is not an integer multiple
 of ThreadsPerChild (35), lowering MaxClients to 140
 for a maximum of 4 child processes,
WARNING: MaxClients (25) must be at least as large
 as ThreadsPerChild (35). Automatically
 increasing MaxClients to 35.

You can resolve these warnings by editing your mpm file and changing ThreadsPerChild so that MaxClients becomes a multiple of it. In this case, setting it to 25 should do the trick.

sudo vim /etc/apache2/modules.d/00_mpm.conf

Change the values and save the file. Now restart Apache and it should stop the warnings.

You could also change MaxClients, but this would only resolve the first warning, and not the second.

PHP complains date.timezone is not set

Sometimes, PHP will kick up a fuss complaining about date.timezone not being set. We found this on the Symfony framework and were able to replicate it on standalone scripts.

[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings.
You are required to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead

Normally, you would fix this by editing your php.ini file and adding a declaration there.

date.timezone = "Europe/Berlin"

But we had already done this and it still wasn’t working! After some further investigation, it seemed that PHP simply couldn’t access the value.

echo(ini_get("date.timezone"));

This doesn’t make any sense, and we never got to the bottom of what was going on, but there are two ways around the problem. Firstly, you could modify your PHP script so that it makes a call to set the system timezone.

date_default_timezone_set("Europe/Berlin");

However, this involves having to modify your code, which is bad as you don’t want to have to set the timezone manually, especially in a piece of code which could be deployed to servers in different timezones.

A better approach is to set it in the vhosts directive in Apache.

php_value "date.timezone" "Europe/Berlin"

This isn’t the cleanest solution but allowed us to solve an otherwise unexplainable error.

Using Apache Bench to load test your website

Apache comes with a cool load testing script called Apache Bench, which lets you throw loads of requests at a URL. It comes bundled with Apache, so if you’re running the LAMP stack, you probably already have it.

The syntax is simple.

ab -n 1000 http://www.google.com/

This will throw a thousand requests at Google and then produce a report on how long it look. You can also use the -c option to set the number of concurrent requests. There are lots more options too – see the Apache docs for full details.

ImageMagick, Apache and Debian

Following on from my previous post about installing ImageMagick from source, to get it working with Apache you need to do the following. First, we need to install something from Pecl. So make sure you have the pecl command at hand – if not, install it.

apt-get install pear

Then run the following.

apt-get install php5-dev
pecl install imagick

Finally, add the extension to your php.ini.

extension=imagick.so

Integrating SVN with Apache

If you want to allow access to SVN via Apache, it’s actually nice and easy to install and configure it on a blank system. First, install Apache.

yum install httpd httpd-devel httpd-manual

Next, install Subversion.

yum install subversion

Now we need to bridge he two.

yum install mod_dav_svn

Once you have done this, we have everything we need. So we can go ahead and edit the Subversion configuration to add the Subversion directory to Apache.

vim subversion.conf

Finally, start and reload Apache, then go about creating your SVN repository.