Thursday, May 12, 2011

Set Apache Password Protected Directories With .htaccess File


Step # 1: Make sure Apache is configured to use .htaccess file

You need to have AllowOverride AuthConfig directive in httpd.conf file in order for these directives to have any effect. Look for DocumentRoot Directory entry. In this example, our DocumentRoot directory is set to /var/www. Therefore, my entry in httpd.conf looks like as follows:
<Directory /var/www>
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
Save the file and restart Apache
If you are using Red Hat /Fedora Linux:
# service httpd restart
If you are using Debian Linux:
# /etc/init.d/apache-perl restart

Step # 2: Create a password file with htpasswd

htpasswd command is used to create and update the flat-files (text file) used to store usernames and password for basic authentication of Apache users. General syntax:
htpasswd -c password-file username
Where,
  • -c : Create the password-file. If password-file already exists, it is rewritten and truncated.
  • username : The username to create or update in password-file. If username does not exist in this file, an entry is added. If it does exist, the password is changed.
Create directory outside apache document root, so that only Apache can access password file. The password-file should be placed somewhere not accessible from the web. This is so that people cannot download the password file:
# mkdir -p /home/secure/
Add new user called samba
# htpasswd -c /home/secure/apasswords samba
Make sure /home/secure/apasswords file is readable by Apache web server. If Apache cannot read your password file, it will not authenticate you. You need to setup a correct permission using chown command. Usually apache use www-data user. Use the following command to find out Apache username. If you are using Debian Linux use pache2.conf, type the following command:
# grep -e '^User' /etc/apache2/apache2.conf
Output:
www-data
Now allow apache user www-data to read our password file:
# chown www-data:www-data /home/secure/apasswords
# chmod 0660 /home/secure/apasswords
If you are using RedHat and Fedora core, type the following commands :
# grep -e '^User' /etc/httpd/conf/httpd.conf
Output:
apache
Now allow apache user apache to read our password file:
# chown apache:apache /home/secure/apasswords
# chmod 0660 /home/secure/apasswords
Now our user samba is added but you need to configure the Apache web server to request a password and tell the server which users are allowed access. Let us assume you have directory called /var/www/docs and you would like to protect it with a password.
Create a directory /var/www/docs if it does not exist:
# mkdir -p /var/www/docs
Create .htaccess file using text editor:
# cd /var/www/docs
# vi .htaccess
Add following text:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/secure/apasswords
Require user samba
Save file and exit to shell prompt.

Step # 3: Test your configuration

Fire your browser type url http://yourdomain.com/docs/ or http://localhost/docs/ or http://ip-address/docs
When prompted for username and password please supply username samba and password. You can add following lines to any file <Diretory> entry in httpd.conf file:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/secure/apasswords
Require user samba
To change or setup new user use htpasswd command again.

Troubleshooting

If password is not accepted or if you want to troubleshoot authentication related problems, open and see apache access.log/error.log files:
Fedora Core/CentOS/RHEL Linux log file location:
# tail -f /var/log/httpd/access_log
# tail -f /var/log/httpd/error_log

Debian Linux Apache 2 log file location:
# tailf -f /var/log/apache2/access.log
# tailf -f /var/log/apache2/error.log

Monday, May 9, 2011

How to install Groovy on ubuntu


Download zip file from http://groovy.codehaus.org/ and unzip to folder

$ sudo unzip groovy-binary-1.7.6.zip -d /opt/groovy/


Edit PATH in the environment file
$ sudo nano /etc/environment

Add the following to the environment file
PATH="... :$GROOVY_HOME/bin"
GROOVY_HOME="/opt/groovy/groovy-1.7.5"

Add symbolic links to the usr/bin folder
$ sudo ln -sf /opt/groovy/groovy-1.7.5/bin/* /usr/bin/.

Open a new terminal. Test installation
$ groovy --version
Groovy Version: 1.7.5 JVM: 1.6.0_20

Thursday, March 31, 2011


This guide will explain how to install sventon, the java subversion repository browser on Debian Lenny. You will need to be logged in as the root user.
First of all we need to enable the the “non-free”  repository within your APT sources.list.

Open /etc/apt/sources.list in your favorite editor:
vi /etc/apt/sources.list

Add the following lines:
deb http://ftp.debian.org/debian/ contrib non-free
deb-src http://ftp.debian.org/debian/ contrib non-free
and save the file.
Now we need to install Tomcat + Java JDK
apt-get update
apt-get install sun-java6-jdk tomcat5.5 tomcat5.5-webapps

By default, tomcat will listen on port 8180
If tomcat is running, you need to stop it.
/etc/init.d/tomcat5.5 stop

You now need to deploy the .war file from the sventon binary distribution, this can be downloaded from:
 http://developer.berlios.de/project/showfiles.php?group_id=3670
For this I will be using sventon-2.1.5-bin.zip
Download the .zip file and unzip it:
mkdir -p /root/tmp; cd /root/tmp
wget http://download.berlios.de/sventon/sventon-2.1.5-bin.zip
unzip sventon-2.1.5-bin.zip
cd sventon-2.1.5
cp svn.war /usr/share/tomcat5.5/webapps/

We then need to start-up tomcat to deploy the .war file:
/etc/init.d/tomcat5.5 start

Please allow a minute or so for tomcat to start then stop tomcat again and remove the war file:
/etc/init.d/tomcat5.5 stop
rm -rf /usr/share/tomcat5.5/webapps/svn.war
Then restart tomcat:
/etc/init.d/tomcat5.5 start

When tomcat starts you will be able to access the Sventon configuration via
http://(server-ip):8180/svn

Thursday, March 3, 2011

Crontabs

To edit the crontabs of a specific user use the below command:
$crontab -e -u username

Tuesday, February 22, 2011

BuildForge Introduction


Before you start
In this tutorial, learn how to install and configure IBM Rational® Build Forge® to build the open source project Jakarta Tomcat. Create a continuous integration environment for Tomcat, with builds occurring whenever changes are committed to the Tomcat Subversion repository. With this 2-part series, go from zero to 96 bpd (builds per day) in two days. This tutorial covers the tasks for the first day.
If you are a developer involved in build automation, or a system operator providing infrastructure support for build and deploy functions, this series is for you.
Part 2 (the second day) of this series describes how Build Forge provides for the reuse of existing project scripting. It also covers how Build Forge can extend a simple compile and package build process by adding customization and deployment capability.
After completing this tutorial you will know:
  • Basic Build Forge concepts
  • How to install and set up Rational Forge
  • How to create Build Forge objects to represent build servers for the tutorial
  • How to configure a Hello World project to run
It is assumed that you have some understanding of building applications based on Java™ technology. Build Forge is language agnostic, but the Tomcat project is written in the Java programming language. Experience with Apache Ant and Subversion is helpful, but not required.
To complete the steps in this tutorial, you should have access to the following tools, which you can get by using the contact information on the Rational Build Forge product overview
  • Introduction
  • This tutorial uses Tomcat as an example project to show how a Rational Build Forge implementation reuses existing scripts. Think of Tomcat as an analogy for any project you'd like to include in a build management system where you can't, or don't want to, change build scripts. In the tutorial example, Tomcat could represent any internal or external project related to your projects.
  • Interrelated projects need to be deployed into an integration environment so they can be tested together. Triggering builds in the integration environment continuously when project codebases change (continuous integration), then running automated tests, is best practice for ensuring that system integration points continue working.
    When implementing build management, you want to avoid impacting developers' current build workflows, or limiting their future ability to innovate. Using an open source project is perfect. A build management system should be judged on: enabling an organization to achieve continuous integration, customized notifications, secure access, scheduling, and reporting without requiring development changes. The open source project will show how Rational Build Forge can automate the key tasks.

    Before and after
    Before and after 

Install and set up Rational Build Forge
This section explains how to set up the required server components, as shown below.
Section 2 goal
For this tutorial, all server processes, including the database, will be running on a single host.
The Build Forge Management Console will check for a valid license on startup. You need to install the Rational License Server and import an evaluation license before installing the Build Forge Management Console.
  1. Unzip the installation files.
  2. Run Setup. Select Install Rational License Server.
  3. Accept the default options for the rest of the license server installation. When setup is complete, click Finish.
  1. Start the License Key Administrator by selecting All Programs > IBM Rational > IBM Rational License Key Administrator.
  2. Select Import a Rational License File, and click Next.
  3. Browse to the location of the Evaluation License Key file.
  4. Open the file, and click Import.
  5. Verify that the licenses are valid, and click Import.
  6. Agree to restart the license server.
The Build Forge Management Console will store configuration data and build log files in a database. For this tutorial, install MySQL version 5.0.45.
  1. Unzip the installation file, then run it.
  2. When prompted, select the Complete setup.
  3. Select Install.
  4. Click Next until you see the window below. Select Configure the MySQL Server now, then click Finish.
  5. Click Next, select the Standard Configuration, and click Next.
  6. Select:
    • Install As Windows Service
    • MySQL for the Service Name
    • Launch the MySQL Server Automatically
    • Include Bin Directory in Windows PATH
    and click Next
  7. Enter a root password, click Next, then click Execute.
  8. Click Finish.
You need to create a database instance inside MySQL to store Build Forge data. You also need to create a MySQL user for Build Forge to connect with.
  1. Open a command prompt and, as shown below, enter mysql -uroot -p<password entered during mysql install>
  2. At the mysql prompt, enter create database build;
  3. At the mysql prompt, enter grant all on build.* to build identified by 'build';
  4. At the mysql prompt, enter quit
Now that there is a license server ready to serve valid Build Forge licenses, and a database available and configured, proceed with the installation of the Build Forge Management Console.
  1. Unzip the installation file, and run it.
  2. Click Next on the setup wizard Welcome panel.
  3. Select your destination folder.
  4. Enter localhost for the License Host, and accept the default Http Server Port unless the system you are using is currently using that port (for example, another Web Server).
  5. Enter MC1 for Location Name. Select Connect to existing database, and:
    • DB Name: build
    • DB Type: MySQL
    • DB Host: localhost
    • Username: build
    • Password: build
    Management Console 
  6. Click Install.
    After installation, the Build Forge Management Console will start up in the background as a service. When it starts and encounters the empty MySQL database, it will begin creating a table structure. This process may take a minute. Wait for the system to become idle before proceeding.
  7. After stopping the Build Forge service (bfengine), you'll copy libmySQL.dll to the BuildForge Apache directory. At a command prompt, enter net stop bfengine
  8. Enter copy "c:\Program Files\MySQL\MySQL Server 5.0\bin\libmySQL.dll" "c:\Program Files\BuildForge\Apache\bin"
  9. Restart the Build Forge service by entering net start bfengine
  10. Close the command prompt window.
  11. Double-click the Management Console icon on the desktop.
  12. Enter the User name root and Password root, and click Login.
  13. You should then see the Management Console home page for the root user.
    Management Console
Build Forge Agents can be installed on any system that will take part in a build, deploy, and test process managed by Build Forge. For this tutorial, install the agent on the same system as the Management Console. The agent system can, and usually will, be remote.
  1. Unzip the installation file and run win-bfagent-7.0.1.211.exe.
  2. Accept all defaults throughout the agent installation panels.
  3. Click Finish when prompted.
This concludes the installation required for the Rational License Server, MySQL, the Rational Build Forge Management Console, and the Rational Build Forge Agent. The next section explains how to configure Build Forge to create a build process.

First steps to Hello World
In this section you create Build Forge objects to represent build servers for the tutorial, and configure a Hello World project to run. For a complete explanation of the options in these steps, see the online help with Rational Build Forge.
Hello World
You installed the Build Forge agent in Install and set up Rational Build Forge. The first step is to configure the Management Console to communicate with the agent process. This configuration will use functions from the Servers navigation panel in the Management console.
Hello World
The object holds the credentials the Management Console will use to log into the system running the Agent. The account used must have sufficient privileges to perform the tasks in the build process.
  1. Click Server Auth under Servers.
  2. Enter localhost auth for the Name, and the login parameters for the Administrator (or an account with sufficient privileges).
  3. Click Save Server Authentication.

    Hello World
Build Forge provides a powerful means of selecting a build server dynamically at build time. It is beyond the scope of this tutorial to describe this function, so you will hard wire the builds to a particular server. First you need to make a Selector that selects a server based on its name.
  1. Click Selectors under Servers.
  2. Enter build selector for the Name.
  3. Click Save.

    Hello World
Build Forge allows multiple criteria to be used, such as free disk space, number of CPUs, and so on. This tutorial uses:
  1. Default Name BF_NAME.
  2. Operator == .
  3. Enter build_server for the Value.
  4. Yes for Required.
  5. Click Save.

    Hello World
The server object holds the connection information (host) and the link to the Server Authentication we created in Create server authentication. On the build server, the working directories for builds are set by the Path entry on this panel. Build Forge also lets you associate a server with an Environment variable specific to it.
  1. Click Servers.
  2. Enter build_server for the Name, c:\build for Path, and select localhost auth for Authentication. Leave the default values for the remaining fields.
  3. Click Save.

    Hello World
Build Forge will not be able to write to the directory specified in the path above unless it has been created. At a command prompt, enter md c:\buildHello World
To test the connection to the agent:
  1. Select build_server.
  2. Click Test Connection.

    Hello World
The Test Results tab will be displayed. After the Management Console has connected with and tested the agent, the display will be updated with the test results and the indicator on the icon for the server will show a green status.
Hello World
Now that the Management Console can control builds with an agent, you can write a Hello World project that will use the agent to echo a value. A Build Forge project contains several steps representing the commands that make up the build process.
  1. To create the build project, it must be configured with a name and a selector. Consult the online help for a description of the remaining project configuration fields.
    • Click Projects.
    • Enter Hello World for the Name, and verify that Selector has defaulted to build selector.
    • Click Save Project.

      Hello World
  2. Open the project by clicking on Hello World in the project list.
  3. In the project, the steps are configured to perform the build process. In the Details tab, create a single step that echoes back a value:
    • Enter Echo Value for the Name
    • Enter echo Hello World in the Command area.
    • Leave the rest of the fields with default values for now.
    • b. Click Save Step.

      Hello World
  4. Execute the project by clicking Start Project.
  5. Leave the default values shown below, and click Execute.
  6. The running build page will be displayed, showing progress through the project steps as they execute. The result from each step is also displayed.
  7. Click the Step Name Echo value to see the log output from the step execution.
  8. Scroll to the bottom of the log output. The expected Hello World message is shown.

    Hello World

Summary
You've accomplished a lot. The Build Forge Management console is running, and is connected to a "remote" server. You learned some basic Build Forge concepts, and are now familiar with the Build Forge deployment architecture and basic configuration. The architecture is able to control a simple build process on a remote server.
Get some rest and be ready for your second day, when you'll use everything created so far to begin building a real-world project: Jakarta Tomcat. Part 2 describes how Build Forge provides for the reuse of existing project scripting. It also covers how Build Forge can extend a simple compile and package build process by adding customization and deployment capability.

Monday, February 21, 2011

CGI installation on ubuntu server

I'm keen to execute perl CGI scripts on my ubuntu system, So i need to configure cgi in my apache2. I followed below steps.


sudo vi /etc/apache2/apache2.conf
Add the following line somewhere:
ServerName localhost
and restart Apache.
sudo /etc/init.d/apache2 restart

Step 1: Create a new Apache site

To create a new site, first create a directory where you want to keep files associated with this site. I like to keep sites in /usr/local/public_html directory. The configuration files for all sites available to Apache are stored in the /etc/apache2/sites-available/ directory. Create a configuration file for your new site (here called samba) by copying the configuration file for the default site.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/samba
Open the new configuration file.
sudo vi /etc/apache2/sites-available/samba
You will notice that there is a lot of stuff between <VirtualHost> tags. You have to edit some of this. Change the DocumentRoot path to point to the newly created site directory.
DocumentRoot /usr/local/public_html
In a similar fashion, change one of the Directory directives (it looks something like this)
<Directory /var/www/>
to be consistent with your site path.
<Directory /usr/local/public_html/>
After making these changes, disable the default site using the Apache disable site script.
sudo a2dissite default
Next, use the Apache enable site script to activate the new site.
sudo a2ensite samba
Finally, restart Apache.
sudo /etc/init.d/apache2 restart
Create a simple index.html file and save it in /usr/local/public_html/ to test your new site. Something simple like
<html>
<strong>Ubuntu Hardy Heron is Here</strong>
Browse (preferable on another machine) to your new site to test the configuration.

Step 2: Install phpmyadmin and create root mySQL user

In order to make mySQL database administration easy, many hosts provide phpMyAdmin. You can easily install this tool on your Ubuntu LAMP server too using the built in package management software. At the command prompt type
sudo aptitude update
sudo aptitude install phpmyadmin
You will have to insert the Ubuntu install CD to complete this installation. During the installation the script will ask which version of Apache to automatically configure. If you installed apache as per this previous postthen select apache2 (with space bar) and continue. After the install completes, the phpMyAdmin script should be in the /usr/share/directory and (after restarting Apache; see above) it should resolve in your browser when you type localhost/phpmyadmin (or xxx.xxx.xxx.xxx/phpmyadmin). If it doesn’t, you must add the following alias and include to the bottom of the apache configuration file apache2.conf in /etc/apache2/.
Include /etc/phpmyadmin/apache.conf
Alias /phpmyadmin /usr/share/phpmyadmin
You can log in by using root as your username and the root password configured during the mySQL installation (if you decided not to enter a mySQL password or were not prompted for a password then the password field is blank by default). Once logged on to phpMyAdmin, you can set a new root password by navigating to the privileges page, clicking the icon that looks like a pencil next to each root account (there may be more than one), and entering a password in the appropriate field of the page that loads.

Step 3: Configure a cgi-bin directory

Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs (here I create /usr/local/public_html/cgi-bin) and add the following to the site configuration file (again between the <VirtualHost> tags).
ScriptAlias /cgi-bin/ /usr/local/public_html/cgi-bin/
<Directory /usr/local/public_html/cgi-bin/>
          Options ExecCGI
          AddHandler cgi-script cgi pl
</Directory>
The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.




To Enable the apache with the CGI :

Enable CGI and perl support for apache2 server
You need to install the following package
sudo aptitude install libapache2-mod-perl2
Configure a cgi-bin directory
You need to create a cgi-bin directory using the following command
sudo mkdir /home/www/cgi-bin
Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs and add the following to the site configuration file (again between the <VirtualHost> tags).
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
<Directory /home/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>
The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.
Test your Perl Program
cd /home/www/cgi-bin
sudo nano perltest.pl
Copy and paste the following section save and exit the file.
###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";
for ($i=0; $i<10; $i++)
{
print $i."<br />";
}
###End###
make sure you change permissions on it
sudo chmod a+x perltest.pl
Now open your web browser open http://yourserverip/cgi-bin/perltest.pl.It should be working.