If you have Amazon EC2 linux, then here it is complete tutorial for deploying Java Web Application. First connect to your Amazon EC2 Linux Instance. To run Java web application, you need below things to be installed
- JDK
- Tomcat
- Database (Here I am using MySQL)
By default you will be connected as ec2-user. Now login as administrator to have complete rights
sudo su
JDK
Amazon EC2 Linux comes with JDK installation. You don't need to install it. Just check its version
java -version
Tomcat 7
Use below commands for Tomcat 7 management
// Install tomcat 7 with webapps docs-webapp admn-webapps sudo yum install tomcat7-webapps tomcat7-docs-webapp tomcat7-admin-webapps // Start tomcat7 server sudo service tomcat7 start // Stop tomcat7 server sudo service tomcat7 stop // Restart tomcat7 server sudo service tomcat7 restart // To know running status of tomcat7 sudo service tomcat7 status // To reload sudo service tomcat7 reload // Add Tomacat 7 service to the autostart sudo chkconfig tomcat7 on
Database (MySQL)
Find below queries for mysql server management
// To install mysql server sudo yum install mysql-server // To start mysql server sudo service mysqld start // To stop mysql server sudo service mysqld stop // To start server on startup sudo chkconfig mysqld on // connect to mysql as root mysql -u root // to change root password mysql> use mysql; mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit // To create database Create database********** create schema demos connect demos quit
Webapps
We should deploy WAR file tomcat webapps folder, so now we have to find out it
// find where "webapps" folder located find / -type d -name 'webapps' // this is general path for tomcat7 webapps folder /var/lib/tomcat7/webapps // change permission for webapps chmod 777 webapps // find server.xml find / -type f -name 'server.xml' // this is general path for tomcat7 server.xml /etc/tomcat7/server.xml // If you want to change server.xml cd /etc/tomcat7 vi server.xml //press insert button //do changes you want //escape key then :wq
Run Web application on Port 80
Tomcat 7 default port is 8080. HTTP default port is 80, So we have to redirect all traffic from port 80 to 8080. Find below for commands
// It will redirect HTTP request data from port 8080 to 80 sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 sudo /sbin/service iptables save
To delete war files or app folders
If you want to remove apps or war files from webapps folder, then use below commands
// for Deleting folders rm -r mydir rm -rf mydir
Deploy WAR File
Now we came to final phase of deploying WAR file. Here we have to copy WAR file from local machine to Amazon EC2 Instance.
Required software
While creating amazon EC2, you will get private key file (.pem) to access EC2 instance. Using Putty and this private key file (.pem), you can connect your Amazon EC2 instance. For more information read this article. FileZilla uses .ppk file. So we have to convert .pem file to .ppk file. We can user PuttyGen for converting .pem file to .ppk file
Convert .pem file to .ppk file
- Download your .pem from AWS
- Open PuTTYgen, select Type of key to generate as: SSH-2 RSA
- Click "Load" on the right side about 3/4 down
- Set the file type to *.*
- Browse to, and Open your .pem file
- PuTTY will auto-detect everything it needs, and you just need to click "Save private key" and you can save your ppk key for use with PuTTY
Setup FileZilla
Install FileZilla and Open It.
Now Click on File > Site Manager
Add a new site with the following parameters:
Host: Your public dns name of ec2 instance, or the public ip address of the server
Protocol: SFTP
Logon Type: Normal
User: From the docs: "For Amazon Linux, the default user name is ec2-user. For RHEL5, the user name is often root but might be ec2-user. For Ubuntu, the user name is ubuntu. For SUSE Linux, the user name is root. Otherwise, check with your AMI provider."
Now click on "Connect"
Now copy WAR file to webapps folder
Restart tomcat server. Now your web application on the net
Hey how to connect to mysql database in my war...??
ReplyDeleteIt is simple. Install MySQL in local PC and EC2 instance with same credentials. Develop Java Web Application with local database. Export it into WAR file. Deploy that WAR file to EC2. Now EC2 MySQL database will be local database to your deployed WAR file.
DeleteHow to start the tomcat
ReplyDeletesudo service tomcat7 start
DeleteHi..I have install tomcat server successfully on aws ec2-server.
ReplyDeleteBut not able to deployed my war file due permission denied on webapps
This comment has been removed by the author.
Deletesudo chmod 777 /var
Deletesudo chmod 777 /var/lib
sudo chmod 777 /var/lib/tomcat7
sudo chmod 777 /var/lib/tomcat7/webapps
run the above commands after verifing your tomcat version
or you can only change the permissions of webappps only by:
sudo chmod 777 /var/lib/tomcat7/webapps
but if we are changing the permission with 777, it will be open to the world which is security threat for our application. But how to overcome this ?
Deletethanks
ReplyDeleteThis was very useful, very clear explaination
ReplyDeleteIEEE Cloud computing DOamin is a general term for anything that involves delivering hosted services over the Internet. IEEE Projects on Cloud Computing The cloud is a metaphor for a global network of remote servers which operates as a single ecosystem, commonly associated with the Internet. IEEE FInal Year Project Domains Final Year Projects for CSE cloud computing is the delivery of computing services—including servers, storage, databases, networking, software, analytics, and intelligence
DeleteJavaScript Training in Chennai
JavaScript Training in Chennai
how to deploy my database .sql file to my AMI i have followed all the above steps
ReplyDeleteThis comment has been removed by the author.
ReplyDeletewhen i deploy the application it fails saying:
ReplyDeleteFAIL - Application at context path /appname could not be started
I have deployed the war file in tomcat and restarted the tomcat.
ReplyDeleteHow can we see whether the application is running or not?
I have deployed the war and restarted the tomcat
ReplyDeleteTomcat is working fine but when i access my application i am getting 404 error
Can you help me in this
This is generally a result of the multi-level distribution systems or multiple entities with individual approaches and goals. visit site
ReplyDelete2) Appliance Search Oven Repair Services in Los Angeles
ReplyDelete