Installing Elgg on WebSphere sMash
Pre-requisites
You will need Mysql 5.x running and accessible. You will need to know a username and password for a user who has access rights to create databases.
Installation
| Instruction | What am I doing? |
|
Download and unzip the latest WebSphere sMash command line interface.
|
This is the bootstrap which will get the rest of WebSphere sMash for you as you request it.
|
Add the location of the newly unzipped zero directory to your path.
Windows: set PATH=c:\where_i_unzipped\zero;%PATH%
Linux: export PATH=/home/me/where_i_unzipped/zero:$PATH
|
The WebSphere sMash command line zero must use the CLI you downloaded, not any other one you may have downloaded earlier - otherwise you might get older sMash modules downloaded.
|
|
Go to the where_i_unzipped/zero directory and zero resolve.
|
This downloads the core of sMash, and sets up your local repository under zero/zero-repository.
|
| In the same directory zero create elgg.
|
This creates a new sMash project called "elgg", from a default template which does not yet include php dependencies.
|
Go to the newly created zero/elgg/config directory and edit the ivy.xml file. Add the following lines in the dependencies section.
<dependency org="zero" name="zero.php" rev="[1.0.0.0, 2.0.0.0["/>
<dependency name="mysql-connector-java" org="mysql" rev="[5.0.0.0,6.0.0.0["/>
|
These tell WebSphere sMash that your project requires php and mysql.
|
|
In your new zero/elgg directory zero resolve.
|
The newly requested php and mysql libraries will be downloaded to your local repository.
|
Edit the zero.config file in zero/elgg/config, add the following lines:
/config/handlers += [{
"events" : "requestBegin",
"handler" : "URLRewrite.class"
}]
|
The will allow us to manipulate URLs in a similar way to Apache mod_rewrite.
|
|
Create a java class called URLRewrite.java in the zero/elgg/java directory. The code is given below.
|
This is the handler code that implements the mod_rewrite rules.
|
|
In your new zero/elgg directory zero compile.
|
The will compile the URLRewrite.java class.
|
|
Get the latest copy of Elgg (mine is Elgg 1.5). Unzip the contents into your /zero/elgg/public directory. Now you should have a elgg directory under 'zero/elgg/public. Move the entire contents up one level, so all the files which were under zero/elgg/public/elgg are now under zero/elgg/public. Delete the empty public/elgg directory.
|
Moving the contents up makes public the root directory, so you do not have to specifically name the root directory for WebSphere sMash.
|
Edit the php.ini file in zero/elgg/config, add the following lines:
SMTP = <smtp server>
sendmail_from = <from field for emails sent by Elgg>
smtp_port = <smtp port>
|
The SMTP settings will allow elgg to send out emails when a new user registers to Elgg.
|
Edit the php.ini file in zero/elgg/config, modify the following line:
error_reporting = E_ALL
|
Removing E_STRICT prevents a large number of strict warning messages from filling the sMash logs.
|
Use mysql or similar to create an empty database called elgg.
mysql -uroot -p<password>
mysql> create database elgg;
mysql> exit
|
Elgg needs a database to start from, but will create and populate its own tables - so you just create an empty database for it to work with.
|
|
In your zero/elgg directory - zero start.
|
This starts the ZSO launcher for your application - you should see the message saying that sMash is listening on port 8080. If you do not like the choice of port, you can zero stop, alter the zero.config file in zero/elgg/config, and zero start again.
|
|
Navigate in a browser to http://localhost:8080, and you should see the Elgg installation page. Follow the on screen install instructions.
|
If in doubt - follow the instructions in the Elgg installation documentation. If you wish to Enable HTTPS logins then follow the instructions here. You will also need to start WebSphere sMash on ports 80 and 443.
|
Here is the URLRewrite handler that will manipulate URLs in the same way as mod_rewrite.
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import zero.core.context.GlobalContext;
public class URLRewrite {
static String reWriteBase = "/";
static String reWrites[][] = {
{"^action\\/([A-Za-z\\_\\-\\/]+)$","engine/handlers/action_handler.php?action=$1"},
{"^export\\/([A-Za-z]+)\\/([0-9]+)$","services/export/handler.php?view=$1&guid=$2"},
{"^export\\/([A-Za-z]+)\\/([0-9]+)\\/$","services/export/handler.php?view=$1&guid=$2"},
{"^export\\/([A-Za-z]+)\\/([0-9]+)\\/([A-Za-z]+)\\/([A-Za-z0-9\\_]+)\\/$","services/export/handler.php?view=$1&guid=$2&type=$3&idname=$4"},
{"^\\_css\\/css\\.css$","_css/css.php"},
{"^pg\\/([A-Za-z0-9\\_\\-]+)\\/(.*)$","engine/handlers/pagehandler.php?handler=$1&page=$2"},
{"^pg\\/([A-Za-z0-9\\_\\-]+)$","engine/handlers/pagehandler.php?handler=$1"},
{"xml-rpc.php","engine/handlers/xml-rpc_handler.php"},
{"mt/mt-xmlrpc.cgi","engine/handlers/xml-rpc_handler.php"},
{"^tag/(.+)/?$","engine/handlers/pagehandler.php?handler=search&page=$1"}
};
static HashMap < Pattern,String > hm = new HashMap < Pattern,String > ();
static {
for ( String patterns[] : reWrites ) {
hm.put(Pattern.compile(patterns[0]),patterns[1]);
}
}
public void onRequestBegin() {
String path = GlobalContext.zget("/request/path");
if ( path.startsWith(reWriteBase) ) {
path = path.substring(reWriteBase.length());
}
for( Entry < Pattern,String > entry : hm.entrySet() ){
Pattern pattern = entry.getKey();
Matcher matcher = pattern.matcher(path);
if (matcher.find()) {
String newuri = matcher.replaceFirst(entry.getValue());
String[] array = newuri.split("\\?");
String newPath = array[0];
String query = null;
if ( array.length == 2 ) {
query = array[1];
}
String oldQuery = GlobalContext.zget("/request/queryString");
String newQuery = oldQuery;
if ( query != null ) {
if ( oldQuery == null || oldQuery.equals("") ) {
newQuery = query;
} else {
newQuery = oldQuery + "&" + query;
}
}
GlobalContext.zput("/request/path", reWriteBase + newPath);
GlobalContext.zput("/request/queryString",newQuery);
}
}
}
}
-- timpreece - 31 Jul 2009