<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JVM Host Blog</title>
	<atom:link href="http://www.jvmhost.com/articles/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jvmhost.com/articles</link>
	<description>Java hosting, regular hosting and VPS hosting blog</description>
	<lastBuildDate>Tue, 18 Jun 2013 14:13:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>How to create and drop databases dynamically from Java/JSP code</title>
		<link>http://www.jvmhost.com/articles/create-drop-databases-dynamically-java-jsp-code</link>
		<comments>http://www.jvmhost.com/articles/create-drop-databases-dynamically-java-jsp-code#comments</comments>
		<pubDate>Tue, 28 May 2013 11:17:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=576</guid>
		<description><![CDATA[JDBC drivers allow developers to perform DDL SQL commands in their Java/JSP code including CREATE and DROP of databases. In this example we present a simple JSP page that will allow you to test these functionality. In cPanel environment the &#8230; <a href="http://www.jvmhost.com/articles/create-drop-databases-dynamically-java-jsp-code">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>JDBC drivers allow developers to perform DDL SQL commands in their Java/JSP code including CREATE and DROP of databases. In this example we present a simple JSP page that will allow you to test these functionality.</em></p>
<p>In cPanel environment the hosting (system) user &#8216;username&#8217; has database creation privilege for any database that starts with username_ prefix. You can verify it by running &#8216;SHOW GRANTS for username@localhost;&#8217; in mysql client:</p>
<pre>GRANT ALL PRIVILEGES ON `username\_%`.* TO 'username'@'localhost'</pre>
<p>This username can thus be used to create/drop databases dynamically from Java/JSP code. To execute DDL (Data Definition Language) commands (CREATE, DROP) you will need to call executeUpdate() instead of most commonly used executeQuery() that returns ResultSet. executeUpdate() returns integer &#8211; 0 in case we run DROP and 1 when we run CREATE.</p>
<pre>int result = statement.executeUpdate("CREATE DATABASE username_databasename");</pre>
<p>You need to update username and password variables in the example code. Also do not forget to put mysql-connector-java.X.X.X-bin.jar in your WEB-INF/lib or application server-wide lib directory.</p>
<p>Specifying database name in connection used to create and drop databases is optional. In case of MySQL you can of course use everlasting &#8216;mysql&#8217; database and in PostgreSQL use &#8216;template1&#8242; database.</p>
<p>In a bare system (e.g. dedicated or VPS without a control panel) you would normally use &#8216;root&#8217; user to create/drop databases unless you created another user and assigned him correct privileges.</p>
<pre>connection = DriverManager.getConnection("jdbc:mysql://localhost/", "root", "rootpassword");</pre>
<p>Note that databases created dynamically will not be shown in cPanel&#8217;s database list.</p>
<p>Here goes the full code of create_drop_database.jsp for your reference:</p>
<pre>&lt;%@page import="java.sql.*" %&gt;
&lt;%

// database to be created/dropped
String database = null;
// your cPanel username and password here - the user has right to create/drop databases
String username = "username";
String password = "secret";

String url = "jdbc:mysql://localhost/";
Connection connection = null;
Statement statement = null;
ResultSet rset = null;
boolean databaseListChanged = false;
int result = -1;

try { 
    Class.forName("com.mysql.jdbc.Driver").newInstance(); 
} catch(ClassNotFoundException e) { 
    out.println("Class not found: "+ e.getMessage());
    return;
}

try {

    connection = DriverManager.getConnection(url, username, password); 
    statement = connection.createStatement();

    out.println("&lt;b&gt;List of databases accessible by user " + username + ":&lt;/b&gt;&lt;br/&gt;");
    rset = statement.executeQuery("SHOW DATABASES");
    while (rset.next())   {
        out.println(rset.getString(1) + "&lt;br/&gt;");
    }
    rset.close();
    out.println("&lt;hr&gt;");

    if (request.getParameter("database") != null) {
        database = (String)request.getParameter("database");
        if (request.getParameter("Create") != null &amp;&amp;
            request.getParameter("Create").equals("Create")) {
            result = statement.executeUpdate("CREATE DATABASE " +  database);
            out.println("result of 'CREATE DATABASE '" + database + " is " + result);
            databaseListChanged = true;
        } else if (request.getParameter("Drop") != null &amp;&amp;
            request.getParameter("Drop").equals("Drop")) {
            result = statement.executeUpdate("DROP DATABASE " +  database);
            out.println("result of 'DROP DATABASE '" + database + " is " + result);
            databaseListChanged = true;
        }
    }

    statement.close();
    connection.close();
    if (databaseListChanged) { response.sendRedirect(request.getRequestURL().toString() + "?result=" + result); }
    if (request.getParameter("result") != null) { 
        out.println("result of last CREATE or DROP database is " + request.getParameter("result") + "&lt;br/&gt;");
    }
%&gt;

&lt;form action="create_drop_database.jsp" method="post"&gt;&lt;table&gt;
&lt;tr&gt;&lt;td align="left"&gt;Database name to create or drop: &lt;input type="text" name="database" size="20"&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;&lt;input type="submit" name="Create" value="Create"&gt;
&lt;input type="submit" name="Drop" value="Drop"&gt;
&lt;input type="reset" name="Reset" value="Reset"&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/form&gt;

&lt;%

} catch (SQLException e) {
    out.println(e.getMessage());
} finally {
    try {
        if(connection != null) connection.close();
    } catch(SQLException e) {}
}

%&gt;</pre>
<p>And here are 2 screenshots of its output:<br />
1) after deleting database (result is 0)<br />
2) after creating database (result is 1)</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2013/05/create_drop_database1.png"><img class="aligncenter size-full wp-image-586" title="create drop database with Java/JSP" src="http://blog.jvmhost.com/articles/wp-content/uploads/2013/05/create_drop_database1.png" alt="create drop database with Java/JSP" width="630" height="174" /></a>Creating and deleting databases on the fly is rarely used as this process is a bit costly IO-wise. If you initially decided for using this method you may need to rethink your needs as probably your goal can be achieved without using create/drop.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/create-drop-databases-dynamically-java-jsp-code/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to call Java executable from PHP?</title>
		<link>http://www.jvmhost.com/articles/how-to-call-java-executable-from-php</link>
		<comments>http://www.jvmhost.com/articles/how-to-call-java-executable-from-php#comments</comments>
		<pubDate>Wed, 01 May 2013 12:09:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP/Perl/Python]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=553</guid>
		<description><![CDATA[For PHP to find Java and see related environment variables you need to set the variables explicitly in your PHP code or use Java related variables predefined in your .bashrc or similar shell resource file. As fastcgi subprocesses do not &#8230; <a href="http://www.jvmhost.com/articles/how-to-call-java-executable-from-php">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>For PHP to find Java and see related environment variables you need to set the variables explicitly in your PHP code or use Java related variables predefined in your .bashrc or similar shell resource file.</em></p>
<p>As fastcgi subprocesses do not start separate shells, they do not read shell resource scripts (e.g. .bashrc) from your home directory. They use environment variables of parent process instead and evidently your expected java related variables will not be there.<br />
You will need to define needed variables in your php script for example:</p>
<p><!--?php <br ?--></p>
<pre>echo 'test without shell (variables defined in php)';
$JAVA_HOME = "/opt/jdk1.6.0_43";
$PATH = "$JAVA_HOME/bin:".getenv('PATH');
putenv("JAVA_HOME=$JAVA_HOME");
putenv("PATH=$PATH");
$r=`echo $JAVA_HOME; which java; java -version 2&gt;&amp;1`;
echo "&lt;pre&gt;$r&lt;/pre&gt;";</pre>
<p>Another solution is to call bash explicitly in shell_exec (or with backticks) as interactive shell and then it will read in your .bashrc defined variables like JAVA_HOME, JAVA_OPTS and PATH:</p>
<p><!--?php <br ?--></p>
<pre>echo 'test with interactive shell (variables in ~/.bashrc)';
$r=`bash -ic 'echo \$JAVA_HOME; which java; java -version 2&gt;&amp;1'`;
echo "&lt;pre&gt;$r&lt;/pre&gt;";
echo 'another variant of above';
exec("bash -ic 'echo \$JAVA_HOME; which java; java -version 2&gt;&amp;1'", &amp;$myOutput, &amp;$result);
echo "&lt;pre&gt;".join("&lt;br/&gt;",$myOutput)."&lt;br/&gt;result = ".$result."&lt;/pre&gt;";</pre>
<p>Note: java messages go to stderr so it must be redirected to stdin to be catched by shell_exec and printed by the php script thus the 2&gt;&amp;1 redirection.</p>
<p>The same way you may define CLASSPATH variable so that your jars are found by java process. Use full paths for other input/output files provided in java command line (for example a file with data to be processed or a file where results will be stored).</p>
<p>On a shared hosting server you have limited JVM related resources like heap and PermGen memory so you should also set correct JAVA_OPTS if you are not using the &#8216;bash interactive&#8217; method.</p>
<p>Yet another approach to get Java and its parameters visible by PHP is to source a file (commonly known as <em>envvars</em> in case of Apache) that sets or modifies environment variables when Apache is started but this solution only makes sense on a VPS or dedciated server as it makes global changes affecting all PHP subprocesses.</p>
<p>And last but not least there is <a title="php-Java bridge project" href=" http://php-java-bridge.sourceforge.net/pjb/">php-java bridge</a> project that you may also use for executing Java code from PHP &#8211; it provides better integration between the languages.<br />
See more in <a title="How to run PHP applications in Tomcat 7 with PHP-Java bridge?" href=" http://www.jvmhost.com/articles/run-php-applications-in-tomcat-7-with-php-java-bridge">How to run PHP applications in Tomcat 7 with PHP-Java bridge?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/how-to-call-java-executable-from-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to recover from java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet</title>
		<link>http://www.jvmhost.com/articles/recovery-from-java-lang-classnotfoundexception-javax-faces-webapp-facesservlet</link>
		<comments>http://www.jvmhost.com/articles/recovery-from-java-lang-classnotfoundexception-javax-faces-webapp-facesservlet#comments</comments>
		<pubDate>Tue, 26 Feb 2013 09:41:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=530</guid>
		<description><![CDATA[If you build a JSF based application that works fine in your local development environment but fails to work after uploading to production server you may find the java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet error in your application server log. SEVERE: Error loading WebappClassLoader      &#8230; <a href="http://www.jvmhost.com/articles/recovery-from-java-lang-classnotfoundexception-javax-faces-webapp-facesservlet">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>If you build a JSF based application that works fine in your local development environment but fails to work after uploading to production server you may find the java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet error in your application server log.</em></p>
<pre>SEVERE: Error loading WebappClassLoader     
  delegate: false                                                 
  repositories:                           
    /WEB-INF/classes/                                             
----------&gt; Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@16fd0b7                    
 javax.faces.webapp.FacesServlet                           
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet</pre>
<p>Most possible cause is that JSF libraries are missing. These could have been included in your local development environment calsspath in a way but have not been bundled into the final WAR file. You should check locally why this happened and correct it for the future.</p>
<p>But for now, to recover from this error simply download latest JSF 2.1 or JSF 1.2 libraries (jars) from <a title="JSF 1.2 2.1 at Oracle" href="http://www.oracle.com/technetwork/java/javaee/download-139288.html">http://www.oracle.com/technetwork/java/javaee/download-139288.html</a> or directly from <a title="JSF 1.2 mojarra and 2.1 at Javaserverfaces" href="http://javaserverfaces.java.net/download.html">http://javaserverfaces.java.net/download.html</a></p>
<p>In case of <strong>JSF 2.1</strong> you get single jar (for example <strong>javax.faces-2.1.17.jar</strong>) to put into Tomcat&#8217;s lib or your application&#8217;s WEB-INF/lib directory.</p>
<p>In case of <strong>JSF 1.2</strong> you get zip archive (for example mojarra-1.2_14-binary.zip) so unpack it and get <strong>jsf-api.jar</strong> and <strong>jsf-impl.jar</strong> from lib directory inside the archive. Have the jars located in Tomcat&#8217;s lib or your application&#8217;s WEB-INF/lib directory or your application server&#8217;s classpath whatever suits you best.</p>
<p>Do not forget to restart your application server and optionally check its logs to confirm the error is gone and no other error messages are present.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/recovery-from-java-lang-classnotfoundexception-javax-faces-webapp-facesservlet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use your existing PEM/OpenSSL key and cerificate with Java keystore</title>
		<link>http://www.jvmhost.com/articles/how-to-existing-pem-openssl-key-cerificate-java-keystore</link>
		<comments>http://www.jvmhost.com/articles/how-to-existing-pem-openssl-key-cerificate-java-keystore#comments</comments>
		<pubDate>Fri, 01 Feb 2013 16:05:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=520</guid>
		<description><![CDATA[Easy method for importing PEM key and certificates into Java keystore with JDK6+. In this tutorial we have x509 PEM OpenSSL certifcate used in Apache2 and related private key. Now we want to use them directly in Tomcat by importing &#8230; <a href="http://www.jvmhost.com/articles/how-to-existing-pem-openssl-key-cerificate-java-keystore">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Easy method for importing PEM key and certificates into Java keystore with JDK6+.</em></p>
<p>In this tutorial we have x509 PEM OpenSSL certifcate used in Apache2 and related private key. Now we want to use them directly in Tomcat by importing them into Java keystore. This situation differs from the case when you generate key using keytool.</p>
<p>What we have:<br />
a) key &#8211; www_yourdomain_com.key<br />
b) certificate &#8211; www_yourdomain_com.crt<br />
c) intermediate cetificates bundle &#8211; www_yourdomain_com_intermediate.crt</p>
<p>JDK6 keytool allows for quite easy import procedure. It was more complicated with previous JDK version. Let&#8217;s go.</p>
<p>1) We build intermediate keystore in PKCS12 format using the key and certificate (including intermediate certifciates).</p>
<pre># cat www_yourdomain_com.crt www_yourdomain_com_intermediate.crt &gt; www_yourdomain_com_all.crt
# openssl pkcs12 -export -in www_yourdomain_com_all.crt -inkey www_yourdomain_com.key \
    -passout pass:changeit &gt; keystore.p12</pre>
<p>2) We then convert this store into a Java key store:</p>
<pre># keytool -importkeystore -srckeystore keystore.p12 -srcstoretype PKCS12 \
    -srcstorepass changeit -deststorepass changeit -destkeypass changeit \ 
    -destkeystore keystore -alias 1 -destalias tomcat</pre>
<p>3) Now we modify HTTPS connector in Tomcat&#8217;s conf/server.xml to read:</p>
<pre>&lt;Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    keystoreFile="${catalina.base}/keystore" keystorePass="changeit"
    keyAlias="tomcat" clientAuth="false" sslProtocol="TLS" /&gt;</pre>
<p><span style="text-decoration: underline;"><strong>Notes:</strong></span><br />
- A (might be temporary) password is needed for destination store and key to avoid a null reference exception at import step<br />
- We use &#8216;alias 1&#8242; for keytool to correcty find our certificate/key in keystore.p12<br />
- Choose your own destination password<br />
- You may import CA/intermediate certificates separately later instead of doing it in one bundle with website certificate like in above example (start with CA cert and go down)</p>
<p>If you are using APR (Apache Portable Runtime) to increase performance then you do not use keystore format. Instead you use the original certificates and key in PEM format (OpenSSL).</p>
<pre>&lt;Connector port="8443" scheme="https" secure="true" SSLEnabled="true"
    SSLCertificateFile="${catalina.base}/www_yourdomain_com.crt"
    SSLCertificateKeyFile="${catalina.base}/www_yourdomain_com.key"
    SSLPassword="" 
    SSLCertificateChainFile="${catalina.base}/www_yourdomain_com_intermedaite.crt"
    keyAlias="tomcat" SSLProtocol="TLSv1"/&gt;</pre>
<p>References: <a title="How to use SSL certificates with Java, Tomcat and cPanel?" href="http://www.jvmhost.com/articles/using-ssl-certificates-with-java-tomcat-cpanel">How to use SSL certificates with Java, Tomcat and cPanel?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/how-to-existing-pem-openssl-key-cerificate-java-keystore/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate and the famous &#8216;Communications link failure&#8217; and &#8216;last packet sent successfuly&#8217; issue solved with C3P0</title>
		<link>http://www.jvmhost.com/articles/hibernate-famous-communications-link-failure-last-packet-sent-successfuly-issue-solved-c3p0</link>
		<comments>http://www.jvmhost.com/articles/hibernate-famous-communications-link-failure-last-packet-sent-successfuly-issue-solved-c3p0#comments</comments>
		<pubDate>Tue, 27 Nov 2012 17:04:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=507</guid>
		<description><![CDATA[With pure hibernate applications longer period of database inactivity can cause first database connection to fail. Subsequent web page refreshes will usually work fine. Why this happens? Usually, MySQL global parameter wait_timeout is set to 28800 (i.e. 8 hours). If &#8230; <a href="http://www.jvmhost.com/articles/hibernate-famous-communications-link-failure-last-packet-sent-successfuly-issue-solved-c3p0">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>With pure hibernate applications longer period of database inactivity can cause first database connection to fail. Subsequent web page refreshes will usually work fine. Why this happens?</em></p>
<p>Usually, MySQL global parameter wait_timeout is set to 28800 (i.e. 8 hours). If your page is not accessed for more than 8 hours (e.g. in the night) MySQL will close the connection on its side. If your database connection config (in Java app) is not prepared for such case your page may display error message and also the error will be logged. For example:</p>
<pre>org.hibernate.SessionException: Session is closed!
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure           
The last packet successfully received from the server was 22,761 milliseconds ago.  The last packet sent successfully to the server was 9 milliseconds ago.
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.</pre>
<p>Usually the connection will be also dropped on your application side and a new one created so subsequent queries may work. But what if we want to be sure our site visitors will not ever see the error? We need to enable idle connection testing.</p>
<p>How to configure database connection parameters in your code to test connection before use? Here goes an example for Hibernate. C3P0 project &#8211; an extension of JDBC &#8211; will help us to achieve it.</p>
<p>You can verify MySQL wait_timeout in your environment with:</p>
<pre>mysql&gt; show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 | 
+---------------+-------+</pre>
<p>To correct the issue in a generic application that uses hibernate-core 3.3.1.GA perform the following 3 steps:</p>
<p>1) Download <a title="hibernate-c3p0 jar" href="http://repo1.maven.org/maven2/org/hibernate/hibernate-c3p0/3.3.1.GA/hibernate-c3p0-3.3.1.GA.jar">hibernate-c3p0-3.3.1.GA.jar</a> and <a title="c3p0 jar" href="http://repo1.maven.org/maven2/c3p0/c3p0/0.9.1/c3p0-0.9.1.jar">c3p0-0.9.1.jar</a> into Tomcat&#8217;s lib or application&#8217;s WEB-INF/lib</p>
<p>2) In generic WEB-INF/classes/hibernate.cfg.xml add 3 new properties:</p>
<pre>// tell hibernate to use C3P0
&lt;property name="connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt; 

// If this is a number greater than 0, C3P0 will test all idle, pooled but unchecked-out connections, every this number of seconds
// Set this to something below your MySQL wait_timeout
&lt;property name="c3p0.idle_test_period"&gt;14400&lt;/property&gt; 

// a query used to test connections
&lt;property name="c3p0.preferredTestQuery"&gt;select 1;&lt;/property&gt;</pre>
<p>Here is full <a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/11/hibernate.cfg.xml.txt">hibernate.cfg.xml</a> from our application.</p>
<p>3) Restart the Tomcat and enjoy!</p>
<p>Other settings that should also be set in hibernate config file (parameter names differ from these used in c3p0.properties) are listed <a title="hibernate specific c3p0 parameters" href="http://www.mchange.com/projects/c3p0/index.html#hibernate-specific">here</a>. Note, that if you do not set them in hibernate config file &#8211; hibernate defaults for these paramters will override c3p0.properties counterparts.</p>
<p>Next planned article will handle the same issue with DBCP.</p>
<p>References:<br />
<a title="C3P0 project" href="http://www.mchange.com/projects/c3p0/index.html">http://www.mchange.com/projects/c3p0/index.html</a><br />
<a title="c3p0 paramteres at jboss wiki" href="http://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool">http://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/hibernate-famous-communications-link-failure-last-packet-sent-successfuly-issue-solved-c3p0/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BIND chrooted nameserver install in Centos 5 &#8211; copy and paste guide</title>
		<link>http://www.jvmhost.com/articles/bind-chroot-nameserver-install-centos-5</link>
		<comments>http://www.jvmhost.com/articles/bind-chroot-nameserver-install-centos-5#comments</comments>
		<pubDate>Wed, 14 Nov 2012 12:34:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dedicated Server]]></category>
		<category><![CDATA[Non-Java]]></category>
		<category><![CDATA[VPS]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=497</guid>
		<description><![CDATA[Many of our Java clients use pure (no control panel) VPSes and sometimes want to run their own nameservers. Some of them may prefer full featured BIND nameserver over DNSmasq described in the other article although BIND comes with larger &#8230; <a href="http://www.jvmhost.com/articles/bind-chroot-nameserver-install-centos-5">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Many of our Java clients use pure (no control panel) VPSes and sometimes want to run their own nameservers. Some of them may prefer full featured BIND nameserver over DNSmasq described in the <a title="Your own lightweight nameserver with DNSmasq" href="http://www.jvmhost.com/articles/lightweight-nameserver-dnsmasq">other article</a> although BIND comes with larger memory footprint. BIND configuration file &#8216;named.conf&#8217; is not installed by default so we need to create it manually.</em></p>
<p>In this copy and paste tutorial we assume that your server IP is 10.1.1.1 and the domain name you are setting DNS zone for is yourdomain.com. Let&#8217;s begin with installing required packages and making named to start at boot time.</p>
<pre>yum -y install bind-chroot bind bind-utils
chkconfig named on</pre>
<p>You may have different bind version so replace 9.3.6 with your version accordingly and copy example configuration files.</p>
<pre>cp /usr/share/doc/bind-9.3.6/sample/etc/* /var/named/chroot/etc</pre>
<p>Optionally, you may delete view &#8220;internal&#8221; from /var/named/chroot/etc/named.conf</p>
<pre>perl -i.bak -ne 'local $/; $f = &lt;&gt;; $f =~ s/view "internal".*?^key ddns_key/key ddns_key/ms; print $f' /var/named/chroot/etc/named.conf</pre>
<p>In view &#8220;external&#8221; replace &#8220;my.external.zone&#8221; with your domain name &#8220;yourdomain.com&#8221;. This will also update zone file name.</p>
<pre>sed -i 's/my.external.zone/yourdomain.com/g' /var/named/chroot/etc/named.conf</pre>
<p>With below command generate and the paste the key into &#8220;key ddns_key&#8221; secret field.</p>
<pre>SECRET=`/usr/sbin/dns-keygen`; sed -i "s/secret .*$/secret \"$SECRET\";/" /var/named/chroot/etc/named.conf</pre>
<p>Copy the other template files into your chrooted /var/named.</p>
<pre>cp -r /usr/share/doc/bind-9.3.6/sample/var/named/* /var/named/chroot/var/named</pre>
<p>And now create zone file for yourdomain.com assuming you will be using your own nameservers ns1/ns2.yourdomain.com with the server&#8217;s public IP. Don&#8217;t forget to update MYDOMAIN, MYIP.</p>
<pre>MYDOMAIN=yourdomain.com; MYIP=10.1.1.1; SERIAL=`date +%s`
echo -e "\$TTL 14400
@       86400   IN      SOA     ns1.$MYDOMAIN. root.$MYDOMAIN. (
        \t$SERIAL    ; serial, timestamp
        \t86400        ; refresh, seconds
        \t7200        ; retry, seconds
        \t3600000        ; expire, seconds
        \t86400 )        ; minimum, seconds

$MYDOMAIN. 86400 IN NS ns1.$MYDOMAIN.
$MYDOMAIN. 86400 IN NS ns2.$MYDOMAIN.

$MYDOMAIN. IN A $MYIP

localhost.$MYDOMAIN. IN A 127.0.0.1

$MYDOMAIN. IN MX 0 $MYDOMAIN.

mail IN CNAME $MYDOMAIN.
www IN CNAME $MYDOMAIN.
ftp IN A $MYIP
$MYDOMAIN. IN TXT \"v=spf1 a mx -all\"" &gt; /var/named/chroot/var/named/yourdomain.com.db</pre>
<p>Clear the environment variables we used and start named.</p>
<pre>unset SECRET MYDOMAIN MYIP SERIAL
service named start</pre>
<p>Finally, you may test if the nameserver responds with correct information by querying it from another host and asking for all records of your domain (zone transfer):</p>
<pre>u7:~$ host -t IXFR yourdomain.com 10.1.1.1
Using domain server:
Name: 10.1.1.1
Address: 10.1.1.1#53

yourdomain.com has SOA record ns1.yourdomain.com. root.yourdomain.com. 1352893256 86400 7200 3600000 86400
yourdomain.com descriptive text "v=spf1 a mx -all"
yourdomain.com mail is handled by 0 yourdomain.com.
yourdomain.com name server ns1.yourdomain.com.
yourdomain.com name server ns2.yourdomain.com.
yourdomain.com has address 10.1.1.1
ftp.yourdomain.com has address 10.1.1.1
localhost.yourdomain.com has address 127.0.0.1
mail.yourdomain.com is an alias for yourdomain.com.
www.yourdomain.com is an alias for yourdomain.com.
yourdomain.com has SOA record ns1.yourdomain.com. root.yourdomain.com. 1352893256 86400 7200 3600000 86400</pre>
<p>Now register your nameservers in your domain registrar control panel. For example:<br />
ns1.yourdomain.com 10.1.1.1<br />
ns2.yourdomain.com 10.1.1.1<br />
and you are all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/bind-chroot-nameserver-install-centos-5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your own lightweight nameserver with DNSmasq</title>
		<link>http://www.jvmhost.com/articles/lightweight-nameserver-dnsmasq</link>
		<comments>http://www.jvmhost.com/articles/lightweight-nameserver-dnsmasq#comments</comments>
		<pubDate>Mon, 12 Nov 2012 16:59:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dedicated Server]]></category>
		<category><![CDATA[Non-Java]]></category>
		<category><![CDATA[VPS]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=489</guid>
		<description><![CDATA[Sometimes your registrar does not provide DNS service but you want to point your domain to your VPS IP address. Your VPS package may also not include DNS service (although if you register a domain thru a big registrar like &#8230; <a href="http://www.jvmhost.com/articles/lightweight-nameserver-dnsmasq">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Sometimes your registrar does not provide DNS service but you want to point your domain to your VPS IP address. Your VPS package may also not include DNS service (although if you register a domain thru a big registrar like eNom or Godaddy it will come with DNS management service).</em></p>
<p>In such case you may change registrar to a better one <img src='http://blog.jvmhost.com/articles/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (transfer out  your domain) or register your own nameservers (ns1.yourdomain.com ns2.yourdomain.com) using your VPS IP (or IPs) in their control panel. Then you can run your own nameserver software on the VPS. Commonly used DNS software includes BIND, tinydns, PowerDNS.</p>
<p>For basic use like serving all queries related to a domain or a set of domains from single IP, Centos users can do below steps when logged in as &#8216;root&#8217;.</p>
<p>1. Install dnsmasq and backup its config file.</p>
<pre>yum install dnsmasq
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak</pre>
<p>2. Disable a few features to lower resource usage.</p>
<pre>sed -i -e 's/^#no-resolv/no-resolv/' -e 's/^#no-poll/no-poll/' -e 's/^#no-host/no-host/' /etc/dnsmasq.conf</pre>
<p>3. In the below command replace yourdomain.com with your domain name and 10.10.10.10 with your VPS IP address.</p>
<pre>sed -i 's/^#address=/doubleclick.net/127.0.0.1/address=\/yourdomain.com\/10.10.10.10/' /etc/dnsmasq.conf</pre>
<p>4. Optionally you can verify the changes you made.</p>
<pre>diff -Nu /etc/dnsmasq.conf /etc/dnsmasq.conf.bak</pre>
<p>5. Start dnsmasq and make it start at boot time.</p>
<pre>service dnsmasq start
chkconfig dnsmasq on</pre>
<p>Now, if you run a DNS query for your domain or a host/subdomain you should receive your VPS IP. For example from your PC ping www.yourdomain.com and 10.10.10.10 (your VPS IP) should reply.</p>
<p>Of course dnsmasq is more powerful than above. You may also use /etc/hosts to define records for selected hosts or enable mail (MX) lines in /etc/dnsmasq.conf to name a few. Dnsmasq.conf contains verbose comments for you to read first.</p>
<p>Note: I do not like the mess created by tinydns anyway you may also try this DNS server due to its low resource usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/lightweight-nameserver-dnsmasq/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Increasing Tomcat logging verbosity for quick problem resolution</title>
		<link>http://www.jvmhost.com/articles/increase-tomcat-logging-verbosity-quick-problem-resolution</link>
		<comments>http://www.jvmhost.com/articles/increase-tomcat-logging-verbosity-quick-problem-resolution#comments</comments>
		<pubDate>Fri, 12 Oct 2012 09:21:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=481</guid>
		<description><![CDATA[Increasing logging verbosity of a Java application can be helpful in quick problem identification and resolution as error messages with default Tomcat logging settings can be quite vague. Default logger in Tomcat 6 and 7 is java.util.logging logger. Previously Log4J &#8230; <a href="http://www.jvmhost.com/articles/increase-tomcat-logging-verbosity-quick-problem-resolution">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Increasing logging verbosity of a Java application can be helpful in quick problem identification and resolution as error messages with default Tomcat logging settings can be quite vague.</em></p>
<p>Default logger in Tomcat 6 and 7 is java.util.logging logger. Previously Log4J was used. See an example how increased logging verbosity helps solving an issue. When deploying fresh Grails application all error messages we initially got were:</p>
<pre>INFO: Deploying web application archive /home/grailswebapp/appservers/apache-tomcat-7.0.30/webapps/grailswebapp.war
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Oct 12, 2012 4:00:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Oct 12, 2012 4:00:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/tixomatic] startup failed due to previous errors</pre>
<p>Quite unclear information, not leading straight to a reason and solution. Let&#8217;s now stop the Tomcat and put logging.properties file into application&#8217;s WEB-INF/classes with the following content:</p>
<pre>org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler</pre>
<p>Clear catalina.out and start Tomcat. Now we get (scroll right to see &#8216;Access denied for user&#8217; message):</p>
<pre>INFO: Deploying web application archive /home/grailswebapp/appservers/apache-tomcat-7.0.30/webapps/grailswebapp.war
Oct 12, 2012 4:13:37 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Oct 12, 2012 4:13:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Oct 12, 2012 4:13:42 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'grailswebapp_dbuser1'@'server.company.net' (using password: YES))
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:126)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:707)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
    at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:153)
    at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:170)
    at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:127)
    at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.configureWebApplicationContext(GrailsConfigUtils.java:121)
    at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:104)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)</pre>
<p>and a few more related exceptions ending with</p>
<pre>Oct 12, 2012 4:13:42 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Oct 12, 2012 4:13:42 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/tixomatic] startup failed due to previous errors</pre>
<p>It means somewhere in the code the database host was referenced with a host name different from localhost while only localhost access is granted or SQL credentials are wrong. Just checking these 2 items made problem solved and logging.properties was removed to avoid excessive logging.</p>
<p>Similar issue where increased verbosity helped with quick resolution was</p>
<pre>org.apache.catalina.core.StandardContext start SEVERE: Error listenerStart
org.apache.catalina.core.StandardContext start SEVERE: Context [/grailswebapp] startup failed due to previous errors</pre>
<p>In this case it was a ClassNotFoundException and problem has been solved after adding required class or jar.</p>
<p>Yet another example of unclear error message when JDK6 was used for application compiled with JDK7:</p>
<pre>INFO: Deploying web application archive /home/tomcat/apache-tomcat-7.0.32/webapps/ROOT.war
Oct 13, 2012 8:03:33 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Oct 13, 2012 8:03:33 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors</pre>
<p>And after enabling verbose logging we know where we are (wrong JDK version used):</p>
<pre>INFO: Deploying web application archive /home/tomcat/apache-tomcat-7.0.32/webapps/ROOT.war
Oct 13, 2012 8:05:19 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class website.web.MainAggregation
java.lang.UnsupportedClassVersionError: website/web/MainAggregation : Unsupported major.minor version 51.0 (unable to load class website.web.MainAggregation)</pre>
<p>Refer <a title="Tomcat 7 documentation on logging" href="http://tomcat.apache.org/tomcat-7.0-doc/logging.html">Tomcat 7 documentation</a> for more on logging.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/increase-tomcat-logging-verbosity-quick-problem-resolution/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to connect with PgAdminIII to PostgreSQL with SSH tunnel</title>
		<link>http://www.jvmhost.com/articles/connect-pgadminii-postgresql-ssh-tunnel</link>
		<comments>http://www.jvmhost.com/articles/connect-pgadminii-postgresql-ssh-tunnel#comments</comments>
		<pubDate>Fri, 28 Sep 2012 13:38:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Control Panels]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Non-Java]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=470</guid>
		<description><![CDATA[On a cPanel server remote connections to PostgreSQL server are disabled by default. See how to leverage SSH tunnel and connect with PgAdminIII and Putty. If your key-based connection works fine (refer &#8216;Steps to connect with Putty using key based &#8230; <a href="http://www.jvmhost.com/articles/connect-pgadminii-postgresql-ssh-tunnel">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>On a cPanel server remote connections to PostgreSQL server are disabled by default. See how to leverage SSH tunnel and connect with PgAdminIII and Putty.</em></p>
<p>If your key-based connection works fine (refer &#8216;Steps to connect with Putty using key based authentication&#8217; article) lets start Putty again and create SSH tunnel needed to remotely connect to PostgreSQL database.</p>
<p>1. Load my_conection seesion but do not open it.<br />
2. Goto Connection &gt; SSH &gt; Tunnels in left side Putty area.<br />
3. Find &#8216;Add new forwarded port&#8217; secton and:<br />
a) in &#8216;Source port&#8217; enter an arbitrary local port for example 5433 (it can be also 5432 if no PostgreSQL server is using it locally).<br />
b) in &#8216;Destination&#8217; enter destiantion hostname and port for example: 127.0.0.1:5432<br />
Click Add.</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_putty_tunnel.jpg"><img class="aligncenter size-full wp-image-471" title="SSH putty tunnel" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_putty_tunnel.jpg" alt="SSH putty tunnel" width="456" height="442" /></a>4. Go to Session and save my_connection<br />
5. Download PgAdminIII (in this tutorial version 1.16.0 was used &#8211; you can use any other client the same way). PostgreSQL server will see the connection as coming from 127.0.0.1 and will accept it when correct database credentials are given.</p>
<p>6. Start pgAdminIII &gt; File &gt; Add Server and fill in connection details</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_pgadminIII.jpg"><img class="aligncenter size-full wp-image-472" title="SSH pgadminIII" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_pgadminIII.jpg" alt="SSH pgadminIII" width="600" height="669" /></a>Click Ok and you should be connected. When in Windows you can see your tunnel listening and established connection by listing open ports and connections with &#8216;netstat -an&#8217; in command line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/connect-pgadminii-postgresql-ssh-tunnel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to connect with Putty using key based authentication &#8211; screenshots</title>
		<link>http://www.jvmhost.com/articles/connect-putty-key-based-authentication-cpanel</link>
		<comments>http://www.jvmhost.com/articles/connect-putty-key-based-authentication-cpanel#comments</comments>
		<pubDate>Fri, 28 Sep 2012 13:10:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Control Panels]]></category>
		<category><![CDATA[Non-Java]]></category>

		<guid isPermaLink="false">http://www.jvmhost.com/articles/?p=451</guid>
		<description><![CDATA[On a cPanel server where password login is not allowed you will need to use SSH key. Follow this guide to have key based SSH connection set up in Putty. For SSH access from Windows we recommend PuTTY and PuTTYgen &#8230; <a href="http://www.jvmhost.com/articles/connect-putty-key-based-authentication-cpanel">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>On a cPanel server where password login is not allowed you will need to use SSH key. Follow this guide to have key based SSH connection set up in Putty.</em></p>
<p>For SSH access from Windows we recommend PuTTY and PuTTYgen from <a title="Putty download" href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html ">http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html </a></p>
<p><em><span style="color: #993300;"><strong>1. Login to cPanel and go to Security &gt; SSH/Shell Access to generate SSH key pair for use with a standalone SSH client like Putty.</strong></span></em></p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_shell_access.jpg"><img class="aligncenter size-full wp-image-452" title="SSH shell access" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_shell_access.jpg" alt="SSH shell access" width="499" height="103" /></a><span style="color: #993300;"><strong><em>2. Click Manage SSH Keys &gt; Genarate a New Key. You should use a password to protect the key. You will be asked the password each time you use the key.</em></strong></span></p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_generate_keypair.jpg"><img class="aligncenter size-full wp-image-453" title="SSH generate keypair" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_generate_keypair.jpg" alt="SSH generate keypair" width="630" height="370" /></a>This will create kay pair (id_dsa, id_dsa.pub) in /home/USERNAME/.ssh<br />
In 11.32.4 version of cPanel there seems to be a problem with generating key size different than 1024.</p>
<p><em><strong><span style="color: #993300;">3. In Public key section click &#8216;Manage Authorization&#8217; and &#8216;Authorize&#8217;</span></strong></em></p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_manage_authorization2.jpg"><img class="aligncenter size-full wp-image-454" title="SSH manage authorization" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSh_manage_authorization.jpg" alt="SSH manage authorization" width="630" height="122" /><img class="aligncenter size-full wp-image-455" title="SSH manage authorization" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_manage_authorization2.jpg" alt="SSH manage authorization" width="630" height="77" /></a></p>
<p>This will create authorized_keys and authorized_keys2 file in your /home/USERNAME/.ssh<br />
In each of these files your public key string is included.</p>
<p><em><strong><span style="color: #993300;">4. In Private key section click &#8216;View/Download&#8217; beside the key (id_dsa) and then</span></strong></em> <em><strong><span style="color: #993300;">under &#8216;Private SSH Key id_dsa conversion to ppk format:&#8217; enter the password you set in step #2 and click Convert to get the key in format suitable for Putty and download the key (id_dsa.ppk or id_rsa.ppk) to your PC.</span></strong></em></p>
<p>Note: Before leaving this cPanel page check first if the downloaded key is the same as the one displayed in cPanel. You may just check last line starting with &#8216;Private-MAC:&#8217;.</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_private_key_download_ppk.jpg"><img class="aligncenter size-full wp-image-458" title="SSH private key download" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_private_key_download.jpg" alt="SSH private key download" width="630" height="82" /><img class="aligncenter size-full wp-image-459" title="SSH private key download ppk" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_private_key_download_ppk.jpg" alt="SSH private key download ppk" width="600" height="356" /></a><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_private_key_download_ppk2.jpg"><img class="aligncenter size-full wp-image-460" title="SSH private key download ppk2" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_private_key_download_ppk2.jpg" alt="SSH private key download ppk2" width="573" height="288" /></a></p>
<p><em><strong><span style="color: #993300;">5. Run putty.exe and in Putty:</span></strong></em></p>
<p>a) Enter your hosting server hostname (consult &#8216;New Hosting Account Created&#8217; email if in doubt)<br />
b) Set correct SSH port (consult &#8216;New Hosting Account Created&#8217; email if in doubt)</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_putty_define_connection.jpg"><img class="aligncenter size-full wp-image-461" title="SSH putty define connection" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_putty_define_connection.jpg" alt="SSH putty define connection" width="456" height="442" /></a></p>
<p>Enter connection label e.g. &#8216;my_connection&#8217; and click Save. &#8216;my_connection&#8217; will appear added below &#8216;Default Settings&#8217;.</p>
<p>c) Click SSH &gt; Auth in the left menu and choose &#8216;Private key file for authentication&#8217;. Use path to your id_dsa.ppk or id_rsa.ppk here.</p>
<p>In the example the file was read from &#8220;C:\&#8221; path.</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_load_ppk.jpg"><img class="aligncenter size-full wp-image-462" title="SSH load ppk" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_load_ppk.jpg" alt="SSH load ppk" width="456" height="442" /></a></p>
<p>d) Click Connection &gt; Data in the left menu and set &#8216;Auto-login username&#8217; to your username.</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_username.jpg"><img class="aligncenter size-full wp-image-463" title="SSH username" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_username.jpg" alt="SSH username" width="456" height="442" /></a></p>
<p>e) Click Session in the top of left menu, make sure &#8216;my_connection&#8217; is highlighted and save.<br />
f) Double click the session name. You should be prompted for password from step #2 and subsequently logged in.</p>
<p><a href="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_putty_connected.jpg"><img class="aligncenter size-full wp-image-464" title="SSH putty connected" src="http://blog.jvmhost.com/articles/wp-content/uploads/2012/09/SSH_putty_connected.jpg" alt="SSH putty connected" width="580" height="158" /></a></p>
<p>In another article we will show how to use this encrypted connection to have PgAdminIII or any other PostgreSQL client tunnelled to the PostgreSQL server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jvmhost.com/articles/connect-putty-key-based-authentication-cpanel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

 Served from: blog.jvmhost.com @ 2013-06-19 23:20:50 by W3 Total Cache -->