All about opensource

Tuesday, February 24, 2009

To protect a directory with .htaccess in Fedora

A folder or directory of the public documents can be protected to prevent unauthorized visitors from seeing its contents using "HTTP authentication"

Create a file named .htaccess in the directory you want to protect and put following into file:

AuthType Basic
AuthName "Secure Area"
AuthUserFile /etc/httpd/conf/htpasswdfile
Require valid-user


Save the file and exit.
Now create the htpasswd file at given location.

cd /etc/httpd/conf

htpasswd -c htpasswdfile admin

Here one user 'admin' and password file 'htpasswdfile' is being created with the command 'htpasswd'
It will prompt for password (2 times), supply the password.

## (Some how apache, the web server user is not able to read the password file if you place the file in /root and /home/ folder so keep the file in the location where the httpd.conf file is)

## Make sure AllowOverride is set to All in the httpd.conf file

Tuesday, February 17, 2009

Amazon EC2 Server Setup

Assuming you already created account on AWS ans S3 so you will be having:
EC2 Private Key
EC2 Certificate Key
User ID
S3 access key
S3 secret key

Download Amazon EC2 API Tools from here:

The command line tools used here require Java version 5 or later to run. Either a JRE or JDK installation is acceptable.

Unzip it at some location.
Let say on /root/amazon
Also assuming you have your EC2 Private Key & EC2 Certificate Key at /root/amazon/ec2

Set these in your environment. Open .bash_profile file and add these entries as below:

PATH=............:/root/amazon/ec2-api-tools-1.3-30349/bin

export PATH
unset USERNAME

JAVA_HOME=/usr/local/jdk1.6.0_10
export JAVA_HOME

EC2_HOME=/root/amazon/ec2-api-tools-1.3-30349
export EC2_HOME

EC2_PRIVATE_KEY=/root/amazon/ec2/pk-xxxxxxx.pem
export EC2_PRIVATE_KEY

EC2_CERT=/root/amazon/ec2/cert-xxxxxxxxxx.pem
export EC2_CERT

After closing the .bash_profile file run the following command:
source .bash_profile

Finding a Suitable AMI:
ec2-describe-images -o self -o amazon | grep machine
ec2-describe-images | grep public




Generating a Keypair:
ec2-add-keypair gsg-keypair
Save the output content in a file (ex: id_rsa-gsg-keypair)

chmod 600 id_rsa_gsg-keypair

ec2-run-instances ami-86e90eef -k id_rsa_gsg-keypair
Note down the instance id (i-56a32e3f). This may be different for you.

ec2-describe-instances i-56a32e3f

(Note the Public URL ec2-174-129-185-64.compute-1.amazonaws.com, this may be different for you)

Authorizing Network Access to Your Instances:
ec2-authorize default -p 22
ec2-authorize default -p 80

Connecting to your Instance:

ssh -i id_rsa_gsg-keypair root@ec2-174-129-107-244.compute-1.amazonaws.com

root@my-instance #
After login to the ec2 server start the services
Start the Apache Web Server:
[root@ip-xx-xxx-xx-xxx:~] /etc/init.d/httpd start
Start the MySQl Server
[root@ip-xx-xxx-xx-xxx:~] /etc/init.d/mysqld start
Start the Asterisk Server
[root@ip-xx-xxx-xx-xxx:~] amportal start

Point the browser at:
http://ec2-174-129-107-244.compute-1.amazonaws.com/

Congratulations !! you have running Asterisk server with FreePBX and latest sugar.
To Access sugar:
http://ec2-174-129-107-244.compute-1.amazonaws.com/sugar52
(User/Pass: admin/admin)

Thursday, January 22, 2009

Managing S3 account from Fedora or Linux machine

Download S3 commands tool from SourceForge

(select tar file of the s3cmd to download)

Untar it some convenient location say /usr/local
cd /usr/local
tar ixzf s3cmd-0.9.8.x.tar.gz

It will create one dir s3cmd-0.9.8.x
cd s3cmd-0.9.8.x
python setup.py install


Create a configuration file:
s3cmd --configure

Supply your S3 account id and secret key

Follow the instructions...

Once config file is created you can use s3cmd.

How to use and other for general usage run the
s3cmd --help

Monday, November 24, 2008

Creating Virtual Hosts in Apache for Fedora

In the /etc/httpd/conf/httpd.conf file add following line at the end or in the virtual host section.

NameVirtualHost *

# for domain mydomain1.com
< VirtualHost * >
DocumentRoot /var/www/vhosts/mydomain1/htdocs
ServerName mydomain1.com
ErrorLog /var/www/vhosts/mydomain1/logs/error_log
CustomLog /var/www/vhosts/mydomain1/logs/access_log common
< /VirtualHost >


# for domain mydomain2.com
< VirtualHost * >
DocumentRoot /var/www/vhosts/mydomain2/htdocs
ServerName mydomain2.com
ErrorLog /var/www/vhosts/mydomain2/logs/error_log
CustomLog /var/www/vhosts/mydomain2/logs/access_log common
< /VirtualHost >

Save end Close the file.

Create directories/files according to the virtual hosts defined in the httpd.conf file.

$ cd /var/www
$ mkdir vhosts
$ cd /var/www/vhosts
$ mkdir -p mydomain1/htdocs
$ cd mydomain1
$ mkdir logs
$ cd logs
$ touch error_log
$ touch access_log
$ cd mydomain1
$ chown -R apache:apache logs
$ chown -R apache:apache htdocs

Restart the web server (apache).

/etc/init.d/httpd restart

To teat the Virtual Host syntax:

$ /usr/sbin/httpd -S

(Output will be like below)

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:* is a NameVirtualHost
port * namevhost mydomain1.com (/etc/httpd/conf/httpd.conf:1049)
port * namevhost mydomain2.com (/etc/httpd/conf/httpd.conf:1057)
Syntax OK

Virtual Host can be easily set and tested on Local Fedora / Redhat machine
In local Fedora/RH machine:

NameVirtualHost 127.0.0.1

< VirtualHost 127.0.0.1 >
DocumentRoot "/var/www/html"
ServerName localhost
< /VirtualHost >

< VirtualHost 127.0.0.1 >
DocumentRoot "/var/www/mysite"
ServerName mysite.com
< /VirtualHost >

Add the mysite.com in the /etc/hosts file (at the end)
127.0.0.1 localhost.localdomain localhost localhost
::1 localhost6.localdomain6 localhost6
127.0.0.1 mysite.com mysite.com

Restart the Apache.

Point your browser at:
http://localhost

It will display the content under /var/www/html dir

http://mysite.com/

It will display the content under /var/www/mysite dir

Tuesday, November 4, 2008

creating svn repository in Fedora

Lets first install subversion (svn server packages) and Apache module for subversion:

$ yum -y install subversion mod_dav_svn

$cd /etc/httpd/conf.d/
$ vi subversion.conf

# Make sure you uncomment the following if they are commented out
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

# Add the following to allow a basic authentication and point Apache to where the actual
# repository resides.

DAV svn
SVNPath /var/www/svn/repos
AuthType Basic
AuthName "SVN Access"
AuthUserFile /etc/httpd/conf.d/svnpassowrd
Require valid-user


Add user who can access the repository:
$ htpasswd -cm /etc/httpd/conf.d/svnpassowrd user1
(It will ask for the apssword for the user 'user1')

$ htpasswd -m /etc/httpd/conf.d/svnpassowrd user2
(It will ask for the apssword for the user 'user2')

Create the repository:

$ cd /var/www/
$ mkdir svn
$ cd svn
$ svnadmin create repos
$ chown -R apache:apache repos
$ service httpd restart

Access repository from a web browser:
http://ip-address/repos
(It will ask the apache authentication user and password, supply the user/pass we created using htpasswd command)

Imporing a project into repository:
$ svn import /home/sanjay/testproj/ file:///var/svn/repos/testptoj -m "initial testproject"

Here "repos" is the svn repository (created by svnadmin create command) and "testproj" is one project inside this repository.
/home/sanjay/testproj is the folder containing all the files we want to be in repos.

Adding a dir tree in the existing repository.
Case: Although we can use the svn add/commit but if the dir is too big and there is no UI access for svn repository then
better use the "import" command of svn.


Now if we want to add "wiki" folder into the "testproj" then use the import as below"

$ svn import /home/sanjay/testproj/wiki/ file:///var/svn/repos/testproj/wiki -m "wiki folder in testproj"

Thursday, July 24, 2008

Taking dump of svn repository

This is for taking a dump of a existing svn repository and creating a svn repository on different server.

Take the dump of svn repo from svn.
If we want all the log history then no argument is needed.
$svnadmin dump /opt/svn/myrepo/ >myrepobackup

Copy this file to new server.

Create one repo on new server.
$ svnadmin create --fs-type fsfs /opt/svn/myrepo/
Load from the svn dump copy
$svnadmin load /opt/svn/myrepo < /root/Desktop/myrepobackup

This way we will get all the history log file of existing repository.

If we want dump of a particular revision the use:
$ svnadmin dump /opt/svn/myrepo -r 100 >myrepobackup100

For creating a repository read:
http://sanjaykatiyar1.blogspot.com/2007/06/add-svn-repository.html

Thursday, June 19, 2008

CVS Installation on Ubuntu

Login to server as root.
Install CVS files:
apt-get install cvs

Install the CVS server:
apt-get install cvsd

After installing some file it will prompt (UI) for your repository name.
By default it provides 2 repos
demo
myrepos

Either you can remove these and add one new or let it be there and add new one.
Let say add '/cvsrepo'. Click the OK to close the UI.

If the folder cvsrepo does not exist, then create it.
cd /var/lib/cvsd
mkdir cvsrepo


Initialize the repository
cvs -d /var/lib/cvsd/cvsrepo init

Create a user and password to access the cvs repository (cvsrepo):
cvsd-passwd /var/lib/cvsd/cvsrepo +cvsuser
(cvsuser is the user name who is going to access the cvs repo.
It will ask password for user 'cvsuser' supply the password)
If you want to add more user follow the same..

cvsd-passwd /var/lib/cvsd/cvsrepo +newuser

Change the following

vi /var/lib/cvsd/cvsrepo/CVSROOT/config

Change "SystemAuth=no"

Just make sure the cvsrepo is added.
Open the /etc/cvsd/cvsd.conf file

vi /etc/cvsd/cvsd.conf
Go to the end of the file.
If below line is there then its fine otherwise add the following line
Repos /cvsrepo

then restart cvsd:
/etc/init.d/cvsd restart

Give the right permission to the repo:
cd /var/lib/cvsd
chown -R cvsd:cvsd cvsrepo


Test installation:
cd to some dir

cvs -d :pserver:cvsuser@localhost:/cvsrepo login

cvs -d :pserver:cvsuser@localhost:/cvsrepo checkout .

If its checking out without any error then it means all is well.
Then you can create the projects (module) in cvsrepo.

Thursday, May 29, 2008

How to insatll Java plugins in Firefox on Fedora

Case 1: If you do not have have JDK >1.5 installed then download the jre for Fedora/Redhat from here:
http://java.com/en/download/help/5000010500.xml#download
And installed jre as steps given at same page.

Let say jre has been installed at /usr/java/jre1.6.0/

Case 2: If Firefox is installed as RPM then run the command:
$ cd /usr/lib/firefox-x.x.x.x/plugins
$ ln -s /usr/java/jre1.6.0/plugin/i386/ns7/libjavaplugin_oji.so

Case 3: If you already have JDK >1.5 installed then cd to jdk location.
Lets say jdk is insatlled at:
/usr/local/jdk1.5.0_09/
$ cd /usr/lib/firefox-x.x.x.x/plugins
$ ln -s /usr/local/jdk1.5.0_09/jre/plugin/i386/ns7/libjavaplugin_oji.so


Case 4: If Firefax has been installed manually then cd to firefox
Lets say Firefox is at /usr/local/firefox
$ cd /usr/local/firefox/plugins
$ ln -s /usr/local/jdk1.5.0_09/jre/plugin/i386/ns7/libjavaplugin_oji.so

or
$ ln -s /usr/java/jre1.6.0/plugin/i386/ns7/libjavaplugin_oji.so

Restart the Firefox:)

Friday, May 23, 2008

Using Jasper reports with Postgres database

As Jasper reports has been written in Java we need JDK/JRE installed on machine.
Download jasper report from here (jasperreports-3.0.0-project.tar.gz)
http://sourceforge.net/project/showfiles.php?group_id=36382&package_id=28579

Open it at some convenient location lets say:
/usr/local
A folder will be created jasperreports-3.0.0

Here we are going to create reports from the Postgres sql so we need Java Postgres driver.
Download driver from here:
http://jdbc.postgresql.org/download.html
Select appropriate jar file, means if JDK is >1.4 <1.6 and Postgres >8.1 then
download the JDBC3 (postgresql-8.2-508.jdbc3.jar)
Place this file at /usr/local/jasperreports-3.0.0/lib folder.

There are many sample reports type availabe in the jasperreports-3.0.0/demo/samples
Let say we are interested in the Charts type of report (Bar, Pie and Line charts)

To connet to the postgres database open the ChartsApp.java file.
By defualt Jasper uses inbuilt HSQL db and below function does this:
private static Connection getConnection() throws ClassNotFoundException, SQLException
{
//Change these settings according to your local configuration
String driver = "org.hsqldb.jdbcDriver";
String connectString = "jdbc:hsqldb:hsql://localhost";
String user = "sa";
String password = "";


Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}


Change it to something like this:
// for postgre sql db
private static Connection getConnection() throws ClassNotFoundException, SQLException
//Change these settings according to your local configuration

String driver = "org.postgresql.Driver";
String connectString = "jdbc:postgresql://localhost:5432/YOUR_PG_DB_NAME";
String user = "PG_USER_NAME";
String password = "PG_USER_PASSWORD";

Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}


Now in any one of the jrxml file you can write your sql query depending upon the requirement.

Friday, April 25, 2008

installing webmin

If you want to manage your server then its a good idea to install a control panel application like webmin.
Its easy to install on Redhat based systems like RH, Fedora or CentOS.

Download the rpm package from here:
http://www.webmin.com/download.html

Then run the command as su
rpm -U webmin-1.410-1.noarch.rpm

To access the webmin via browser:
http://Your_IP_Address:10000/
or
http://localhost:10000/

By default webmin uses 10000 port.

May be this port is blocked by firewall on your system, to open this port just add following line in the /etc/sysconfig/iptables file
[0:0] -A INPUT -p tcp -m tcp --dport 10000 -j ACCEPT

And restart the iptables
/etc/init.d/iptables restart

Whats new in Ajuby 0.5