≡ Menu


Linux Blog Software

Q. I’ve Debian Linux VPS server for my small business web site. Can you tell me more about a free blog software (weblog software) that can run under LAMP?
[click to continue…]

Sysadmin because even developers need heroes!!!

Fingerprint / Identify Remote Web Server

Q. How do I fingerprint or identify remove web server a from UNIX / Linux shell prompt?
[click to continue…]

Redhat / CentOS / Fedora Linux Install XCache for PHP 5

How do I install Xcache opcode cacher for PHP 5 under RHEL / CentOS version 5.0 server?
[click to continue…]

How to: Measure the Lateceny and Throughput of Apache / Lighttpd / IIS Webserver

Q. I can measure network throughput and packet loss using standard UNIX / Linux command line utilities. How do I find out the lateceny and throughput of a web server like Apache under Linux?

A. You need to use the program called httping. It allows you to measure the latency of a webserver and the throughput.

Task: Ping the webserver on host www.cyberciti.biz

Use the following command for measuring the latency. Press CTRL+c to exit the program. It will display a summary of what was measured.
$ httping -g http://www.cyberciti.biz

PING www.cyberciti.biz:80 (http://www.cyberciti.biz):
connected to www.cyberciti.biz:80, seq=0 time=981.08 ms 
connected to www.cyberciti.biz:80, seq=1 time=709.92 ms 
connected to www.cyberciti.biz:80, seq=2 time=1072.02 ms 
connected to www.cyberciti.biz:80, seq=3 time=903.81 ms 
connected to www.cyberciti.biz:80, seq=4 time=607.84 ms 
connected to www.cyberciti.biz:80, seq=5 time=660.01 ms 
connected to www.cyberciti.biz:80, seq=6 time=730.12 ms 
connected to www.cyberciti.biz:80, seq=7 time=781.49 ms 

The -g url option use selects the url to probe / ping. You can also specify the port with -p port option:
$ httping -g http://www.cyberciti.biz -p 81
You can also connect using SSL, for this to work you need to give a https url or a 443 portnumber:
$ httping -l -g https://www.cyberciti.biz
$ httping -g http://www.cyberciti.biz -p 443

Task: Measure throughput of a webserver

The -G option force GET request instead of a HEAD request – this means that also the complete page/file must be transferred. You also need to pass the -b option with -G option to get the transferspeed (in KB/s).
$ httping -Gbg http://www.cyberciti.biz/

PING www.cyberciti.biz:80 (http://www.cyberciti.biz/):
connected to www.cyberciti.biz:80, seq=0 time=1738.39 ms  22KB/s
connected to www.cyberciti.biz:80, seq=1 time=1650.19 ms  20KB/s
connected to www.cyberciti.biz:80, seq=2 time=1759.65 ms  17KB/s
connected to www.cyberciti.biz:80, seq=3 time=1589.98 ms  21KB/s
connected to www.cyberciti.biz:80, seq=4 time=3709.87 ms  6KB/s
connected to www.cyberciti.biz:80, seq=5 time=3329.69 ms  7KB/s
--- http://www.cyberciti.biz/ ping statistics ---
53 connects, 53 ok, 0.00% failed
round-trip min/avg/max = 1451.9/2013.6/11656.0 ms
Transfer speed: min/avg/max = 6/19/24 KB

Please note above in above command you’re no longer measuring the latency!

You can also pass -X option with -G to show the amount of data transferred (excluding the headers):
$ httping -XGbg http://www.cyberciti.biz/

PING www.cyberciti.biz:80 (http://www.cyberciti.biz/):
connected to www.cyberciti.biz:80, seq=0 time=1576.11 ms  22KB/s 19KB
connected to www.cyberciti.biz:80, seq=1 time=2620.26 ms  9KB/s 19KB
connected to www.cyberciti.biz:80, seq=2 time=1507.69 ms  23KB/s 19KB
connected to www.cyberciti.biz:80, seq=3 time=1522.08 ms  24KB/s 19KB
connected to www.cyberciti.biz:80, seq=4 time=1533.68 ms  23KB/s 19KB
connected to www.cyberciti.biz:80, seq=5 time=1581.92 ms  21KB/s 19KB
connected to www.cyberciti.biz:80, seq=6 time=1512.06 ms  24KB/s 19KB
--- http://www.cyberciti.biz/ ping statistics ---
7 connects, 7 ok, 0.00% failed
round-trip min/avg/max = 1507.7/1693.4/2620.3 ms
Transfer speed: min/avg/max = 9/21/24 KB

Test remote server CPU

The -B option along with -G option ask the HTTP server to compress the returned data – this will reduce the influence of the bandwidth of your connection while increasing the influence of the processorpower of the HTTP server.
$ httping -BGg http://www.cyberciti.biz/

Flood Webserver

The -f option used to flood ping i.e. do not sit idle between each ping but ping as fast as the computer and network allow you to (don’t run this on production or 3rd party servers):
$ httping -fg http://www.cyberciti.biz/

Lighttpd as you compiled without pcre support error and solution

Q. I’m using lighttpd under CentOS 5 and getting the following error:
…can’t handle ‘$HTTP[url] =~ …’ as you compiled without pcre support.

My question is What is pcre support, and how do I solve this problem?

A. Pcre is nothing but Perl-compatible regular expression library. PCRE has its own native API, but a set of “wrapper” functions that are based on
the POSIX API are also supplied in the library libpcreposix. You must compile lighttpd with pcre to support lighttpd regex style config option. pcre-devel package provides the development files (Headers, libraries for static linking, etc) for pcre. Install the following package and rebuild your lighttpd:
# yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel

Now change directory to lighttpd source code and recompile Lighttpd with pcre option:
# make clean
# ./configure
# make
# make install

Now restart lighttpd and it should support pcre style config options.

Lighttpd virtualhost configuration ~ name-based virtual hosting

Q. How do I configure lighttpd web server as virtual host for serving multiple web site from a single public IP address (name-based virtual hosting)?

A. Virtual hosting is a method that servers such as webservers use to host more than one domain name on the same server, sometimes on the same IP address.

There are two basic methods of accomplishing virtual hosting .
(A) name-based virtual hosting : You use multiple host names for the same webserver IP address. For example domain nixcraft.com and theos.in uses same IP address called

(B) ) IIP address / ip-based virtual hosting

How do I configure Lighttpd for name-based virtual hosting?

Let us say your setup is as follows:

  • Public IP address:
  • Domain names: domain1.com and domain2.net
  • Default Document Root: /home/lighttpd/default/http
  • Default Document Root for domain1.com: /home/lighttpd/domain1.com/http
  • Default Document Root for domain2.net: /home/lighttpd/domain2.net/http

First, create required directories:
# mkdir -p /home/lighttpd/default/http
Next, open lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf
Setup default document root:
server.document-root = "/home/lighttpd/default/http/"
Setup public IP address:
server.port = 80
server.bind = ""

At the bottom of the file, add:
include "domain1.com.conf"
include "domain2.net.conf"

Save and close the file.

Create domain1.com virtual host configuration

Create required directories:
# mkdir -p /home/lighttpd/domain1.com/http
# mkdir -p /home/lighttpd/domain1.com/logs

Open /etc/lighttpd/domain1.com.conf file:
# vi /etc/lighttpd/domain1.com.conf
Add following configuration directive:

$HTTP["host"] =~ "domain1\.com" {
            server.document-root = "/home/lighttpd/domain1.com/http"
            accesslog.filename         = "/home/lighttpd/domain1.com/logs/access.log"

Save and close the file.

Create domain2.net virtual host configuration

Create required directories:
# mkdir -p /home/lighttpd/domain2.net/http
# mkdir -p /home/lighttpd/domain2.net/logs

Open /etc/lighttpd/domain2.net.conf file:
# vi /etc/lighttpd/domain2.net.conf
Add following configuration directive:

$HTTP["host"] =~ "domain2\.net" {
            server.document-root = "/home/lighttpd/domain2.net/http"
            accesslog.filename         = "/home/lighttpd/domain2.net/logs/access.log"

Save and close the file.

Restart the lighttpd web server:
# /etc/init.d/lighttpd restart

Make sure document root is owned by your web server user such as www-data or lighttpd:
# chown -R lighttpd:lighttpd /home/lighttpd/

FreeBSD Lighttpd fastcgi php configuration and installation

Q. How do I install and configure php under Lighttpd web server. I’m using

=> FreeBSD 6.2

=> Lighttpd 1.5

=> FastCGI PHP 5.2

How do I configure php under Lighttpd?

A. PHP generally runs on a web server like lighttpd taking PHP code as its input and creating Web pages as output. FastCGI is a protocol for interfacing interactive programs with a web server. Lighttpd has mod_fastcgi to run php application.

Assuming that you have php installed (see these instructions on installing Lighttpd+MySQL+php5 under FreeBSD), open lighttpd.conf file:
# vi /usr/local/etc/lighttpd.conf
Make sure FASTCGI module is enabled:
server.modules += ( "mod_fastcgi" )

Now append following code

fastcgi.server = ( ".php" =>
( "localhost" =>
                        "socket" => "/tmp/php-fastcgi.socket",
                        "bin-path" => "/usr/local/bin/php-cgi"

Save and close the file. Restart lighttpd:
# /usr/local/etc/rc.d/lighttpd restart

Display or view the perl cgi errors in a web browser

Q. I’m currently learning Perl cgi programming and coded a small web site in a Perl. Usually errors are logged in a log file. How can I view the perl cgi errors in a we browser like firefox?

A. CGI scripts have a nasty habit of leaving warning messages in the error logs that are neither time stamped nor fully identified. Tracking down the script that caused the error is a pain.

You need to install and use CGI::Carp module.

With this module the standard warn(), die (), croak(), confess() and carp() calls will automatically be replaced with functions that write out nicely time-stamped messages to the HTTP server error log.

You can also log message to a browser. Now add following two lines before sending any headers to a browser:

use CGI; 
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 

With above lines it is possible to make non-fatal errors appear as HTML comments embedded in the output of your program. To enable this feature, export the new “warningsToBrowser” subroutine. Since sending warnings to the browser before the HTTP headers have been sent would cause an error, any warnings are stored in an internal buffer until you call the warningsToBrowser() subroutine with a true argument.

See official CGI::Carp man page for more information.

PHP encryption symmetric program example using crypt to store password in a text file

Q. Symmetric encryption is a type of encryption where the same key is used to encrypt and decrypt the message. Can you explain how do I use symmetric encryption under PHP to store password in a text file and authenticate the user?

A. Symmetric encryption differs from asymmetric (also known as public-key) encryption, which uses one key to encrypt a message and another to decrypt the message.

PHP crypt() will return an encrypted string using the standard Unix DES-based encryption algorithm or alternative algorithms that may be available on the system. Arguments are a string to be encrypted and an optional salt string to base the encryption on. See the Unix man page for your crypt function for more information.

string crypt ( string $str [, string $salt] )

Consider following example.
$en_password : Stores encrypted password. You need to store this in database or flat text file.
$userPasswordInput : Holds user provided / supplied password via HTML page

If command is use to check encrypted password (hash) with user supplied password.

//Standard DES-based encryption with a two character salt called 'ge'
$en_password = crypt('secrete','ge');

if (crypt($userPasswordInput, $en_password) == $en_password) {
   echo "Password verified, you can login!";

PHP Function to write / store password to a file called /home/secure/.password

function updateAdminLoginPassword($new){
  //This is Blowfish encryption with a sixteen character salt starting with or $2a$
  $encryptedPassword = crypt($new, '$2a$didIL...fpSd78..$');
  // Open the file and erase the contents if any
  $fp = fopen("/home/secure/.password", "w");
  // Write the data to the file
  fwrite($fp, $Password);
  // Close the file
  echo '<h3>Password has been updated!<h3>';
  echo '<SCRIPT>alert(\'Password changed! You must login again to use new password\');</SCRIPT>';
  /* resetSession(); */

Function to verify a password (note we are using hash in both functions $2a$didIL…fpSd78..$):

function verifyPassword($password)
 $username= "admin"; 
// read encrypted password
 $fp = fopen("/home/secure/.password", "r");
 while ( $line = fgets($fp, 1000) ) { $encryptedpasswd=$line; }
 if ( $_POST["username"] == $username && (crypt($password,'$2a$didIL...fpSd78..$') ==  $encryptedpasswd) )
 { // allow login
		session_start(); //Initialize session data
                //store user login name and password
		$_SESSION['user'] = $username;
                $_SESSION['pwd'] = $encryptedpasswd;  
                // display main menu
		header( "Location: /welcome.php" );
 {       // password is not correct or session expired due to password change
	header( "Location: /login.php?sessionnotfound=1" );

Above examples just provides you idea about php password encryptions and hash. You must consider other factors such as SSL http session, MD5 password / hash and mysql database to store password has etc.

Further readings:

Tweaking php For Maximum Execution Time For Scripts

I‘ve been trying to migrate my webblogs using WordPress inbuilt import facility. I’ve exported current blog as a xml file and downloaded to my desktop. Next I navigated to my new blog’s admin area and clicked on Manage > Import. However import failed after importing 50-60% posts only.

I went through Apache and PHP log files and I realized that the script was timed out. How do I fix this problem under Linux / UNIX?
[click to continue…]