Wednesday, May 14, 2008

My first webapp, Walkthrough pt2: Server configuration

In order to prepare a system for the db-enabled webapp, follow the steps below:
  1. Download+install Java (preferrably Java6 SDK). Setup $JAVA_HOME environmental variable accordingly, so that $JAVA_HOME/bin/java is the JVM executable. For linux, package managers now offer sun-java-* packages, you'd better AVOID the gcj stuff, for maximum compatibility.
  2. Download+install MySQL. Again, linux distros have packages in default repos. Edit the MySQL configuration file (/etc/mysql/my.cnf or whatever), so that, under "[mysqld]", you COMMENT the "skip-networking" option and give a good bind address (127.0.0.1 is safest). Part of the file will look like
    [mysqld]
    user = mysql
    pid-file = /var/run/mysqld/mysqld.pid
    socket = /var/run/mysqld/mysqld.sock
    port = 3306
    basedir = /usr
    datadir = /var/lib/mysql
    tmpdir = /tmp
    language = /usr/share/mysql/English
    bind-address = 127.0.0.1
    # skip-networking
    The example listens only on the local loopback interface, change for use with remote tomcat. In general, test access to your mysql daemon with "telnet localhost 3306", or such.
  3. Download+install Tomcat-5.5, preferrably the zip package. Linux distros offer tomcat packages. Consider $CATALINA_HOME to be the installation path, so that $CATALINA_HOME/bin/startup.sh starts the server. Tomcat requires special administration:
    1. Download the MySQL JDBC connector, and place the JAR file in $CATALINA_HOME/common/lib, for all webapps to see. Keep in mind that the MySQL driver class is com.mysql.jdbc.Driver.
    2. See to that the Security Manager lets the driver create a socket to the listening server port, by adding a policy entry to $CATALINA_HOME/common/conf/catalina.policy:
      grant codeBase "jar:file:/path/to/tomcat5.5/common/lib/mysql-connector-java-5.1.5.jar!/-" {
      //permission java.net.SocketPermission "localhost:", "connect";
      //permission java.net.SocketPermission "127.0.0.1:3306", "connect";
      //permission java.net.SocketPermission "127.0.0.1:3306", "resolve";
      permission java.security.AllPermission ;
      };


  4. For development, NetBeans 6.1 is good, Eclipse offers some not-so-good plugins, and Vi is always a safe choice.

1 comment:

La Gigi said...

αχ ναι liebe τι ωραια που τα λες