sandip's blog

New Server CentOS 4.4 at LT Grid with ISPConfig Installed

These are notes, I had taken down while setting up ISPConfig Hosting Control Panel on LayeredTechs Grid. Most of the steps were referenced via howtoforge and ispconfig installation notes. There were some gotchas to look out for and has bee noted below:

Check for number of arguments in bash

# Check for proper number of command line args.

EXPECTED_ARGS=1
E_BADARGS=65

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` {arg}"
  exit $E_BADARGS
fi

looping through an array with the for loop in bash

VALUES=(
value1
value2
value3
...
valueN
)

# Alternately:
#VALUES=("value1" "value2" "value3" "..." "valueN")

for ((i=0; i<${#VALUES[@]}; i++))
do
  echo ${VALUES[$i]}
done

Flash Player 9 released for linux

Adobes' Flash Player 9 is now public ready and can be downloaded from macromedia.mplug.org.

Quick install on Fedora using yum repository:

  1. Create the yum repo file as below:
    # cat << EOF > /etc/yum.repos.d/macromedia.repo
    [macromedia]
    name=Macromedia for i386 Linux
    baseurl=http://macromedia.rediris.es/rpm/
    enabled=0
    gpgcheck=1
    gpgkey=http://macromedia.mplug.org/FEDORA-GPG-KEY
    EOF

  2. Install the flash-plugin via yum:
    # yum --enablerepo=macromedia -y install flash-plugin

Search Engine Friendly Redirects

301 redirect is the most efficient and Search Engine friendly method for webpage redirection. If you have to change file names or move pages around, it's the safest option and preserves your search engine rankings. The code "301" is interpreted as "moved permanently".

With php:

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://host.domain.tld" );
?>

With mod_rewrite:

RewriteEngine on

#Redirect Old domain to New domain
RewriteRule (.*) http://host.domain.tld/$1 [R=301,L]

# Redirect a particular domain
RewriteCond %{http_host} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://host.newdomain.tld/$1 [R=301,L]

# Redirect a particular file
RewriteRule ^old_file.html$ http://host.domain.tld/new_file.html [R=301,L]

Block IP addresses from accessing your site via .htaccess

There are couple ways to block an IP, the one general way is to use htaccess deny feature.

SetEnvIf REMOTE_ADDR "^xxx.xxx.xxx.xxx$" badip
SetEnvIf REMOTE_ADDR "^xxx.xxx.xxx.xxx$" badip

<Limit GET POST>
order deny,allow
deny from env=badip
</Limit>

Extract individual files from an RPM

To extract an individual file from an rpm package without installing the rpm:

  1. Use rpm2cpio or rpm -qpl to list files and full paths in the package:
    $ rpm2cpio <package_name> | cpio -t

  2. Use rpm2cpio to extract a file. Run this command from /tmp or elsewhere in order to avoid overwriting any current system files.
    This creates the full path in the current directory and extracts the file specified.
    $ rpm2cpio <package_name> | cpio -iv --make-directories <full-file-path>

  3. To extract everything to the current directory:
    $ rpm2cpio <package_name> | cpio -ivd

Load your PHP pages faster with GZip compression

If you have heavy pages with lots of images and text, you can greatly improve its' performance by dynamically compressing the page with php.

Put the below code in the header of each php page.

<? ob_start("ob_gzhandler&quot;); ?>

It automatically gzips the page for browsers that support it.

This could also be set in the php.ini file instead, so all php pages are automatically compressed without having to add the above code in each and every php page.

In php.ini add the below code:

output_handler = ob_gzhandler

extracting initrd.img file on Fedora Core 6

initrd in Fedora Core 6 is a gzipped cpio archive which can be extracted using:

$ cd /tmp
$ gunzip < /boot/initrd.img |cpio -i --make-directories

Upgrading Fedora Core with Yum Remotely

I have recently upgraded Fedora Core 2 to Fedora Core 3 using Yum. The steps are outlined below:

  1. Import the Fedora RPM-GPG-KEY if not done so already.
    # rpm --import /usr/share/rhn/RPM-GPG-KEY-fedora

  2. Force install fedora-release and yum rpms of Fedora Core 3.
    # wget http://download.fedoralegacy.org/fedora/3/os/i386/fedora-release-3-8.i386.rpm
    # wget http://download.fedoralegacy.org/fedora/3/os/i386/yum-2.1.11-3.noarch.rpm
    # rpm -Uvh --force fedora-release*.rpm yum*.rpm
  3. Install FC3 kernel. This should also update mkinitrd as a dependency of the kernel.
    # yum update kernel
  4. Set lilo to use the FC3 kernel prior to rebooting.
    # lilo -v -v
    # lilo -R 2.6.12-1.1381_FC3
  5. Remove any old existing kernels.
    # yum remove kernel-2.4*
  6. Continue with the upgrade.
    # yum upgrade
  7. If you get any "Dependency Errors", the mentioned packages needs to be removed prior to a successful yum upgrade.

  8. Reboot once the upgrade is successful.
Comment