Showing posts from 2012

How to install ruby, rubygems and libyaml

Following are the commands which can be used to install the ruby with rubygems and libyaml:

To install ruby use the following commands:
wget tar -xvf ruby-1.9.3-p194.tar.gz cd ruby-1.9.3-p194 ./configure make make install ruby -v

To check if your ruby is correctly working or not create a test ruby script and run it:
vi test.rb Use the following code for test purpose:
#!/usr/bin/env ruby puts "Ruby working Fine:)" Give the ruby script execute permission and run the script to see if ruby is working fine or not:
chmod +x test.rb ./test.rb

To install rubygems use the following commands:
wget tar -xvzf rubygems-1.8.24.tgz cd rubygems-1.8.24 ruby setup.rb gem -v
If you get an error regarding the libyaml dependency, follow the following steps:

How to apply Apache(HTTP) authentication on any Domain

HTTP authentication is a process of applying authentication to our Domain so that only authorized people can access it.

The following command is used to create the password file in the doc root which is used to store the passwords of the users to whom you want to give the access.

/usr/local/apache/bin/htpasswd -c /var/www/ username  
htpasswd -c /var/www/ username

Use  /usr/local/apache/bin/htpasswd if you are using a Apache with source installation so that it can locate the htpasswd command to create the password file.htpasswd can be directly used if you have done default installation by using tools like yum, rpm etc.-c is used to create the passwd file in the doc root.If you want to add a new user to current file don't use -c as it will create the new file, use the same command without -c and new user name./var/www/ is the destination of the file where you want to create the password file and passwd is the file n…

Command to delete file older than n number of days

Following command can be used to delete files older than n number of days:

find /usr/local/apache/logs -type f -mtime +15 -exec rm -f {} \;

find - It will search the files in the directory.
/usr/local/apache/logs - destination of the directory.
type f - type is used to search by type of file syatem & f is to find the files only in directory.
-mtime +15 - mtime used to search files according to time & +15  to search files older than 15 days.
-exec rm -f - exec is used to run any command & rm -f to forcefully delete the files.
{} - it will hold the result from the find command and will pass it to exec as input. General syntax -exec <command> {}
\; - '\' will tell the find command to take ; as the end of command else it will also include the ; in find command. '\' is works as "escapes" and tell bash to take ; as new argument.

How to redirect a URL which consists of any specific word.

To redirect  URL which has any specific word in it to any other URL the following redirect rule can be used:

RedirectMatch "ravi$" [R=301,NC]

ravi- Is the word which we are finding in the URL and if it appears than it will redirect to the desired URL. Is the site to which we are redirecting in given example.

How to check Apache redirect using CURL command.

To check the Apache redirect we can use the CURL command which can tell us whether our reidrect is working correct or not in terminal it self.

curl -H "" http://localhost/                       //it will tell us where our site is redirecting

curl -H ""                         //it can be used if you know the IP of vhost

curl -H "" http://localhost/abc.html          // it will tell where is redirecting.

How to put permanent redirect in vhost

Following is the example of permanent redirect in which we are directing our site to another location.

<VirtualHost *>

        Redirect permanent /       //destination address


Simple vhost to redirect one site to another.

To create a vhost which does not have any doc root and is redirecting to any other site.

Following vhost will just redirect your site to any other site.

<VirtualHost *>
    ServerAdmin                   //server admin email ID
    ServerName                                        //server name
    RewriteEngine On
    RewriteRule ^/(.*) [R=301,L]        //destination address
    RewriteCond %{REQUEST_METHOD} ^TRACE
    RewriteRule .* - [F]