Author Archive

Thursday, November 20th, 2008 | Author: Angelo

Deleting directories and files starting with special characters on linux server. Suppose you find directories and files starting with special characters for example —- ##– ##### ## #-#- . Removing it using command rm -rf will give you following output.

[root@Linux ~]# rm -rf ----
rm: unrecognized option `----'
Try `rm ./----' to remove the file `----'.
Try `rm --help' for more information.

Or trying to remove directory with name #-#- will not produce any output (means it will not give any error) but also it will not get delete. ls -l will list directory #-#-

[root@Linux ~]# rm -rf #-#-

[root@Linux ~]# ls -l
total 8
drwxr-xr-x 2 root root 4096 Nov 20 18:25 #-#-

To remove all these directories or files starting special characters just add ./ before name.

[root@Linux ~]# rm -rf ./#-#-

[root@Linux ~]# rm -rf ./----

And you have deleted files & directories starting with special character.

Category: Linux  | One Comment
Monday, November 10th, 2008 | Author: Angelo

SSH without authentication while opening multiple sessions.

While working on a remote server via SSH, we need to open multiple sessions for the same remote server. Suppose, you are logged into a server 10.10.10.1, and now you want to transfer a file to server X from your local machine. Then you will have to copy those files using scp, for which you need to enter password while establishing a fresh connection to server X. So, it takes some time as well as it is irritating to enter password again and again.

Here’s the remedy :

Open the file /etc/ssh/ssh_config on your local machine as root to edit. Or if you are not the root user, you can create a file ~/.ssh/config for user level SSH configurations.

Add the following lines at the end of the file you opened just now:

ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p

Save the file and you are done !!

Now check out (One can try it this way) – Open a terminal and connect to a server :

$ ssh root@10.10.10.1

The connection gets established after entering the proper password.

Then in another terminal try to copy a file from your local machine to the same server :

$ scp -r ~/pintos root@10.10.10.1

This time, you don’t need to wait for a fresh connection, neither you will have to enter the password again. File transfer starts instantaneously. SSH shared the already established connection. Similarly you can open another terminal without waiting and entering the password again.

Saturday, November 01st, 2008 | Author: Angelo

Installation of apache module mod_limitipconn on cPanel server (apache version 2.X)

mod_limitipconn is used for limiting number of connections from each ip to particular site by enabling it in virtualhost of particular site. Suppose site name is mysitename.com and it’s cPanel username mysite.

Installation :: installing module mod_limitipconn

Download mod_limitipconn & untar the file. After downloading compile mod_limitipconn with apache using following command.

/usr/local/apache/bin/apxs -cia mod_limitipconn.c

Once you finish with installation of module mod_limitipconn

Uncomment following line in virtual host of site mysitename.com in /etc/httpd/conf/httpd.conf

Include "/usr/local/apache/conf/userdata/std/1/mysite/mysitename.com/*.conf"

Now fire following command to create directory mysitename.com with it’s parent directory mysite.

mkdir -p /usr/local/apache/conf/userdata/std/1/mysite/mysite.com
cd /usr/local/apache/conf/userdata/std/1/mysite/mysite.com

Then, touch a file called ipconn.conf and in it add following line. So that site will have max 3 connections from each ip.

<Location />
MaxConnPerIP 3
# exempting images from the connection limit is often a good
# idea if your web page has lots of inline images, since these
# pages often generate a flurry of concurrent image requests
NoIPLimit image/*
</Location>

Now restart apache service.

We can directly add above lines in virtualhost of domain mysitenaem.com. But when easyapache will be done in the server, the above changes will be overwritten. To avoid this we recommend above this method.

Now run following cPanel script and restart apache service.
/scripts/ensure_vhost_includes –user=mysite

Saturday, October 25th, 2008 | Author: Angelo

ERROR: Connection dropped by IMAP server.

Common error while accessing email account via squirrel mail client on cPanel server. This error occurs due to wrong ownership of file or folder located under etc or mail directory. Here is what worked for me on cPanel server. Suppose cPanel username is xyz to fix the issue execute following commands on server.

[root@server ]#cd /home/xyz
[root@server ]#chown xyz.xyz mail -R
[root@server ]#chown xyz.mail etc -R

Wednesday, October 22nd, 2008 | Author: Angelo

phpMyAdmin – Error

#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)

Here is what worked for me on cPanel server.

root@server [~]# vi /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php

find
$cfg['Servers'][$i]['socket'] = '';
change to
$cfg['Servers'][$i]['socket'] = '/var/lib/mysql/mysql.sock';

next line
$cfg['Servers'][$i]['connect_type'] = 'tcp';
change to
$cfg['Servers'][$i]['connect_type'] = 'socket';

now restart mysql service

root@server [~]# /etc/init.d/mysql restart

Saturday, October 18th, 2008 | Author: Angelo

How to keep ssh connection alive ?

While working remotely using ssh, you may have experienced ssh connection is closed (disconnected) while you are out for a tea or when you leave sshconnection inactive for few mins. It is very annoying that ssh connection getting disconnected again and again. Here is script which help you to keep ssh connection alive.

Executing following script to keep your ssh connection alive. This script will keep executing commands hostname and date every after 60 seconds so your ssh connection will never inactive more than 60 secs.

Edit the file keepalive.sh using vi editor and add following lines in the same.
[root@linuxserver ~]#vi keepalive.sh

#!/bin/sh

if [ $# -eq 1 ]; then
sleep_time=”$1″
else
sleep_time=60
fi

while true; do echo "`hostname` `date`"; sleep $sleep_time;done

now execute it as given below

[root@linuxserver ~]#sh keepalive.sh 60

When you will return to your work you can terminate this running script by pressing ctrl + c.

Friday, October 17th, 2008 | Author: Angelo

Command grep is used for printing lines which matches to a pattern you have defined.
Exercise ::
For example there is one file name is test contains following lines.
is it test file ?
is it test file

Now pattern you defined is ? means you are trying to print all lines which contain ? (question mark) from file test.
Usually we try follow command.
cat test | grep ?

But output will show both lines because grep treat ? as single character both lines contains more than single character. Solution for grep lines containing ? (symbol) is define ?(special character) in []
cat test | grep [?]
is it test file ?

Same in case of all special character *, . , ‘ , ” , }, ) . This trick will help you when you need to search all lines containing defined pattern from log files. Also useful in shell scripting.

Friday, October 17th, 2008 | Author: Angelo

What is Xcache ? :: Xcache help to accelerates the performance of PHP on servers. It optimizes performance by excluding compilation time of PHP scripts by caching the compiled state of PHP scripts into the RAM and uses the compiled version directly from the RAM. Which help to increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of php scripts and help to reduce serverload.

Installing Xache module:

XCache is a fast, stable PHP opcode cacher that has been tested on linux server and running under high load.
XCache 1.2.1 is release is compatible with apache1/ZendOptimizer/ZendCore compatibility. This version support only support 4.3.x 4.4.x 5.1.x and 5.2.x but does not support the PHP 5.0.x series, also note Xcache is not compatible with IONCUBE.

Installation:
[root@linuxserver ~]# wget http://xcache.lighttpd.net/pub/Releases/1.2.1/xcache-1.2.1.tar.gz
[root@linuxserver ~]# tar -xzf xcache-1.2.1.tar.gz
[root@linuxserver ~]# cd xcache-1.2.1
[root@linuxserver ~]# phpize
[root@linuxserver ~]# ./configure –enable-xcache –enable-xcache-optimizer
[root@linuxserver ~]# make
[root@linuxserver ~]# make install

Adding extensions and configuring xcache in php.ini you can find location of php.ini file by following command
[root@linuxserver ~]# php -i | grep php.ini
Now edit php.ini file.
Under ? extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613" line add following parameter to enable xcache.

extension = xcache.so

[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin" ? no need to add system user.

; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "cd959ac3debe8f587546a3fa353b3268" ? Password in MD5(op3nsesam3)

[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 128M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0

; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On

[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""

save and quit.

Restart httpd service.

Now from xcache source copy the "admin" directory to your htdocs from where you can manage the xache.

http://server-ip/admin/

Thursday, October 16th, 2008 | Author: Angelo

Defining variable in shell scripting.

For processing data, it must be store in RAM memory. Generally RAM memory is divided into small locations, and each location had unique number called memory address, which is used to hold our data. scripting can give a unique name to this address of ram called memory variable or variable. You can call this as storage location which can have different value but only one at the time.

There are two types of variables:

[A} Variable defined by Linux are known as system variable. All theses variable are defined in capital letters.
[B] Variables defined by user are known as user defined variables. You can define them in capital letters as well as in small letter or can be define using capital or small letter. But it is recommended that small letters should be used while defining user defined variables.

Determine system defined variable (also know as environment variables) by command env it will show you all variable created by Linux with value assigned to the same.

[root@server ~]#env

Exercise: User defined variables.

When variable name is followed by =value, the value of the variable is set to value.

Let’s define variable angelo with value scripting

[root@server ~]#angelo=scripting
[root@server ~]#echo $angelo

scripting

Wednesday, October 15th, 2008 | Author: Angelo

In apache error log if you find error for a account as “Warning: Cannot modify header information – headers already sent by blah,blah…”

Then simply open .htaccess and put following code
php_flag output_buffering on

In case of php-suexec server create php.ini file under respective directory and add turn on output buffering.