วันศุกร์ที่ 12 มีนาคม พ.ศ. 2553

วันพุธที่ 10 มีนาคม พ.ศ. 2553

Configuring gentoo apache with fcgi

mod php and worker are not stable as PHP official page.

Gentoo user might not aware this because we can compile PHP with threads use flag without realizing the warning.

Before get start with apache-worker fcgid and php. You need the following :
1) installed PHP with cgi use flag.
2) installed mod_fcgid (emerge mod_fcgid)

PHP configuration :
- modify /etc/php/cgi-php5/php.ini to suite your need.

apache configuration :
- modify /etc/apache2/modules.d/20_mod_fcgid.conf adding the following in
AddHandler fcgid-script .php .fcgi
DefaultInitEnv PHPRC "/etc/php/cgi-php5"

IdleTimeout 60
BusyTimeout 120
ProcessLifeTime 360
SpawnScoreUpLimit 2100
MaxProcessCount 2100
DefaultMaxClassProcessCount 2100
IPCConnectTimeout 120
IPCCommTimeout 120

FCGIWrapper /usr/bin/php-cgi .php

Please change the /usr/bin/cgi/ to your path. And don't forget to add +ExecCGI to option directive.

- edit /etc/conf.d/apache2 add -D FCGID to APACHE2_OPTS

restarting apache.

วันอังคารที่ 9 มีนาคม พ.ศ. 2553

Monit : debuging monit process

Misconfiguration on apache can lead monit false alet and do wrong action. I found that some monit process in one of my servers always complaining about apache cannot connect port 80. which is not right cause I can still access the pages.

Here are tip for debugging what goes wrong:

1) stop monit as a daemon
2) smart monit in foreground
#monit -Iv
3) see the message

From my experience, the server response with 403 http code cause monit alert cannot connect host port 80.
So, I change apache config to get 200 code and everything back to work :)

Monit : server monitoring tools

If you have a web server, have you ever experience apache process not responding to http request?

or

How to make sure that apache are running? and If server load go too high please restart it for me.

Monit can help you monitoring common for system admin.


It can monitoring server process, file size, memory server load. And, you can set the appropriate action to those events: sending email, restart process etc.

To install monit
for gentoo :
#emerge -av monit
for debian:
#apt-get install monit

Configuring monit
Locate configuration file : /etc/monitrc or /etc/monit/monitrc
Here is the example configuration for apache with these condition
1) check whether apache is running : if not restart
2) check http:80 is working : if not restart
3) if server go to high : restart apache process
set daemon 120

set mailserver smtp.localhost


set mail-format { from: admin@localhost.com }

set alert systemadmin@localhost.com


check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed port 80 protocol http then restart
if loadavg(5min) greater than 100 for 2 cycles then restart
alert extrapeople@localhost.com

If you are interested in monit for advance feature please visit monit official site.
check out monit document

วันศุกร์ที่ 5 มีนาคม พ.ศ. 2553

Advance php error handling

PHP server need different configuration for production and development server.

This article help you understanding php.ini configuration better and applicable to your server.

- display_errors
echo error to the browser this should be turn off for production but should be enable for test server.

- log_errors
instead of displaying error to stderr, you can choose to enable error logging to the file instead for production.

More option can be study here :
http://perishablepress.com/press/2008/01/30/advanced-php-error-handling-via-php/

apache with fcgid

Once, I used gentoo with apache(worker) + phpmod as a webserver. After switching to ubuntu, I've found that phpmod is not stable with apache(worker), this is not a problem with gentoo b'coz u can customize everything by yourself.

Up to this point ,there are 2 choice for ubuntu apache works with php
1) use apache prefork + phpmod
2) use apache worker + cgi + php

More description about fcgid/fastcgi http://www.seaoffire.net/fcgi-faq.html

I found the following study show that fcgid might be a good choice. And, it is.
http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html

For fcgid reference for apache :
http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

วันพฤหัสบดีที่ 4 มีนาคม พ.ศ. 2553

monitoring mysql with cacti

By default, cacti don't come with mysql graphing template. Here is the plugin that help you graphing mysql important data.

The installation is like the other plugins.
1) copy php script to cacti host /script directory
2) import template using web interface
3) add mysql user to mysql host
4) have fun :)


plugin document/download :
http://code.google.com/p/mysql-cacti-templates/wiki/InstallingTemplates

author blog:
http://www.xaprb.com/blog/2009/10/25/version-1-1-4-of-improved-cacti-templates-released/