Newsflash & Grails useful stuff

Hello to you, good ‘ol people who follow me. Sorry I haven’t been around for like 2 weeks or so, but I was occupied with some development I’m doing and that it needs to be done before Monday. But here I’m again, giving you guys the newsflash of these few days. To start, let me say that yesterday, I was able to buy tickets for the Civil War premiere on April 27th, so expect a non spoiler review.

Getting back to the initial objective of the post, today I’m bringing you a step by step guide for Grails deployment in Tomcat server, in Debian-based server environments (Debian server, Ubuntu server, etc.). I’m going to try to make this tutorial for beginners, but if you have any doubts, feel free to ask me.

So, let’s start!

Prepare your server environment.

First thing you want to do, is to prepare the software needed for the deployment, which in this case it’s free and open for us to use it (yei!). The software components we’ll be using are: Apache2 web server (or httpd), phpMyAdmin, MySql server, Tomcat application server, all in their latest releases.

We start by installing Apache2, from a terminal (local or SSH, doesn’t matter), executing the following command:

sudo apt-get install apache2

When prompted, say ‘Yes’ and the terminal will do all the work. If successful, you should be able to see something like this when navigating to the server’s IP address:

apache-default-page1

Secondly, let’s install MySQL server (I’m using this for the example, could be the one you prefer), by executing this command:

sudo apt-get install mysql-server

The terminal is going to ask you for a root password, so type in the password to use for the root user in MySQL and that will do it.

Thirdly, the phpMyAdmin. In Debian based servers, the installation is similar to the ones we have already ran, with this command:

sudo apt-get install phpMyAdmin

 

When the command prompts for the server selection, choose the freshly installed Apache2 web server.

Fourthly, the famous Tomcat server. I strongly recommend downloading the binaries and upload them into the server, in the path you prefer. To keep it organized, I recommend the /usr/share folder for the upload. I’m assuming that the binaries are inside a tar file still, so we start by “un-tar”ting them, with the command:

tar -xvf [name of the file].tar.gz

Once untarted, and assuming that Java is properly installed on your server instance, you can go on and start Tomcat, but let’s just let it off for now.

Config the software.

The config is made mostly on the phpMyAdmin, because we need to connect this client to the MySQL server. Fortunately, the process is quite simple, here it goes:

First, edit the config.inc.php file located on the root folder of phpMyAdmin, which is located in /etc/phpmyadmin/ if you installed the client using apt-get.

Once located, we have to edit it, to set our database server password properly.

These are the lines you’re looking for:

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'your password';

Prepare the deployment.

We’re almost done! Be proud of yourself! This is no easy config if made with no tutorials, so be proud.

The last config we need to do is our Tomcat server, to make it capable of connecting both back end with it’s database. We need to edit the Tomcat‘s context.xml file in order to connect, and since this is the most tricky part, I developed a connection string for MySQL, check it out below:

<Resource name="jdbc/[database name]"
auth="Container"
type="javax.sql.DataSource"
username="[your user]"
password="[your password]"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql:/[database IP address]:3306/[database name]"
maxActive="15"
maxIdle="3" />

You are maybe wondering how the Tomcat is going to know the way MySQL communicates and handles the data and well, the question is about to be answered. What you need to do is go ahead and download the connector from MySQL and place the .jar file into the lib folder of Tomcat.

What’s next?! Well, now it’s time to upload our webapp, so feel free to generate the web apps’ WAR file, and just copy it to the webapps folder of the Tomcat. After the upload, just start the server with the startup.sh script in the bin folder, wait for the server to start, and enjoy your web app!

That’s it for today folks! Hope this tutorial will make your life easier! See ya around!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s