Deployment procedure of Apache-Tomcat Server on Ubuntu

Step 1:   System Requirements

    1.2 Software requirement
        a)    Ubuntu Client 12.10 64 bit
        b)    JDK 7
        c)    Apache-Tomcat -6.0.36
        d)    MySQL Server -5.5

Step 2:  Software installation and configuration

    2.1 Operating system dependency update
        update all essential Ubuntu services.
        Open the terminal or Press Ctrl + Alt + T , write the command on terminal
        sudo apt-get update
  2.2  JDK installation and configuration
         2.2.1  JDK installation
            Open the terminal or Press Ctrl + Alt + T , write following command on terminal
            a) Navigate to desktop
            cd  ~/
            b) To download  jdk  for 64 bit
            wget -c --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" "http://goo.gl/AJ1oS" -O jdk-7u7-nb-7_2-linux-x64-ml.sh
            c) To execute
            chmod +x jdk-7u7-nb-7_2-linux-x64-ml.sh
            d) To install jdk
            sudo sh jdk-7u7-nb-7_2-linux-x64-ml.sh

      2.2.2 JDK configuration
            Java Home variable setup
            After jdk install completed then setup JAVA_HOME variable
            Open the terminal or Press Ctrl + Alt + T , write following command on terminal
            a) Open '.bashrc' file
            nano ~/.bashrc
            b) Edit  file
             press  left,right,up,down arrow to go the place where you want to edit
            c) Add the following lines at the end of the file named
             Example: Write those lines in this file       
                export JAVA_HOME=/home/abcd/jdk1.7.0_07
                export JRE_HOME=/home/abcd/jdk1.7.0_07/jre

            d) Save  file
                press  Control +o
                 then  press Enter
            e) exit  from  file
                press Control+x
Note: If you do not want to save anything in press control+x



 2.3 MySQL Installation and Configuration
        Open the terminal or Press Ctrl + Alt + T, write following command on terminal
        a)  To install mysql server
          sudo apt-get install mysql-server-5.5
        b) Write down PC’s root user password
        c) Write down mysql root user password

2.4 Tomcat installation and configuration
   2.4.1 Tomcat installation
            Open the terminal or Press Ctrl + Alt + T, write following command on terminal
           a) Navigate to desktop
           cd ~/
           b)  To download apache-tomcat-6.0.36
            wget http://mirrors.ispros.com.bd/apache/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.tar.gz   
           c) To untar apache-tomcat-6.0.36
            tar zxvf apache-tomcat-6.0.36.tar.gz
    2.4.2 Tomcat configuration
           Open the terminal or Press Ctrl + Alt + T, write following command on terminal
          To give the permission
            chmod -R a+x  apache-tomcat-6.0.36
         Tomcat user configuration
          a) open  tomcate-users.xml  file
           nano ~/apache-tomcat-6.0.36/conf/tomcat-users.xml
          b) edit file
           press  left,right,up,down arrow to go the place where you want to edit

                <tomcat-users>
                 <role rolename="manager-gui"/>
                  <role rolename="manager-script"/>
                  <user username="tomcat_username" password="tomcat_password" roles="manager-gui,manager-script"/>
                </tomcat-users>


           e) Save file
              press  Control+o
                then  press Enter
           f) exit  from file 
              press  Control+x  
        Note: If you do not want to save anything in  press  control+x

Change uploads war file size (if required):
        Default file upload is 50MB.
             Open the terminal or Press Ctrl + Alt + T, write following command on terminal
          a) open  web.xml file
             nano ~/apache-tomcat-6.0.36/webapps/manager/WEB-INF/web.xml
           b) edit file
              press  left,right,up,down arrow to go the place where you want to edit
                    <multipart-config>
                      <!-- 150MB max -->
                      <max-file-size>152428800</max-file-size>
                      <max-request-size>152428800</max-request-size>
                      <file-size-threshold>0</file-size-threshold>
                    </multipart-config>

           e) Save file
              press  Control+o
                then  press Enter
           f) exit  from file 
              press  Control+x  
     Note: If you do not want to save anything in  press  control+x


Step 4: Database

        Requirements:
        1. musicmanagementdb.sql
        2. Mysql server installed

4.1 Create a new Database
    Open the terminal or Press Ctrl + Alt + T, write following command on terminal
    a) login mysql server
    mysql  -u[username]  -p[password];    
    (Exapme mysql –uroot -pabcd)
    b) Create musicmanagementdb database
    create database musicmanagementdb;
    c) To check database created database list
    show databases;
    you  will see musicmanagementdb in databases
    d) Logout mysql server
     exit;

4.2 Restore the database
    Open the terminal or Press Ctrl + Alt + T, write following command on terminal
    a) Restore freebeepay Database
    mysql -u[uname] -p[pass] musicmanagementdb < [backupfile.sql]  
    (Example mysql -uroot -pfreebee musicmanagementdb <  musicmanagementdb.sql )
    Note: To ensure database backup must be exist current location

Step 5: How to start tomcat server

Start or stop tomcat server.
    Open the terminal or Press Ctrl + Alt + T, write following command on terminal
    a) Start tomcat server
    ~/apache-tomcat-6.0.36/bin/startup.sh
    b) Stop tomcat server
    ~/apache-tomcat-6.0.36/bin/shutdown.sh
    c) Check tomcat server stop or not
    tail -100 ~/apache-tomcat-6.0.36/logs/catalina.out


Remote Access To MySQL Database Server on ubuntu from Any Computer


Login MYSQL Server computer by 'SSH Secure Shell Client'
ssh username@ip
   Example: ssh a@192.168.1.96
Enter pc password

Login MYSQL Server  mysql -u[username] -p[password]
   Example: mysql -uroot -pabcd ;



Set bind-address   = 0.0.0.0 on my.cnf for access any computerEdit mysql my.cnf
   $ nano /etc/mysql/my.cnf
   Set bind-address   = 0.0.0.0

Save my.cnf file and exit.  

Check '%' Host and 'root' User on user table
    mysql>  SELECT * FROM mysql.user WHERE HOST='%' AND User='root';


If '%' Host and 'root' User do not exist on user table. Execute below sql query    Mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'mysql_password'  WITH GRANT OPTION
     Example: GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY ‘abcd’ WITH GRANT OPTION
Logout from mysql server
    mysql> exit;

Restart MySql server:
   $ sudo/etc/init.d/mysql restart
To Check remote to remote enable
   mysql -u[root] -p[password] -h[mysql_serverip]
   Example; mysql -uroot -pabcd -h192.168.1.96

Deployment procedure of Glass fish Server on Ubuntu


System Requirements

server requires the following dependencies to be installed.

1. Ubuntu 11.04 OS
2. Jdk 7
3. Mysql server 5.1.54
4. Glassfish Server version 3.1


Step 1: Login to the server

1.1 Remote login server by ‘SSH Secure Shell Client’

1.2 Login directly as root user
After logging into the server directly, open the terminal window.

Write following command sequentially in the terminal window.

JDK
1. sudo add-apt-repository --yes ppa:webupd8team/java
2. Write your root user password
3. sudo apt-get update
4. sudo apt-get install --yes oracle-java7-installer

MYSQL SERVER
5. sudo apt-get install --yes mysql-server
Glassfish
6. cd /root/
7. wget http://download.java.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2.zip
8. unzip glassfish-3.1.2.2.zip


Step 2: Database

Requirements:
1. databasebackup.sql
2. Mysql server installed


3.1 Create a new Database
1. Open the terminal window

2. Type: MYSQL –uusername –ppassword;” (-uroot –ppassword123) to login to mysql server
3. Type: CREATE DATABASE databasebackup CHARACTER SET utf8 COLLATE utf8_general_ci;
4. Type: SHOW DATABASES; (to list the existing database and check if the new DB is there.)
5. Type: “exit” to logout from the mysql server

3.2 Restore the database
1. Upload the database backup file (i.e databasebackup.sql) to a location on the server.
2. Open the terminal window.
3. Goto the directory where the main changescript is uploaded
4. Type: MYSQL -uusername -ppassword “name of database” < databasebackup.sql
5. Type: MYSQL –uusername –ppassword; to login to mysql server
6. Type: USE databasebackup; to select the database
7. Type: SELECT * FROM table_name; (if the databasebackup.sql was successfully restored then this will display the table_name table information)



Step 3: How to start glassfish server
After you have unzipped the glassfish server successfully, go into the glassfish bin directory to start the server

Start or stop glassfish server.

1. Open the terminal window
2. Type: cd /root/glassfish3/bin/
This command will take you to the Glassfish installer directory.
3. Type: ./asadmin start-domain domain1
This command will start the Glassfish server.
4. Type: ./asadmin stop-domain domain1
This command will start the Glassfish server.


Step 4: How to deploy Server

Requirements:
1. server.war file
2. Glassfish server version 3.1
3. Mysql server installed
Please collect the latest server WAR file from the developer. If you have the latest war file, use the following steps to deploy the server. Please also ensure that the server database is setup before you proceed.

4.1 Deploy WAR File:
1. To check if the Glassfish server is up and running . Open a web browser and type the URL to access the the admin console for Glassfish. You will need to specify the port number as well (example 'http:// 192.168.1.105:4848') the default port number of glashfish3 is 4848.
2. Log into the Glasshfish admin panel (default username:password)
3. Click on ‘Application’ link from side bar
4. Click on ‘deploy’ button
5. Select the location radio button. If the server WAR file is located your local hard disk, select the first option. If it is on the server hard disk then select the second option.
6. Click on ‘Ok’ button
7. If the server is successfully deployed then you will see it in the applications panel


Step 5: How to setup the server storage directory

Requirements:
1. Newly installed server WAR file in glassfish server
2. The databasebackup.sql is running on a mysql server
Once the server is successfully deployed and configured to the correct database you will need to specify the image repository in glassfish and the mysql database. This is the directory where all the images will be stored.


5.1 Create the storage directory
1. Open the terminal window.
2. Type: MKDIR <foldername> (/imagedir)
3. Type: CD /imagedir (go inside the /imagedir and create the following subdirectories /abc, /def)
4. Type: MKDIR abc
5. Type: MKDIR def
6. Type: CHMOD 777 /imagedir (to apply the read write execute permission)

5.2 Setup repository path in Glassfish
The first step is to add the directory as a property in Glassfish Server
1. Open a browser and login to the glassfish admin console (https://192.168.1.105:4848)
2. Extend 'Server-config' in side menu bar (Configurations>server-config)
3. Extend in 'Virtual Service' (Configurations>server-config> virtual service)
4. Click on 'Server' (Configurations>server-config> virtual service> server)
5. Click the “Add Property” button in Additional Properties .
6. Enter name and values
7. Example name=”alternatedocroot_1”
8. Example value= “from=/ imagedir /* dir=/root/glassfish/”
9. Click on 'Save' button