02 Mar 2012

Enable mod_status for CAKEPHP

I’ve been trying to isolate a CPU issue for an app running on Apache2 written with Cakephp. Apache has a module to monitor the server status with mod_status. http://www.debian-administration.org/article/Monitoring_Apache_with_mod_status

For Apache 1.2 enable mod_info and restart apache.

sudo a2enmod info
sudo /etc/init.d/apache2 restart

You should also enabled ExtendedStatus.

sudo vi /etc/apache2/conf.d/extendedstatus

Add the following

ExtendedStatus On

Once the module is enabled you have to enable the settings in the appropriate vhost in /etc/apache2/sites-enabled

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost ip6-localhost
</Location>

The problem if you are using cakephp is that the .htaccess will try to route the request which will fail. You have to edit your .htaccess file to look like the following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !=/server-status
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
30 Oct 2009

Apache Virtual Hosts (XAMPP)

apache

I had to create a couple virtual hosts on a windows 7 machine running XAMPP for development purposes. This is typically a simple task. XAMPP has an Apache virtual host configuration file in <xampp installation>\apache\conf\extra\httpd-vhosts.conf

There are some basic containers already set that you can use as reference, but in the end you have something like this:

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
	DocumentRoot D:/www
	ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1:80>
	DocumentRoot D:/www/mysite
	ServerName mysite.dev
</VirtualHost>

You then just configure your hosts file to point to your local IP address:

127.0.0.1    localhost
127.0.0.1    mysite.dev

You can add more directives to the virtualhost, but this was just the basic setup to get urls working without having to use subdirectories like http://localhost/mysite. Instead, I can use http://mysite.dev.

Restart apache and everything should be golden, but no, never quite that easy. I kept getting a blank screen for mysite.dev, but localhost was working. I would ping mysite.dev and get 127.0.0.1 like I would expect.

Well, long story short, I’ve behind a proxy/firewall and didn’t tell my browser to ignore the .dev domain. So, for my own purpose when I forget this again in a year or so, or anyone else behind a corporate network that may have a similar issue, this was why.