Flex/Flash to STOMP to ActiveMQ

Software Development 2 Comments

Recently, I wanted to look into writing a Flash client which uses the STOMP protocol to talk to an Apache ActiveMQ Server. I found this great blog, Flex chat application that uses Apache ActiveMQ and STOMP, that talks about creating a STOMP-based chat client using Flex. I tried to follow the blog and found that it was missing several installation steps and instructions on how to use the free Flex SDK. To save you the trouble, I’ve documented the missing steps below.

Note: I’ve never developed with Flash or Flex before but after some reading, I came to the realization that both were different ways of doing the same thing. Flash is an in-browser platform which uses the ActionScript language, similar to a Java Applet using the Java language. Flex could be considered as way to package ActionScript 3 (AS3) code, pre-built AS3 GUI libraries, and media files for compilation into a SWF file. This paragraph is probably totally inaccurate but it helps me keep things organized in my head.

First, download and unzip the latest Apache ActiveMQ Server to a directory like c:\install\apache-activemq.

  • Enable the STOMP support:
    • Open and edit c:\install\apache-activemq\conf\activemq.xml
    • Search for the text "<transportConnectors>"
    • Add the stomp connector definition under the existing openwire connector:
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
    <transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
    
  • Run the ActiveMQ Server with this command: c:\install\apache-activemq\bin\activemq.bat. The ActiveMQ Server will start listening on ports 61616 and 61613.

Second, download and install the latest Flash Security Policy Server to a directory like c:\install\flash-policy-server. The Flash Security Policy Server allow cross-domain STOMP connections to be made from the Flex chat client.

Note: Adobe added cross-domain security restrictions to Adobe Flash 9 players and later versions. This restriction prevents the Flash player from connecting to another server or to a different port on the same server (such as the STOMP port 61613) from which the Flash player’s hosting HTML page was served. To allow the Flash player to talk to the different STOMP port 61613, we have to run a flash security policy server on the same hosting server with a configuration allowing the action.

  • Allow Flash clients to talk to the server’s Stomp port:
    • Open and edit c:\install\flash-policy-server\resources\default_policy.xml
    • Search for text "allow-access-from"
    • Under the allow access statement for port 8080, add a second line for the stomp port 61613:
    <allow-access-from domain="*" to-ports="8080" secure="false"/>
    <allow-access-from domain="*" to-ports="61613" secure="false"/>
    
  • Run the policy server with the command: c:\install\flash-policy-server\start-policy-server.bat. The policy server will listen on port 843.

Third, download and unzip the latest Adobe Flex SDK to a directory like c:\install\flex-sdk.

  • Add the Flex SDK bin directory to your path environmental variable:
    • Right-click on “My Computers” and select “Properties”. A dialog window will appear.
    • Click on “Advanced” tab and hit the “Environment Variables” button. A smaller dialog window will appear.
    • Double-click on the “Path” variable in either list boxes. An even smaller dialog window will appear.
    • Go to the “Variable value” edit field and append “;c:\install\flex-sdk\bin” to the end.
    • Hit OK, OK, OK.
  • Alternative, you can just run the following in the command prompt window before compiling with Flex: “set PATH=%PATH%;c:\install\flex-sdk\bin”

Fourth, download and unzip the STOMP chat client source to a directory like c:\projects\stompchat.

  • Launch the Window command prompt application by going to Start menu, select “Run…”, type in “cmd”, and hit the OK button.
  • Go to the stompchat directory: “cd \projects\stompchat”
  • Compile the STOMP chat client using the Flex SDK compiler:
    mxmlc.exe -source-path=.\ .\StompChat.mxml -output .\StompChat.swf
    
  • Drag and drop the generated StompChat.swf file into two browser windows (the latest Firefox or IE will work). Login with any name and start chatting back and forth.

Congratulations! Hopefully everything worked for you.

If it didn’t, here are some debugging steps:

  • Manually connect to the ActiveMQ STOMP service to make sure it is actually running by following this Stomp Tutorial.
  • If you have the Java SDK installed, you can use JConsole to look at the ActiveMQ queue statistics.
    • Run jconsole.exe from the Java SDK bin directory.
    • Select “Local Process” and “run.jar start”. Click on Connect.
    • Click on “BMeans” tab
    • Expand “org.apache.activemq”, “localhost”, “Topic”, and “CHAT.DEMO” which is the queue name used by the STOMP chat client (if you open StompChat.mxml, you will see it defined as the topic variable)
    • Expand “Attributes” and select “QueueSize”. The QueueSize count should keep increasing as chat messages are received by ActiveMQ server. You will have to hit the Refresh button to update the count.

FYI, Integrating Flex and RabbitMQ using STOMP is another Flex STOMP example that sends an image file instead of just text chat messages. Here are the Flex SDK compilation commands:

mxmlc.exe -source-path=.\src\ -library-path+=.\libs\Stomp.swc
   .\src\ImageSender.mxml -output .\bin\ImageSender.swf
mxmlc.exe -source-path=.\src\ -library-path+=.\libs\Stomp.swc
   .\src\ImageReceiver.mxml -output .\bin\ImageReceiver.swf

Javascript to JSON to PHP (and back)

Software Development No Comments

I was working on a little project that involved having a javascript client talk to a PHP backend using the JSON format. Of course, the first thing I did was to google for a simple example of this. Unfortunately, the info was scattered across several sites so it required some detective work to stitch together all the different data to get a working example.

To hopefully save you the time, I will provide a working example of how to get Javascript to talk to PHP using JSON. I will follow the time-honored tradition of providing a Hello World example. Even though it is very boring, it does demonstrate the bare essentials of the code.

Below is the Hello World PHP server script (let us call it “hello.php”). It parses a JSON-formatted post body and responds in kind.

<?php

// Retrieve the request body
// The request body is expected to look like:
// {
//   "firstName" : "John",
//   "lastName" : "Doe"
// }
$reqBodyJSON = @file_get_contents('php://input');
$reqObj = json_decode($reqBodyJSON);

// Retrieve the first and last name
$firstName = $reqObj->firstName;
$lastName = $reqObj->lastName;

// Construct our json response which will be an array
// of two possible replies
$response = array(
   "friend" => "Hi, ".$firstName."!  I'm glad to see you!",
   "foe" => "Goodbye, Mr. ".$lastName."!  Go away, please!"
);

// Output json response header and body
header('Content-type: application/json');
echo json_encode($response);

?>

Below is the Hello World HTML and Javascript client (let us call it “hello.html”). It will call the PHP server and display one of the two returned responses (selected randomly). The client uses a lightweight javascript framework called Prototype to facilitate the Ajax call to the server; we will need the “prototype.js” to be placed on the server for retrieval by the javascript client.

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Hello World!</title>

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">

function sayHello() {
  // Retrieve the values from the form
  var first = document.getElementById("firstName").value;
  var last = document.getElementById("lastName").value;

  // Construct request object
  var reqObj = {
    firstName : first,
    lastName : last
  };

  // Call the server
  new Ajax.Request('hello.php', {
    method : 'post',
    contentType : 'application/json',
    postBody : Object.toJSON(reqObj),
    requestHeaders : {Accept: 'application/json'},
    onSuccess : function (response) {
      // Get the response object
      var respObj = response.responseJSON;
      // Make our response random
      var isFoe = Math.floor(Math.random()*2+1); // 1 or 2
      var replyText;
      if (isFoe == 1) {
        replyText = respObj.foe;
      } else {
        replyText = respObj.friend;
      }
      document.getElementById("reply").value = replyText;
    },
    onFailure : function() {
      alert('Ajax call failed');
    }
  });
};

</script>
</head>

<body>
<h3>Hello World!</h3>

Please input your first and last name:
<form>
  First Name: <input id="firstName" type="textbox" value="George"><br>
  Last Name: <input id="lastName" type="textbox" value="Washington"><br>
  <input type="button" value="Say Hello" onclick="sayHello()">
  <br><br>
  Response: <input id="reply" type="textbox" readonly size="50"
             value="Press button for response!">
</form>
</body>
</html>

I hope that this example will help you in your explorations of web programming.

Secure Subversion on the XAMPP Apache Server

Software Development 2 Comments

To secure subversion, we just need to create a password file and configure apache to use it for subversion repository access.

  1. Open up the apache config file “C:/xampp/apache/conf/httpd”. At the end, look for the subversion repository URL location and add the additional text in bold:

    <Location /repos>
        DAV svn
        SVNPath c:/svn_repos
        
        AuthType Basic
        AuthName "Subversion Repository"
        AuthUserFile conf/svn-password.pass
        Require valid-user
    </Location>

  2. Create the svn-password.pass file by launching the “Start->All Programs->Accessories->command Prompt” and running these commands:

    c:/xampp/apache/bin/htpasswd.exe -cm c:/xampp/apache/conf/svn-password.pass username1
    c:/xampp/apache/bin/htpasswd.exe -m c:/xampp/apache/conf/svn-password.pass username2
    c:/xampp/apache/bin/htpasswd.exe -m c:/xampp/apache/conf/svn-password.pass username3

    You will be prompted to input the password for each user. I’m suggesting that the full path to htpasswd.exe be used because other programs (such as PUTTY) may have incompatible versions.

  3. Restart the Apache server.
  4. Browse to http://localhost/repos/ and you will be asked to input a username and password.

Additionally, we can create an authorization file to assign permissions to users or groups of users.

  1. Open up the apache config file “C:/xampp/apache/conf/httpd”. At the end, look for the subversion repository URL location and add the additional text in bold:

    <Location /repos>
        DAV svn
        SVNPath c:/svn_repos
        
        AuthType Basic
        AuthName "Subversion Repository"
        AuthUserFile conf/svn-password.pass
        AuthzSVNAccessFile conf/svn-authz.conf
        Require valid-user
    </Location>

  2. Create the c:/xampp/apache/conf/svn-authz.pass file. Here is some example content:

    [groups]
    devteam = username1,username2
    qateam = username3,username4,username5

    [/]
    @devteam = rw
    username6 = r

    [/project1]
    @devteam = rw
    @qateam = r
    username7 = rw

  3. Restart the Apache server.
  4. Browse to http://localhost/repos/ and you will be prompted to input a username and password.
  5. When using the subversion command line, you can use the –username flag to pass in your username the first time:
    svn –username username1 co http://localhost/repos/myproject

The info above was derived from How to Setup Subversion + Apache + WebSVN.

Using Eclipse to Debug PHP

Software Development 1 Comment

With EasyEclipse and the PHP Debugger extension, you can debug and step through a PHP call.

Installing the PHP Debugger (DBG) Extension

  1. Download the PHP Debugger (DBG); specifically the DBG 2.15.5 dbg modules for windows.
  2. Unzip the dbg modules to a temporary directory.
  3. Copy the relevant php extension file, currently “x86\php_dbg.dll-5.2.x” in the archive (since XAMPP 1.6 comes with PHP 5.2.5), to the extension directory “c:\xampp\php\ext” and rename it to “php_dbg.dll”.
  4. Open up the “c:\xampp\apache\bin\php.ini” config file.
    • Add this to the end of php.ini:
      [debugger]
      extension=php_dbg.dll
      debugger.enabled=on
      debugger.profiler_enabled=on
      debugger.hosts_allow=localhost
      debugger.hosts_deny=ALL
      debugger.ports=7869, 10000/16
      
    • Search for the first instance of “zend_extension_ts” in php.ini (it should be right underneath the “[Zend]” section) and before it, add this line:
      [Zend]
      zend_extension_ts = "c:\xampp\php\ext\php_dbg.dll"
      ...
      
  5. Verify that the DBG Extension is loaded:
    • Stop and start the apache http server (a reload or restart won’t work).
    • Create a phpinfo.php file with this content:
      <html>
      <head>
      <title>PHP Test Script</title>
      </head>
      <body>
      <?php
      phpinfo();
      ?>
      </body>
      </html>
      
    • Install phpinfo.php under the apache root document directory and then browse to it. You will see the info on the PHP environment. If DBG is installed correctly, you should see this line:
      Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
          with DBG v2.15.5, (C) 2000,2007, by Dmitri Dmitrienko
      
    • Search on “dbg” and you will see the configuration section for dbg also.

Disabling PHP Debugging

  • Once you have installed the DBG extension, debugging will be enabled and for any PHP file that is browsed to, the PHP engine will attempt to debug and fail because we have not setup a PHP Debugger service yet.
  • To disable debugging permanently:
    1. Open up the “c:\xampp\apache\bin\php.ini” config file.
    2. Change the “debugger.enabled=on” to “debugger.enabled=off”.
    3. Restart the Apache HTTP server.
  • To disable debugging for the current active HTTP session:
    1. Browse to “http://localhost/myproject/index.php?DBGSESSID=-1″.
    2. This URL will remove the cookie added by the DBG extension to enable PHP debugging.

Starting the PHP Debugger Service

In order for PHP debugging to work, we must configure and start a PHP Debugger service using EasyEclipse:

  1. Run EasyEclipse and go to menu “Run->Debug…”. If you don’t see the Run->Debug menu, then open up the Debug perspective, switch back to PHP perspective, and try again.
  2. Select and highlight the “PHP DBG Script” and click on the New icon on the upper-left.
  3. Input whatever Name you want.
  4. Under the File tab, input “index.php” (or your main entrypoint PHP file). (Alternatively, you can Browse… and select it.)
  5. Under the Arguments tab, you should see “Use default working directory” checked and the “Working Directory” is “C:\Projects”.
  6. Under Environment tab:
    • Under the Interpreter sub-tab, click the New button and browse to “c:\xampp\php\php.exe”
    • Under the “Remote Debug” sub-tab, check “Remote Debug” and uncheck “Open with DBGSession URL in internal Browser”. Make sure that the Remote Sourcepath is “C:\Projects\myproject”.
    • Note: It is very important that the Remote Sourcepath (and all other paths) is set correctly; otherwise the PHP debug won’t work.
  7. Hit the Apply button.
  8. Start the PHP Debugger service by clicking on the Debug button below the Apply button. Take note of the port number (should be 10001) that the PHP Debugger service is listening on.

Debug Tracing PHP

  1. Open up “index.php” and set a breakpoint inside it (I suggest setting a breakpoint in the main entry routine).
    • You can set a breakpoint by clicking on the leftmost vertical blue bar in the file viewer. You should see a blue dot show up and an entry added to the Debug perspective’s Breakpoints window.
    • Alternatively, you can right-click on the leftmost vertical blue bar and select “Toggle PHP Breakpoint”.
  2. Browse to “http://localhost/myproject/index.php?DBGSESSID=1@localhost:10001″ and the breakpoint should be hit. You can then step into, over, or out. Yippee!
    • Note: The 10001 in “localhost:10001″ should match the port that the PHP Debugger is listening on in the EasyEclipse debug window.
    • Passing in the request parameter DBGSESSID will create a cookie (session based), so you no longer have to pass in the DBGSESSID http parameter in subsequent requests. Yipee again!
  3. Disable debug tracing for the current session by browsing to “http://localhost/myproject/index.php?DBGSESSID=-1″. Adding the parameter “DBGSESSID” with value “-1″ will delete the debugging cookie.
  4. CAVEAT: Unfortunately, there is a bug with the PHP Debugger service in that after servicing the HTTP request, the PHP Debugger service will terminate.
    • You can quickly start the PHP Debugger service again by hitting F11 shortcut key. You will want to do this after each HTTP request is debugged.

Note: Some info above was derived from XOOPS Docman – Installing DBG.

Using Eclipse to Develop in PHP

Software Development No Comments

The EasyEclipse distribution is a quick and easy packaging of Eclipse with plugins for different purposes. I recommend using EasyEclipse for PHP which comes with PHP edit mode and useful plugins like SubEclipse for subversion source control integration.

  1. Download and install the latest version of EasyEclipse for PHP.
    • When you launch EasyEclipse, it will prompt you for the workspace directory. Input “c:\projects”. If EasyEclipse doesn’t prompt you for a workspace and instead uses a workspace from an old project, you can manually change the workspace by going to menu “File->Switch workspace”.
    • Note: It is not recommended for you to move or rename your workspace directory once created. The workspace properties have a reference to the original workspace directory.
  2. At this time, checkout the myproject codeline to c:\projects.
    • Go to the EasyEclipse menu “File->New->Project->SVN->Checkout Projects from SVN”.
    • Enter the Repository URL: http://localhost/repos/
    • Then select directory: /myproject
    • Change the project name to: myproject
  3. Edit PHPEclipse options to run XAMPP server:
    • Go to the php external tools settings “Windows->Preferences->PHPeclipse Web Development”. (The following steps will be referenced off of this location.)
    • Set the xampp start and stop buttons under “PHP External Tools->XAMPP”.
    • Set the DocumentRoot path under “Project Defaults” to: C:/projects
    • Add the following to the “Include Paths” under “Project Defaults” to: C:/projects/myproject
    • (Optional) Turn off php file browser preview. Under “Browser Preview Defaults”, uncheck “Refresh PHP browser view…” and “Show PHP browser view…” selections.
  4. (Optional) Configure the tab width to be 3:
    • Go to “Windows->Preferences->PHPeclipse Web Development->PHP”
    • Set “Displayed tab width” to 3.
  5. (Future) Synchronize your source to the latest SVN repository:
    • In the left-hand Navigator, right-click on “myproject”.
    • Select right-click menu “Team->Update”.
  6. Hint: If you are not in PHP edit mode, you can always go to it by going to menu “Windows->Open Perspective->PHP”

Note: If the subversion commands you issue using SubEclipse return errors, you may have an incompatible SVN install directory in the “path” environmental variable. To resolve this, you can remove the SVN install directory from the “path” environmental variable or you can re-install a compatible SVN version. For example, SVN 1.4.6 is compatible with SubEclipse 1.2.1 which comes with EasyEclipse 1.2.2.

Add Subversion to the XAMPP Apache Server

Software Development 10 Comments

Subversion is a simple and popular source control system. It has the option of running as part of the Apache server. We’ll examine how to quickly get subversion up and running with the Apache server which comes with XAMPP.

  1. Download the latest subversion windows archive. Look for a file named “svn-win32-1.4.6.zip” (or with a later version number) at the bottom of the list.
  2. Unzip it to a local directory “c:/bin” and you will end up with “c:/bin/svn-win32-1.4.6″.
    • Add “c:/bin/svn-win32-1.4.6/bin” to the end of the Windows “path” environmental variable. This will allow us to run the command line subversion client and repository administration tool.
    • Warning: If you use Eclipse and the SubEclipse plugin, putting subversion in the “path” environmental variable may break the SubEclipse plugin. If this happens, just remove subversion from the “path” environmental variable and use Eclipse to perform subversion functions exclusively. Or ensure that your installed SVN version is compatible with SubEclipse; for example, SVN 1.4.6 is compatible with SubEclipse 1.2.1.
    • Also set “SVN_EDITOR=notepad.exe” to identify the default text editor to be used by the subversion command line tools.
  3. Create an initial blank repository called “svn_repos” by launching the command prompt window and running “svnadmin create c:/svn_repos“.
  4. Configure apache to use the subversion module
    • Stop the Apache server
    • Copy the apache module “c:/bin/svn-win32-1.4.6/mod_dav_svn.so” into the apache modules directory “C:\xampp\apache\modules”. Go ahead and overwrite the existing “mod_dav_svn.so” file as it is from an older version of subversion.
    • Open up the apache config file “C:/xampp/apache/conf/httpd”
    • Enable the subversion module by adding “LoadModule dav_svn_module modules/mod_dav_svn.so” anywhere after the existing “LoadModule dav_module modules/mod_dav.so” line. The best thing would be to add it as the last LoadModule line.
    • At the end, add a URL location (what you would enter into the browser or your subversion client) for your repository:

      <Location /repos>
          DAV svn
          SVNPath c:/svn_repos
      </Location>

    • Start the Apache server
    • You can access the repository using the URL “http://localhost/repos”. You should see a “Revision 0″ header with no other data. If you get an error, check the “C:/xampp/apache/logs/error.log” file for details on the problem.
    • Note that you will need to add a location block like the above for each repository that you create with “svnadmin create”. (You shouldn’t need to do this because a repository can contain as many projects as you want.)
    • Note: we have not secured the repository so anyone can read or write to it. To secure subversion, see this post.
  5. Import an existing project (source code directory) into the “svn_repos” repository
    • If you have source code in a project directory like “c:/oldprojects/myoldproject”, you can import the contents of “myoldproject” into the subversion “svn_repos” repository by running this command: “svn import c:/oldprojects/myoldproject http://localhost/repos/myproject -m "Initial import"“.
    • The comment “-m "Initial import"” is optional. If you don’t input it, the default subversion editor (“notepad.exe”) will appear. Add your import comment and save the file. If you close the file without making any changes, you will need to input “c” into the command prompt window to continue the import.
    • Browse to “http://localhost/repos/myproject” and you should see “Revision 1″ header with the list of folders and files that have been imported.
  6. You can create a new empty project by creating an empty folder and importing it (see above).
  7. Checkout the initial “myproject” project to create a local working copy
    • Open the command line and go to the “c:/projects” directory.
    • Check out “myproject” by issuing the following command “svn co http://localhost/repos/myproject myproject“.
    • You will see a “c:/projects/myproject” directory with your imported folders or files (if you did the import step above). If you didn’t import, you will see an empty directory except for a “.svn” subdirectory; don’t touch the “.svn” subdirectory as it is used by the subversion client for bookkeeping.
  8. Inside your local working copy “c:/projects/myproject”, you can issue the following common subversion commands:
    • To update your local working copy with the latest revision from the repository: “svn up http://localhost/repos/myproject”
    • To add a new file: “svn add newfile.cpp
    • To remove a file: “svn rm oldfile.cpp
    • To move and/or rename a file: “svn mv oldfile.cpp subdir/newoldfile.cpp
    • List the changes (aka status) that you have made to your working copy: “svn st
    • To commit (aka checkin) the local working changes to the repository: “svn ci -m "my checkin comments"“. If you don’t input the comment using the “-m” flag, the default editor (“notepad.exe”) will open to allow you to input the comment.
  9. To ignore certain subdirectories or files that you do not wish to check into subversion
    • Go to the directory containing the subdirectories or files to be ignored and run this command: “svn propedit svn:ignore .
    • The default editor (“notepad.exe”) will open. Input the subdirectory and file names, one per line.
    • Instead of putting the exact filename, you can use a file pattern like “*.obj”.
    • Save and close the file.
    • To make this change permanent, issue a “svn ci” command.
    • You can also create a text file “ignore.txt” containing the subdirectory, filenames, and file patterns that you wish subversion to ignore, and apply it recursively to the current and all subfolders by running “svn propset -R svn:ignore . -F ignore.txt

To secure subversion, see my next post.

Some info above derive from Ned Batchelder: Subversion on Windows quick start.

Setting Up an Apache, MySQL, PHP Development Environment with XAMPP

Software Development 2 Comments

Rather than installing Apache, MySQL, and PHP individually, XAMPP is an integrated development enironment that combines all three (and more) into one easy installation.

  • Download XAMPP and install it into the default “c:\xampp” directory. Set apache and mysql to start as services.
  • Start XAMPP and browse to “http://localhost/” and you will see a welcome message.
  • If you don’t want to use the default “c:\xampp\htdocs” directory as your document root, you can update the DocumentRoot "C:/xampp/htdocs" property and <Directory "C:/xampp/htdocs"> element in the “c:/xampp/apache/conf/http.conf” file. For example:

    DocumentRoot “c:/projects”
    <Directory />… don’t change this / default root block…</Directory>
    <Directory "c:/projects">

  • Likewise, if you use SSL, update DocumentRoot "C:/xampp/htdocs"
    in “c:/xampp/apache/conf/extra/http-ssl.conf”.
  • Note: XAMPP uses the “c:/xampp/apache/bin/php.ini” when running PHP. There is a second “c:/xampp/php/php.ini” which is used if you call “c:/xampp/apache/bin/php.exe” from the command line.
  • Edit “c:/xampp/apache/bin/php.ini” to enable logging by setting the following properties:

    error_reporting = E_ALL
    log_errors = On
    error_log = “C:/xampp/apache/logs/phperror.log”

  • To enable access to the original XAMPP htdocs directory, we can create a subpath redirect to it using the alias function.
    1. Edit “c:/xampp/apache/conf/httpd.conf” and locate the <Directory "C:/projects"> block (or whatever path you had selected as document root).
    2. Immediately after the whole <Directory> block above (look for the matching end tag </Directory>), add the following text:

      # Allow access to the original xampp htdocs
      Alias /htdocs C:/xampp/htdocs
      <Directory "C:/xampp/htdocs">
          Options Indexes FollowSymLinks Includes ExecCGI
          AllowOverride All
          Order allow,deny
          Allow from all
      </Directory>

    3. Adjust the htdocs files to account for the base URL change:
      • Edit “c:/xampp/htdocs/index.php”, locate header(‘Location: ‘.$uri.’/xampp/’);, and change that to be header(‘Location: ‘.$uri.’/htdocs/xampp/’);.
      • Repeat the above for “c:/xampp/htdocs/xammp\index.php” and “c:/xampp/htdocs/xampp/lang.php”.
      • Edit “c:/xampp/htdocs/xampp/splash.php”, locate
        <a href=”/xampp/lang.php?’.$key.’”>
        , and change that to be <a href=”/htdocs/xampp/lang.php?’.$key.’”>.
    4. Start XAMPP, open your browser to “http://localhost/htdocs” and you will see the original xampp htdocs directory.
  • If you attempt to access Apache from another machine in your network and your brower returns an access error, you may need to adjust your Windows Firewall. The latest version of Windows Firewall forces you to manually open up ports for services.
    1. Go to Start, Control Panel, Windows Firewall and click on the Advanced tab.
    2. Make sure that “Local Area Connection” is checked and hit the Settings button to the right of it.
    3. Under Services tab, make sure that “Web Server (HTTP)” is checked.

Setting Up a MySQL, Apache, and PHP Development Environment

Software Development No Comments

Installing Apache and PHP

  1. Install Apache HTTP Server
    • If you don’t install it as a windows service, you can control it using the command line:
      • Start Apache: Run httpd.exe to start the server
      • Stop Apache: Hit CTRL-C in the httpd.exe console window to stop it
  2. Install PHP
    • add php install path to Windows path environment variable
    • copy php.ini-recommended to php.ini
    • edit php.ini to set the doc_root parameter and enable mysql support
      • doc_root = “c:\apache\htdocs”
      • extension=php_mysql.dll
      • extension_dir = “c:\php\ext”
  3. Config Apache to call PHP as a SAPI module
    • edit “c:\apache\conf\httpd.conf” to include the following:
      • Add index.php as a recognized directory index file
        • DirectoryIndex index.html index.php
      • Load PHP 5 as SAPI module
        • LoadModule php5_module “c:/php/php5apache2_2.dll”
      • Add mime type for PHP files
        • AddType application/x-httpd-php .php
      • Configure the path to php.ini (you can insert this at the end of the file)
        • PHPIniDir “c:/php”

Installing mySQL

  1. Install mySQL
    • If you don’t install mysql server as a Windows service, you can use the command line:
      • Start mysql: mysqld –standalone –console
      • Stop mysql: mysqladmin -uroot -p shutdown
  2. Install phpMyAdmin into Apache htdocs directory
    • copy config.sample.inc.php to config.inc.php
    • In config.inc.php, set the value for the ‘blowfish_secret’ to anything
    • When logging into phpMyAdmin using the browser, input the mysql “root” user and default blank password.

Installing IlohaMail

  1. Download IlohaMail and unzip it
  2. Copy the “IlohaMail” subdirectory in the archive into Apache htdocs directory
    • Use phpMyAdmin to create a database and import the “MySQL/sql” file to create tables
    • edit conf.php to change to a mySQL based storage
      • $backend = “DB”;
    • edit db_conf.php to set the database access
      • $DB_HOST=”hostname”;
      • $DB_USER=”username”;
      • $DB_PASSWORD=”user password”;
      • $DB_NAME=”database name”;