Authentication with lighttpd on CentOS

To enable authentication in lighttpd is easy. We can follow this reference to set up a functional environment: Module mod_auth – Using Authentication. However, it is a tragedy in my new CentOS 6 box with lighttpd 1.4.31, due to the separated configuration files.

After I enable mod_auth in modules.conf, set up my authentication functions in conf.d/auth.conf and restart the service, the function seems no work. The issue is on a lost include command in main configuration file – lighttpd.conf, then configuration will not be loaded.

The solution is adding include "conf.d/auth.conf" into lighttpd.conf and everything works fine. What a stupid problem. Enjoy it. 🙂

Suppress massively SNMP notices in message log

In my CentOS, with SNMP, it arise much more SNMP logs in message periodically. Like this:

Connection from UDP: []:xxxxx
Received SNMP packet(s) from UDP: []:xxxxx

Although the notices are harmless, it may drown out other useful messages. To suppress these messages, we can modify the parameters passed to SNMP daemon.

There is a default configuration in /etc/sysconfig/snmpd.options with a comment out option line:

# OPTIONS=”-Lsd -Lf /dev/null -p /var/run/ -a”

This line indicate SNMP’s log facility via syslog is for daemon (-Lsd) and it will log all levels (there are 7 levels). To suppress the notices, the configuration is modified as:

OPTIONS="-LS0-4d -Lf /dev/null -p /var/run/ -a"

. The parameter -LS is to specify the level we want to log, and we set level 0 to 4 (emergency, alert, critical, error, warning) for it. Whereas the level 5 is for notice, 6 for info and 7 for debug are not what we need.

Finally, the log is clearly as usual. 😛

Set MySQL default character set as UTF8 on CentOS

The default character set of MySQL installed in CentOS 5 is latin while a feasible one for CJKs is UTF-8.

mysql> SHOW VARIABLES LIKE '%character%';
| Variable_name | Value |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |

To enable whole system UTF-8, we need to add the following codes in /etc/my.cnf:
default-character-set = utf8

character-set-server = utf8

mysql> SHOW VARIABLES LIKE '%character%';
| Variable_name | Value |
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |

There are lots of additional settings in my Gentoo box, but it seems we don’t need right now. Maybe it can be use later. enjoyt it. 😉

[120302] The parameter default-character-set = utf8 for server configuration in 5.1.61 (or 5.1) is deprecated. We should use character-set-server = utf8 instead.

Use PHP 5.3 and Lighttpd on CentOS 5

The default packages built-in my CentOS box are Apache HTTP Server 2.2 and PHP 5.1. If we want to replace them with Lighttpd and PHP 5.3, we need some modification to the system. This post is an annotation of the procedure.

1. The Lighttpd package is not provided by official repository. We need to add the support via EPEL x86_64 repository (I’m using 64-bit CentOS): # rpm -Uvh

2. After update, we can install lighttpd: # yum install lighttpd lighttpd-fastcgi

3. Update PHP from 5.1 to 5.3, first we need to list all installed 5.1 packages: # rpm -qa | grep php and then to remove them all.

4. Install the PHP53 and related packages we need: # yum install php php-cli php-mysql.
Note: The PHP53 packages also install httpd packages which we cannot removed individually.

5. Enable fastcgi support for Lighttpd in /etc/lighttpd/lighttpd.conf as this reference: lighttpd + FastCGI in CentOS.
Note: The cgi.fix_pathinfo=1 configure is installed by default in /etc/php.d/lighttpd.ini and we can skip to set it up.

6. Finally, the most important step for some application use sessions. We need to set up the permissions by: # chown -R root:lighttpd /var/lib/php because the web server we use is not httpd. If we do not set this, some application like phpMyAdmin we raise error while login.

7. Restart the Lighttpd and enjoy it. 🙂