Archive for the 'General' Category

Install html2ps/pdf library to create PDF files using php

Generating PDF or postscript files on the fly with php is quite easy using a library called html2ps/pdf. Following are the steps which I took to install it on a fedora 7 server running php 5.x

As per the documentation, html2ps/pdf requires either Ghostscript or PDFLIB libraries for fast pdf generation. You can also use the inbuilt FPdf routines but that’s much slower. PDFLIB is non-free library which may requires you to have a license to use, therefore, I opted for GhostScript here.

Step 1. Check whether ghostscript is already installed or not:

Script to sync files between web severs having plesk

I got a little assignment where there are two webservers are there behind a load balancer and both needs to have identical files. Both server has plesk control panel. As we know, plesk store website files in /var/www/vhosts/domain/httpdocs directory, here domain is the name of website. Though this script can be used in any other case, just you may need to update it little bit.

I wrote a wrapper script for rsync and deployed there. Here is the script:

#!/bin/bash
 
############### websync.sh by Jagbir Singh #################
#
# This script acts as wrapper for rsync. It checks every domain listed in /var/www/vshots
# for existence in other server, if found there, then sync domain's 'httpdocs' only directory.
#
# ver 1.0 Mar 8, 2009: Initial version.
#
#############################################################
 
cd /var/www/vhosts
webserver2="192.168.30.2"
 
## get directory list
ls --file-type | grep "\/" | sed 's/\///' | grep -Ev "^chroot|^default" > /tmp/dir.list
exec 10</tmp/dir.list
let count=0
 
## check domains in other server and update them.
while read LINE <&10; do
    ## update second webserver if domain exist there (just in case)
    if  `ssh $webserver2 "ls /var/www/vhosts/$LINE/httpdocs/ > /dev/null 2>&1"` ; then
        `rsync -az --delete -e ssh /var/www/vhosts/$LINE/httpdocs/ $webserver2:/var/www/vhosts/$LINE/httpdocs/`
    fi
 
    ((count++))
done
exec 10>&-

Quickly sync/update time from a time server

A good server machine should always tick its clock with correct time. The best way to keep it in shape is to sync with a time server.

You can use any preferred time server to sync. I’m using public time servers here:

$ ntpdate pool.ntp.org
5 Feb 11:17:00 ntpdate[3332]: step time server 220.225.252.202 offset -585.969659 sec

Network time update command (ntpdate) will contact the available time server from public pool and sync time with it. Here in above example, offset is denoting that the clock was running ahead of time in my server.

To remain updated, you should put a cron entry to sync with time server every midnight:

Create bootable USB drive with Fedora 10 live

How about having a linux bootable USB stick? You can insert that in to any PC, do the do without affecting settings of that PC at all. This is even more helpful for linux admins who find it hard to work on friend’s Windows PC instead of taking delicious dinner, after receiving an unrgent call from NOC Deptt.

Here are quick steps on CentOS 5.2 box (should be identical on any RH based distro):

1. Check whether required tools are already installed or not:

# rpm -q livecd
<no output>

2. Install tools:

Quickly change your ssh port from default 22 to something higher

In the era of daily brute force attacks, it is advisable to change your ssh port from default 22 to something higher, to lower your chances of being a victim.

I’m using CentOS 5.2 box here but the process should be identical in other RH based distros.

Step 1. Update /etc/ssh/sshd_config file, line 13 (it might be different in your file):

old line:
Port 22
Change it to:
Port 54545 # any port number you wish

if you rush and try to restart your ssh service, you may end with getting error:

# /etc/init.d/sshd restart
 Stopping sshd:                                             [  OK  ]
Starting sshd: /etc/ssh/sshd_config line 13: Badly formatted port number. [FAILED]
Get Adobe Flash playerPlugin by wpburn.com wordpress themes