I don't do LAMP, I do JELP (Java, EE5, Linux, PostgreSQL). Here are instructions for installing Java, GlassFish and PostgreSQL on Ubuntu 6.06 "Dapper Drake" Server Edition. No gotchas, just a bunch of steps that I hadn't found together in one place.
I am getting ready for the fall
semester. My software engineering students will be using GlassFish for their projects. In
order to avoid the "but it worked on my computer" syndrome, I make them
deploy their apps on a server in my office. I just installed Ubuntu Server Edition. These
instructions got me started with the Linux basics. This blog has the
(not so) gory details for installing Java, GlassFish, and PostgreSQL. At
the end are the obligatory reflective comments.
I ran all these steps as super-user. Note that Ubuntu Server has no GUI interface by default. I simply put the in a corner, connected with ssh, and ran the commands in a terminal. Required skills: bash shell basics and a stone-age text editor such as vi.
Java
deb http://us.archive.ubuntu.com/ubuntu/ dapper universe multiverse deb-src http://us.archive.ubuntu.com/ubuntu/ dapper universe multiverse
apt-get install sun-java5-jdk
java -versionYou should get something like
java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
Wow. That was phenomenally easy.
GlassFish
wget http://java.net/download/javaee5/promoted/Linux/glassfish-installer-v2-b09.jarbut substitute the correct version number.
java -jar -mx256M glassfish-installer-v2-b09.jar(Again, substitute the correct version number.) The installer automatically runs in headless mode, without a GUI.
mv glassfish /opt/glassfish-v2-b09 ln -s /opt/glassfish-v2-b09 /opt/glassfish
cd /opt/glassfish /opt/glassfish/lib/ant/bin/ant -f setup.xml
mv /opt/glassfish/domains/domain1 /opt ln -s /opt/domain1 /opt/glassfish/domains/domain1
/opt/glassfish/bin/asadmin change-admin-password --user admin Please enter the old admin password>adminadmin Please enter the new admin password>(password is echoed) Please enter the new admin password again>(password is echoed)The password needs to be at least 8 characters long.
#! /bin/sh
### BEGIN INIT INFO
# Provides: glassfish
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: glassfish initscript
# Description: A simple initscript for the glassfish app server
### END INIT INFO
#
# Author: Cay S. Horstmann (http://horstmann.com)
#
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/glassfish/bin
DESC="Java EE5 App Server"
NAME=glassfish
ASADMIN=asadmin
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
# Read config file if it is present.
#if [ -r /etc/default/$NAME ]
#then
# . /etc/default/$NAME
#fi
#
# Function that starts the daemon/service.
#
d_start() {
$ASADMIN start-domain \
|| echo -n " already running"
}
#
# Function that stops the daemon/service.
#
d_stop() {
$ASADMIN stop-domain \
|| echo -n " not running"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload|restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 10
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
No, I don't know what I am doing. I just modified
/etc/init.d/skeleton. Then I ran update-rc.d glassfish defaults

PostgreSQL
apt-get install postgresql-8.1 postgresql-client-8.1
su postgres psql ALTER USER postgres WITH PASSWORD 'secret'; \q exit
wget http://jdbc.postgresql.org/download/postgresql-8.2dev-503.jdbc3.jar(Change the version number...)
/opt/glassfish/bin/asadmin create-jdbc-connection-pool --datasourceclassname org.postgresql.ds.PGSimpleDataSource --restype javax.sql.DataSource --property portNumber=5432:password=secret:user=postgres:serverName=localhost:databaseName=postgres PostgresPool /opt/glassfish/bin/asadmin create-jdbc-resource --connectionpoolid PostgresPool jdbc/Postgres
Try it out. Download the Elvis quiz app.wget http://horstmann.com/elvis/quiz.zip mkdir quiz cd quiz jar xvf ../quiz.zipEdit build.properties and change the password. Edit conf/persistence.xml and specify the data source:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="defaultPersistenceUnit">
<jta-data-source>jdbc/Postgres</jta-data-source>
<properties>
<property name="toplink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>Now run/opt/glassfish/lib/ant/bin/ant run-clientYou should get a message such as
run-client:
[java] elvis.entity.Quiz[id=26,title=A Java Trivia Quiz,questions={IndirectList: not instantiated}]
The Obligatory Reflective Comments
First off, apt-get is great.
This was far and away the easiest JDK installation I have ever done. I
didn't have to fuss with the PATH. I'll get alerted when new versions
appear and can update them easily. There is some behind-the-scenes work
that makes Sun's Java the preferred one (rather than GCJ).
I'd love to be able to run apt-get install glassfish.
I never installed much software on a headless server before and I was pleasantly surprised how easy it was. But if that isn't your cup of tea, you can use the admin web interface to do most steps.
The Glassfish installer needs to do something about the service script. Maybe someone can contribute this? It is an open source project, after all.