Posts Tagged ‘apache’

Debugging Apache segmentation faults

Monday, October 13th, 2008

I haven’t used this extensively, but worth documenting for future reference:

# /etc/init.d/httpd stop
# gdb /usr/sbin/httpd
GNU gdb Red Hat Linux (6.5-37.el5_2.2rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
 
(gdb) run -X

At this point, go ahead and hit the site in an attempt to reproduce the segmentation fault. Once you’ve got a segmentation fault (it should return you to the (gdb) shell), run:

(gdb) backtrace

That should hopefully give you some indication as to where the segmentation fault is happening.

Update: You can also ‘bind’ to a running process by doing:

# gdb -p <pid>

Retain site's hostname w/ mod_rewrite

Monday, August 18th, 2008

Let’s say you want to apply a rewrite rule to several domains, while retaining the site’s hostname when redirecting. Something like this seems to work:

RewriteEngine on
RewriteRule ^/panel https://%{HTTP_HOST}:8443 [L]

Now if only I could figure out why this doesn’t work when not embedded within a VirtualHost directive.

Running two instances of Apache on one machine (CentOS)

Tuesday, August 12th, 2008

I haven’t put this into production, but I tested it and it seems (so far) to work OK. First off:

# cp -a /etc/httpd /etc/httpd2
# cp -a /etc/init.d/httpd /etc/init.d/httpd2
# cp -a /etc/sysconfig/httpd /etc/sysconfig/httpd2
# ln -s /usr/sbin/httpd /usr/sbin/httpd2

I then added the following to /etc/sysconfig/httpd2:

HTTPD=/usr/sbin/httpd2
OPTIONS="-f /etc/httpd2/conf/httpd.conf"
LOCKFILE=/var/lock/subsys/httpd2
PIDFILE=/var/run/httpd2.pid

Some things in /etc/init.d/httpd2 need to be changed:

if [ -f /etc/sysconfig/httpd2 ]; then
        . /etc/sysconfig/httpd2
fi

Finally, I modified the following in /etc/httpd2/conf/httpd.conf:

PidFile run/httpd2.pid
Listen 8080

Starting /etc/init.d/httpd fires up httpd and binds to port 80 and starting /etc/init.d/httpd2 fires up httpd2 and binds to port 8080.

Note, I had to symlink /usr/sbin/httpd2 to /usr/sbin/httpd so that the process name changes which allows each to be killed off independantly.

Update: A customer asked about apachectl which reminded me that I had forgotten to take that into account. What you can do is:

# cp -a /usr/sbin/apachectl /usr/sbin/apachectl2

… and then change these lines:

if [ -r /etc/sysconfig/httpd2 ]; then
   . /etc/sysconfig/httpd2
fi

Update: I’ve made a few minor changes, as some things were documented incorrectly. :)

Automatic creation of vhost.conf files on Plesk

Wednesday, July 2nd, 2008

It’s quite straight-forward. Create the directory /var/www/vhosts/.skel/0/conf and then create a file called vhost.conf in it containing something like this:

<directory /var/www/vhosts/vhosts/@domain_name@/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/@domain_name@:/tmp"
</directory>

The domain being provisioned here gets referenced as @domain_name@.