Monday, November 28, 2011

Apache http Server (Basics Configurations)

Apache Http Server is an open-Source Web server that is being used by many organizations for hosting their applications. Apache Http server when used with a J2ee application server as a back end can provide lot of features to the applications and developers. In this article we will see how we can install and configure apache http server in RHEL5.

If you need to configure apache from source, check here.

  • Install the Http Server (Or) check whether it is available
  • Starting and Stopping Server.
  • Construct an Site www.sam.com and associate an IP address to it
  • Construct multiple Sites with Same IP address
  • Construct an Alias to the Site.


1. Install the Http Server (Or) check whether it is available
The Http server packages are already available in the Linux. We just need to find whether they are available .Once we are sure they are available we need to install the server. The packages that we need to check are httpd, httpd-devel and apr.

We can check using,

Yum list installed | grep httpd

If they are already installed, then the list will be shown by using this command.

2. Starting and Stopping Server
       In Order to start the server we can use,

     Service httpd start

      service httpd restart : restarts the Server
      service httpd stop : Stops the Server 

The configuration file is available in location /etc/httpd/.

3. Construct a Site www.sam.com and associate an IP address to it
       Now we will see how we can construct a sample site .First create an html file for the site. The files that apache web server will check will be available in /var/www/ location. For every site we create we can create files here or we can create some other places and provide the location in the configuration file. Create the directories and files like,

mkdir -p /var/www/virtual/www.sam1.com/html


Create an index.html page with some sample html content.

vi /var/www/virtual/www.sam1.com/html/index.html

<html><head>www.sam1.com</head>
<body>
<b>www.sam1.com
</body></html>

Now it’s time to edit the configuration file, open the configuration file like,

vi /etc/httpd/conf/httpd.conf

Search for a term NameVirtualHost

Uncomment the NameVirtualHost and add the ip address besides it like

NameVirtualHost 10.5.11.119 (This is the ip address on which we are hosting our application)

Note: The NameVirtualHost allows hosting multiple sites with single IP address.

Once the NameVirtualHost is uncommented.Add the VirtualHost element at the end of the file likes,

The Virtual host configuration block is used to create an independent set of configuration directives that apply to a particular hostname or IP address. It is often used in conjunction with system level IP aliasing or dummy network interfaces in order to establish one or more "virtual" servers which all run on the same physical machine. Add the following at the end of the file,

<VirtualHost *:8080>
    ServerAdmin root@www.sam1.com
    DocumentRoot /var/www/virtual/www.sam1.com/html/
    ServerName www.sam1.com
    ErrorLog logs/dummy-www.sam1.com-error_log
    CustomLog logs/dummy-www.sam1.com-access_log common
</VirtualHost>

The elements are pretty much explanatory. The ‘DocumentRoot’ is the file that will be displayed for the user when he enter the site.It is the index.html file that we created in the location /var/www/virtual/www.sam1.com/html/.The ServerName is the name of the host and others belong to logs locations.

Once the configuration in the httpd.conf file is done, we need to make changes to the /etc/hosts file.

The hosts file is a computer file used in an operating system to map hostnames to IP addresses.

Vi /etc/hosts and add the following at the end,

192.168.0.254          www.sam1.com

Once these changes are done, we need to restart the network and http server like,

Service network restart
Service httpd restart

Once these are ok with no issues, try accessing www.sam1.com from a browser and we will see the index.html page.


4. Construct multiple Sites with Same IP address

Create file locations for the second site like,

mkdir -p /var/www/virtual/www.sam2.com/html

Create an index.html page with some sample html content.

vi /var/www/virtual/www.sam2.com/html/index.html

Once these are done, modify the /etc/hosts file and add a new host like,

# do not remove the following line, or various programs
# that require network functionality will fail.
10.5.11.119     www.sam1.com
10.5.11.119     www.sam2.com

Once the file is modified, restart the network. After this update the httpd.conf file with this,

<VirtualHost 10.5.11.119>
    ServerAdmin root@www.sam2.com
    DocumentRoot /var/www/virtual/www.sam2.com/html/
    ServerName www.sam2.com
    ErrorLog logs/dummy-www.sam1.com-error_log
    CustomLog logs/dummy-www.sam1.com-access_log common
</VirtualHost>
    
Restart the httpd server and access www.sam2.com.

5. Construct an Alias to the Site.

In order to create an alias for a site, we need modify the /etc/hosts and httpd.conf file like

10.5.11.119     www.sam1.com
10.5.11.119     www.sam2.com    www.sam3.com

I have added the www.sam3.com as an alias to www.sam2.com

Restart the network and edit the httpd.conf file.For the www.sam2.com site we are creating an alias.

<VirtualHost 10.5.11.119>
    ServerAdmin root@www.sam2.com
    DocumentRoot /var/www/virtual/www.sam2.com/html/
    ServerName www.sam2.com
    ServerAlias www.sam3.com
    ErrorLog logs/dummy-www.sam1.com-error_log
    CustomLog logs/dummy-www.sam1.com-access_log common
</VirtualHost>

Once done, restart httpd server and access www.sam2.com and www.sam3.com which gives us the same pages.
Read More

Friday, November 11, 2011

Deploy a Web Application in LifeRay Portal Server


As we are aware that LifeRay portal server is used for deploying Portal applications, But LifeRay allows us to deploy a standard web application (written in servlet, jsp e.t.c) into the LifeRay portal server as a Portlet application.
In This article we will see how we can deploy a web application as a Portlet in LifeRay portal server.
1. Create a sample web application.
2. Copy the application into the LifeRay Portal Server
3. Add the Portlet
4. Basic Issues

1. Create a sample web application

Create a sample web application (For this demo purpose I have created a sample web application which will have a link, when clicked shows a message).

2. Copy the application into the LifeRay Portal Server

Copy the Application into the auto Deploy folder for liferay.When we see the directory structure of the Liferay portal server , we see

Data
Deploy (Auto Deploy Folder For LifeRay Portal Server)
Jboss-5.1.0
License
Readme.html

Copy the web application into the Deploy directory.we can see the messages in the console about the deployment like,

13:05:53,426 INFO  [AutoDeployDir] Processing SampleApp.war
13:05:53,427 INFO  [PortletAutoDeployListener] Deploying package as a web application
13:05:53,428 INFO  [PortletAutoDeployListener] Copying portlets for /usr/liferay-portal-6.0.6/deploy/SampleApp.war
  Expanding: /usr/liferay-portal-6.0.6/deploy/SampleApp.war into /tmp/20111111130553428
  Copying 1 file to /tmp/20111111130553428/WEB-INF/classes
  Copying 1 file to /tmp/20111111130553428/WEB-INF/classes
  Copying 1 file to /tmp/20111111130553428/WEB-INF
  Copying 1 file to /tmp/20111111130553428/WEB-INF
  Copying 1 file to /tmp/20111111130553428/WEB-INF
  Copying 1 file to /tmp/20111111130553428/WEB-INF/jsp/liferay/wai
  Copying 20 files to /usr/liferay-portal-6.0.6/jboss-5.1.0/server/default/deploy/SampleApp.war
  Copying 1 file to /usr/liferay-portal-6.0.6/jboss-5.1.0/server/default/deploy/SampleApp.war
  Deleting directory /tmp/20111111130553428
13:05:53,566 INFO  [PortletAutoDeployListener] Portlets for /usr/liferay-portal-6.0.6/deploy/SampleApp.war copied successfully. Deployment will start in a few seconds.
13:05:58,194 INFO  [TomcatDeployment] deploy, ctxPath=/SampleApp
13:05:58,347 INFO  [PortletHotDeployListener] Registering portlets for SampleApp
13:05:58,468 INFO  [PortletHotDeployListener] 1 portlet for SampleApp is available for use

Once the Deployment is done,we need to wait for a few minutes until the portlet is auto deployed.

3. Add the Portlet

Create a Page like ,
Select Page from Add Toolbar, Enter the Page Name. The new page will be added.
Click that new Page.











Once the page is created now add the web application as a portlet.Select the web application from the “Undefined” category and click “add”.

The application will be added under the new page we created.

























More Articles To Come , Happy Coding.......
Read More

Thursday, November 10, 2011

LifeRay With OpenID


In This article, we will see how we can configure the OpenID server and link that to the LifeRay Portal Server. For this article I have used the Atlassian Crowd Server as OpenID server. This article goes in steps.

1.    What is an OpenID ?
2.    Benefits of OpendID
3.    How Does It Work
4.    Backend Library
5.    Download the Atlassian Crowd OpenID Server.
6.    Configure the Crowd Open ID Server.
7.    Configure LifeRay with the Crowd Open ID Server.
8.    Create a user in Crowd OpenID Server.
9.    Generate OpenID for the User.
10. Login into LifeRay using OpenID.

This article mainly focuses on OpenID details, configuration of LifeRay with Atlassian's CrowdID OpenID server.

1. What is an OpenID?

OpenID is an open, decentralized, free framework for user-centric digital identity.

OpenID starts with the concept that anyone can identify themselves on the Internet the same way websites do-with a URI (also called a URL or web address). Since URIs are at the very core of Web architecture, they provide a solid foundation for user-centric identity.


2. Benefits of OpenID

From end user View, An OpenID is a single username and password that lets you login to any OpenID-enabled site. OpenID makes remembering different usernames and passwords for different sites a thing of the past.

From Website View, facilitates registration for end users.

The end purpose of OpenID is to keep all the sensible information in the provider so that it's not spread through all the websites where the user has an account. This makes it much easier to protect and keep up to date.

3. How does it work?

  1. User selects an OpenID Provider and creates an account in it. The provider gives the user a unique URL that identifies him.
  2. User finds a new website and wants to create an account. He finds out happily that the website supports OpenID (it's an OpenID consumer).
  3. User logs in with his OpenID URL
  4. The website uses the URL to contact the OpenID provider of the user and requests it some information to be able to create the new account for the user
  5. The user is redirected to his provider's website to:
    1. Login to demonstrate he is the owner of the URL
    2. Accept the request for information from the original website (the providers usually allow maintaining several profiles and the user can select which one to use)
  6. The user is then redirected to the original website with all the necessary information
  7. The website takes that information and creates an account for the user (only the first time) and logs him in
  8. The user logs in

4. Backend Library

LifeRay uses OpenId4java as the backend library to implement the OpenID functionality. This library was chosen because:
  • It is free software with a License compatible with Life ray’s (Apache License 2.0)
  • It seems to have the largest community among the alternatives

5. Download the Atlassian Crowd Server.

Download the Crowd OpenID server from Here .

6. Configure the Crowd Open ID Server.

The first step in configuring the Crowd OpenID server are ,

Specify your Crowd Home directory by editing the configuration file at CROWD-INSTALLATION/WEB-INF/classes/crowd-init.properties for Unix(if working in Unix) and
windows(if working for windows)

crowd.home=/usr/crowd (I changed the directory name to crowd)

2. Go To /usr/crowd/apache-tomcat/conf/Catalina/localhost and open the file crowd.xml (else create one with the data)

Change the docBase with the correct path of crowd-webapp like

<Context path="/crowd" docBase="/usr/crowd/crowd-webapp" debug="0" reloadable="false">
..
..
..
</Context>
3. Go to the Location, /usr/crowd/crowd-openidserver-webapp/WEB-INF/classes
and modify the crowd.properties like,

application.name                       crowd-openid-server
application.password                 password
application.login.url                   http://localhost:8095/openidserver

crowd.server.url                        http://localhost:8095/crowd/services/

session.isauthenticated              session.isauthenticated
session.tokenkey                       session.tokenkey
session.validationinterval           0
session.lastvalidation                 session.lastvalidation

Modify the crowd.server.url and application.login.url.

4. Go to the Location, /usr/crowd/apache-tomcat/conf/Catalina/localhost
and create a file(if not available) openidserver.xml with the following content

<Context path="/openidserver" docBase="../../crowd-openidserver-webapp" debug="0">

    <Resource name="jdbc/CrowdIDDS" auth="Container" type="javax.sql.DataSource"
              username="sa"
              password=""
              driverClassName="org.hsqldb.jdbcDriver"
              url="jdbc:hsqldb:${catalina.home}/../database/crowdopenidserverdb"
              minEvictableIdleTimeMillis="4000"
              timeBetweenEvictionRunsMillis="5000"
              maxActive="20"
            />

<Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="false"/>

</Context>

If the file exists, add the line leaving the rest untouched,

<Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="false"/>

5. Once all these modifications are done. Restart the tomcat server . The url will be

For OpenID server: http://localhost:8095/openidserver/login.action

6. Once the configurations are done , Start the Tomcat server in the same directory location and access the url in a browser and follow the steps,


Since the Crowd OpenID server is available only for a trail version, it will ask for a Evaluation key. We need to register with Atlassian Crowd Server and get a key from the web site. Once the get the key , the server will allow us to move further .The next step would be to configure Type of Database

 










The Next Step would be to select the options,












Give a name to the Deployment Title, Value to Session Time Out and Base URL.

The next step would be to configure the Internal Directory, I just gave the Name and took the default value for others

















The Next step would be to configure and Administrator account,












The next step is to configure the Integrated applications .I have taken the default options.










And Then the final step, 







Once the configuration is done correctly, a login screen will be shown. We can login using the username and password which we created as a administrator.

7. Configure LifeRay with the Crowd Open ID Server.

The Configuration of LifeRay with Crowd OpenID server is done in the 3 step above.

8. Create a User in Crowd OpenID Server.

Login in as administrator (the user that we created while configuring the Crowd OpenID server).Once we login into the Server, we see the screen

















Select Users on the top panel . In the Left pane , click on the Add User. 
 

 














 Create a user with all required details



 













9. Generate OpenID for the User.

Once the user is configured, open the url
http://localhost:8095/openidserver/login.action in a browser and login using the username and password that we created before.









Once we login, we are given with a OpenID.
 











10. Login into LifeRay using OpenID.

Start the LifeRay Server and sign in using the OpenID option under the Sign In portal.

 









Enter the OpenID url that we got and click sign in. It will take us to the OpenID server. Once we are logged in, we see the following page. Select the Allow Always option.











Once we select the Allow Always, we will be taken back to the LifeRay server










By This we complete the Configuration of OpenID server with Liferay.
More Articles To Come , Happy Coding..






Read More