You are on page 1of 6

Download the necessary files

1. Download a JDK on the Sun's website and install it.


2. Download the JBossWeb Win32 zipped archive [ 27 Mb ] on the JBoss.org
website.
3. Download the native Win32 PHP module archive [ 8 Mb ] here.
4. Download MySQL 5.x from here.
5. Download MySQL-Connector-Java from here.

Install MySQL v5.x

Run the executable file and use the following settings:


1. Typical Setup
2. Skip Sign-Up
3. Make sure "Configure the MySQL Server now" is checked
4. "Detailed Configuration"
5. "Developer Machine"
6. "Multifunctional Database"
7. "InnoDB Tablespace Settings" - leave everything default
8. "Decision Support (DSS)/OLAP"
9. Make sure "Enable TCP/IP Networking" and "Enable Strict Mode" are
checked and leave the port number at 3306 (at this point, if you have a
firewall, it will usually try to access itself on the localhost)
10. "Best Support For Multilingualism" - makes UTF-8 the default character
set
11. Check "Install As Windows Service"
12. I recommend checking "Include Bin Directory in Windows PATH"
13. Enter your root password and I would recommend not checking "Enable
root access from remote machines"
14. Then hit "execute" and it'll install and set it up.
Install JDK 1.6 Update 3
Install JDK 1.6 Update 3 as usual with default path and settings.

Extract the archives


1. Extract jbossweb-1.0.1.GA-windows-i686.zip to the root of your c: drive.
2. Extract php5servlet-windows-i586-SP1.zip to the root of your c: drive.
3. Move the contents of c:\php5servlet-windows-i586-SP1\PHP folder to
c:\php5.
4. Make a copy of the C:\php5\bin\php.ini-recommended to
%WINDIR%\php.ini.
5. Open %WINDIR%\php.ini and change “extension_dir” value to
c:/php5/bin/ext/. If you want to use PHP short tag <? change
short_open_tag value to On. Uncomment “extension=php_mysql.dll” and
“extension=php_mbstring.dll” and append “extension=php_mysqli.dll”.

Configure the PHPServlet (All contexts)


1. Find and uncomment this line:
<Listener
className="org.apache.catalina.servlets.php.LifecycleListener"/>in the
file:
C:\jbossweb-1.0.1.GA\server\default\deploy\jbossweb.sar\server.xml

2. Modify (if you want) the default port the server will be listening to, here on
port 8080:
<Connector protocol="HTTP/1.1" port="8080"
address="${jboss.bind.address}"
redirectPort="8443" xpoweredBy="true"/>

3. Find and uncomment the servlets (.php & .phps) declarations:


<servlet>
<servlet-name>php</servlet-name>
<servlet-class>org.apache.catalina.servlets.php.Handler</servlet-
class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>6</load-on-startup>
</servlet>
<servlet>
<servlet-name>phps</servlet-name>
<servlet-class>org.apache.catalina.servlets.php.Highlight</servlet-
class>
</servlet>
in the file:
C:\jbossweb-1.0.1.GA\server\default\deploy\jbossweb.sar\conf\web.xml

4. Find and uncomment the servlets (.php & .phps) mappings:


<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>phps</servlet-name>
<url-pattern>*.phps</url-pattern>
</servlet-mapping>
in the file:
C:\jbossweb-1.0.1.GA\server\default\deploy\jbossweb.sar\conf\web.xml

5. Add/Modifiy one line in the <welcome-file-list> element:


<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.php</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
in the file:
C:\jbossweb-1.0.1.GA\server\default\deploy\jbossweb.sar\conf\web.xml

Check your MS Windows Environment

Variables

1. Create JAVA_HOME = <PATH TO YOUR JDK INSTALLATION>


2. Create PHP_HOME = c:\php5
3. Append “;%JAVA_HOME%\bin;%PHP_HOME%\bin;%PHP_HOME%\bin\ext;”
to PATH variable

It's now time to run


1. C:\jbossweb-1.0.1.GA\bin\run.bat will run the server within a console,
check for error messages!
2. Create a file named index.php in the folder
C:\JBossWeb\server\default\deploy\jbossweb.sar\ROOT.war.
3. Edit the created file with your favorite editor and add this line:
<?php phpinfo(); ?>

Check the installation via the JMX-CONSOLE or via


http://localhost:8080/index.php

Suggestions

Use C:\jbossweb-1.0.1.GA\bin\service.bat to setup JBossWeb as a windows


service.

Notes
1. You need to restart the server to validate changes in the
%windir%/php.ini
2. Keep your JSP or PHP files in the following directory C:\jbossweb-
1.0.1.GA\server\default\deploy\jbossweb.sar\ROOT.war

Connect PHP with MySQL

1. Create your database and table:


Open MySQL Command Line Client.
mysql> create database test;
mysql> use test;
mysql> create people(
id integer,
name varchar(20),
item varchar(20)
);

2. Create your PHP file named “index.php” and save it in C:\jbossweb-


1.0.1.GA\server\default\deploy\jbossweb.sar\ROOT.war.
<?php
$username = "root";
$password = "mat3";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon
$selected = mysql_select_db("test",$dbh)
or die("Could not select first_test");
// you're going to do lots more here soon
if (mysql_query("insert into people values('1','Indranil','Burger')")) {
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
?>

Open your browser and type http://localhost:8080/index.php to test your


page.

Connect JSP with MySQL


Create your JSP file named “fetch.jsp” and save it in C:\jbossweb-
1.0.1.GA\server\default\deploy\jbossweb.sar\ROOT.war.
<%@ page import="java.sql.*" %>
<%
//String connectionURL =
"jdbc:mysql://localhost:3306/test?user=root;password=mat3";
String connectionURL = "jdbc:mysql://localhost/test";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "mat3");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM people");
while (rs.next()) {
out.println(rs.getString("name")+"<br>");
}
rs.close();
%>
</body></html>

Open your browser and type http://localhost:8080/fetch.jsp to test your


page.

You might also like