Thursday, March 29, 2012

Updating Liferay Tomcat Bundle to use MySQL instead on HSQL

Though we are still on Glassfish because of Java development issues, here are a few notes made whilst mucking about with Tomcat. We created another site (www.centralsup.com) with Liferay on Tomcat using this approach 'cos we don't intend to do any development on that site
===
WARNING
This is all very standard, there are additional security precautions that should be taken at the network, OS, Db, WAS and application layers.
===
FYI: I've used Daily.co.uk and Rimuhosting.com as VPS providers. Rimu are little more expensive but better; Daily had some weird thing with their Virtualisation model which fouled up my Java memory somehow when they "patched" it (and incidentally, they rebooted my VPSs far too often for my liking...) - this issue broke two of my websites and I chose to move elsewhere. So, you get what you pay for and I'm with Rimu again - in fact, if you want a really shortcut just ask the guys there to install Liferay when you buy the server!

- On new server you will just have an IP address.
- you will have root access and have a password
- putty to that IP address port 22 and log in as root
DOWNLOADS
1. mkdir /usr/local
2. mkdir /usr/local/downloads
3. mkdir /usr/local/downloads/liferay
4. From the new directory use wget to download the Liferay Tomcat bundle
5. (maybe) if the name of the file that is downloaded is not called 'liferay-portal-tomcat-6.0.6-20110225.zip' then rename it using 'mv liferay-portal-tomcat-6.0.6-20110225.zip
6. mkdir /usr/local/downloads/mysql
8. if necessary rename the file correctly to mysql-connector-java-5.1.18.zip
9. Unzip it.
10. You should have new directory called /usr/local/downloads/mysql/mysql-connector-java-5.1.18
11. ..in there is a file called 'mysql-connector-java-5.1.18-bin.jar' This is important, you will need to copy it to a new location later.
INSTALLATION Step 1 - Default bundle
1. from within /usr/local/downloads/liferay 'cp liferay-portal-tomcat-6.0.6-20110225.zip /usr/local/
2. cd /usr/local
3. unzip liferay-portal-tomcat-6.0.6-20110225.zip
4. ls
- - should see a new directory 'liferay-portal-6.0.6' and the zip file.
5. Delete the zip file: 'rm liferay-portal-tomcat-6.0.6-20110225.zip'
6. cd /usr/local/liferay-portal-6.0.6/tomcat-6.0.29/bin
- - in here you should see a script called 'startup.sh'
7. bash startup.sh
8. in a browser goto :8080
- - you should see Liferay with the 7 Cogs set up and default demo users.
- - if all is well shutdown 'bash shutdown.sh'
INSTALLATION Step 2 - Prepare MySQL
The server should have MySQL installed already (that should happen on installation of Ubuntu). so check:
1. sudo netstat -tap | grep mysql
- - you should see something like this:
- - 'tcp 0 0 localhost.localdo:mysql *:* LISTEN 9276/mysqld'
2. reset the root password, you do this using the statement dpkg-reconfigure mysql-server-5.1'
- - the MySQL shuts down and a dos-like dialog box opens up and you can enter a new password (write it down, it's important!).
3. Create a new database called 'lportal'.
- log on to mysql using 'root' and your new password: 'mysql --user=root --password='
4. create the database: and the command prompt, mysql> create database lportal;
- - (NB you need the semi-colon in that statement.
5 confirm the database is created: 'show databases;'
mysql> show databases;
- you should see a list of databases including 'lportal'.
NOTE - this does not create all the tables for the portal, just the empty database. On start up, if Liferay doesn't find the tables it creates the whole database from scratch inside the empty lportal database - Or at least it SHOULD do. If it doesn't you will have to run the script held in the Liferay Dependencies files (see liferay.com for that).
INSTALLATION Step 3 - Connect to MySQL Database
1. cd /usr/local/downloads/mysql/mysql-connector-java-5.1.18
2. cp mysql-connector-java-5.1.18-bin.jar /usr/local/liferay-portal-6.0.6/tomcat-6.0.29/lib/ext/
3. cd /usr/local/liferay-portal-6.0.6/tomcat-6.0.29/lib/ext/
4. ls
- - should see your filed copied there, amongst other stuff.
5. navigate to /usr/local/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/classes
6. In here you need to create, and update, the portal-ext.properties file (this is what tells Tomcat to use the MySQL database)
7. vi portal-ext.properties
8. paste in the following:
#
# MySQL
#
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=
9. .. then :w and :q to save the information.
10. cd /usr/local/liferay-portal-6.0.6/tomcat-6.0.29/bin
11 bash startup.sh
12 go to :8080 and wait for it to boot up into the default area again. This time, it should be using the MySQL database. You can check this by creating a new portal user and using the MySQL commands to list the users in the lportal database.
You have a production server ready to go.