Debugging PHP on IIS 7.5 on Windows 7 or Windows Server using XDebug and NetBeans

I had been working on a Drupal page on Linux. We need to run it on IIS, so I had to debug errors caused by moving it.

1) I downloaded Netbeans. If you don’t have JDK, you can download the bundle

http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html

2) Download XDebug for your PHP instalation.

Type in elevated command window

> cd C:\Program Files (x86)\PHP\v5.3

> php -i > out.txt

and copy content of out.txt here.

http://www.xdebug.org/find-binary.php

This page gives you tailored instructions for your situation.

For my installation, it was this:

Tailored Installation Instructions

Summary

  • Xdebug installed: no
  • Server API: Command Line Interface
  • Windows: yes – Compiler: MS VC9 – Architecture: x86
  • Zend Server: no
  • PHP Version: 5.3.10
  • Zend API nr: 220090626
  • PHP API nr: 20090626
  • Debug Build: no
  • Thread Safe Build: no
  • Configuration File Path: C:\Windows
  • Configuration File: C:\Program Files (x86)\PHP\v5.3\php.ini
  • Extensions directory: C:\Program Files (x86)\PHP\v5.3\ext
  • Instructions

    1. Download php_xdebug-2.2.0-5.3-vc9-nts.dll
    2. Move the downloaded file to "C:\Program Files (x86)\PHP\v5.3\ext"
    3. Edit C:\Program Files (x86)\PHP\v5.3\php.ini and add the line
      zend_extension = "C:\Program Files (x86)\PHP\v5.3\ext\php_xdebug-2.2.0-5.3-vc9-nts.dll"

    NetBeans prompted me to 4 more lines to php.ini, so I created a section like this

    [zend]
    zend_extension = "C:\Program Files (x86)\PHP\v5.3\php_xdebug-2.2.0-5.3-vc9-nts.dll"
    xdebug.remote_enable=On
    xdebug.remote_host="localhost"
    xdebug.remote_port=9000
    xdebug.remote_handler="dbgp"

    Then I was able to debug my project that I had imported as a new project into NetBeans from existing codes.

    Following website might give additional details: http://www.domainwebcenter.com/?p=936

    Manual Installation of Drupal on IIS 7.5 and MS SQL Server

    1) There is an automated installer from Microsoft: http://www.microsoft.com/web/drupal/

    However, you may want to have some more control, like me, and install Drupal yourself.  I tried the one from http://drupal.org/download too. It will be almost same as described below, but it won’t have MS SQL Server support out of the box (it won’t be listed in the image in step 8 below). So I used the Acquia distribution.

    Go to this link https://network.acquia.com/downloads and download “Acquia Drupal full install (.zip)”

    or you may want to get it from a version control repository
    https://docs.acquia.com/acquia-drupal/install/repository

    2) Unzip this folder C:\inetpub\wwwroot\ and rename as you wish (or move contents of svn folder except the .svn into C:\inetpub\wwwroot\<FolderName>) I have mine here: C:\inetpub\wwwroot\acquiaSVN

    Rename C:\inetpub\wwwroot\acquiaSVN\web.config to C:\inetpub\wwwroot\acquiaSVN\web.config.old, so it will not be used.

    3) run inetmgr (type “inetmgr” in windows start menu)

    4) if you don’t see that folder listed among your webpages, right click to Default Web Site and refresh…

    image

    then click on that folder (acquiaSVN) and click Browse.

    5) You will receive the following error messages

    image

    File system
    The directory sites/default/files does not exist. An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the online handbook.

     
    Settings file The settings file does not exist.
    The Drupal installer requires that you create a settings file as part of the installation process. Copy the ./sites/default/default.settings.php file to ./sites/default/settings.php. More details about installing Drupal are available in INSTALL.txt.

    6) Create that folder C:\inetpub\wwwroot\acquiaSVN\sites\default\files and copy the C:\inetpub\wwwroot\acquiaSVN\sites\default\sites\default\default.settings.php file to C:\inetpub\wwwroot\acquiaSVN\sites\default\sites\default\settings.php.

    Switch to content view in inetmgr software as seen below.

    image

    7) Then edit the permissions for this file and folder

    image

    Give full control to all users click OK and OK.

    image

    8) Now, when you go back to your drupal site and click the “proceed with installation” link at bottom or go to  http://localhost/acquiaSVN/install.php

    You should see no errors :

    image

    You need to click on advanced options if you are using a backend database already installed on another machine:

    image

    Table prefix is for cases where you would use the same database for multiple drupal installations. You probably wouldn’t do that, you would create one database for each one in your server. This might be put there for people whose host allows them a limited number of databases.

    After this step, one final screen will let you set up and admin account and time zone. Then your website will be ready.

    image

    Voice & Video Streaming, Whiteboard and Desktop Sharing Available in Openfire

    Installing Red5 plugin to my Openfire server and enabling it was a breeze using the Openfire  web control console.

    Now, I am reading about Real Time Messaging Protocol, and ActiveX controls to embed Flash Media into .Net forms (axShockwaveFlash COM component that you can add to toolbox in Visual Studio).

    The Jingle implementation that exists in Spark supports voice chat without Flash. At least I can port that to my C# forms client implementation. However there seems to be a long delay. It may be due to my underpowered test server and hopefully improved when I start using our real server. If the delay is due to bandwidth, using better codecs to compress might solve the problem.

    I have found out that ffmpeg supports flv and swf, and there are ways to use ffmpeg inside .net: calling ffmpeg.exe, using ActiveX control, external ActionScript API for C# (tutorial uses an instant messaging application, so should be useful)
    http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cb0.html, http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b8fc4e-8000.html [Code and Samples]

    Resources:
    Compiling Spark for Dummies:
    http://www.igniterealtime.org/community/docs/DOC-1521

    Spark client secure audio/video with Red5 plugin:
    http://www.igniterealtime.org/community/docs/DOC-1633

    Red5 Plugin Readme:
    http://www.igniterealtime.org/community/docs/DOC-1518

    Red5 Linux Setup:
    http://www.igniterealtime.org/community/docs/DOC-1520

    Simple C# and Flash interop:
    http://bojordan.com/log/?p=269

    Note:

    Need to check DirectShow [or this? which is latest documentation] and OSMF [tutorial] as well.

    F-IN-BOX is a developer’s library (for $300) to enhance Macromedia Flash Player ActiveX features. It does not use its own engine to display movies but provide a wrapper around official swflash.ocx/flash.ocx code instead. Thus it is possible to avoid certain Macromedia Flash Player ActiveX limitations.

    Media Streaming Struggles

    Finally, I have our chat server (openfire by JiveSoftware) running, my client connecting to it successfully (using jabber-net C# implementation of an XMPP API). Now I need to figure out how to stream video and audio.

    XMPP has Jingle extension for negotiating streaming parameters (format, ports etc.). However, I haven’t found a .Net implementation. I have used JiveSoftware’s Spark client to connect to my server and had a successful voice chat which means Spark has implementation of Jingle. However Spark is implemented in Java, while I had implemented my client in C#. Now the question is to port my client to Java or to extract and port their Jingle library to C#…

    Another good news is Openfire supports Flash Video and Audio streaming via a plugin implementing Adobe Flash Media Server (through reverse engineering) called red5. This might come handy when I want to support video as well.

    Jingle only negotiates the stream parameters. I have to work on what I can use for compressing and decompressing media. Jingle doesn’t handle such things. Microsoft has a DirectShow API to perform various operations with media files or streams. (Media Foundation is replacing it, but Wikipedia says it won’t support Windows XP, which is still has around %60 of the OS market share.)

    So currently I am researching about DirectShow and Flash based Media streaming APIs to incorporate into my client.

    How to Get the Name of an Object’s Type (Class) in C#

    string name = instanceVariable.GetType().Name;

    “Indexed Properties” of a Class in C#

    In Jabber-net library, which I am using for my client, I saw this piece of code, which basically stores an array of type-unsafe properties. It is a useful idiom to have in mind for C# developers.

    /// <summary>

    /// Sets or retrieves a connection property.

    /// You have to know the type of the property based on the name.

    /// For example, PORT is an integer.

    /// </summary>

    /// <param name=”prop”>The property to get or set.</param>

    /// <returns></returns>

    public object this[string prop]

    {

    get

    {

    if (!m_properties.Contains(prop))

    return null;

    return m_properties[prop];

    }

    set

    {

    m_properties[prop] = value;

    if (PropertyChanged != null)

    {

    PropertyChanged(this, new PropertyChangedEventArgs(prop));

    }

    }

    }

    _________________________________

    Used in this way (if stream is of this class):

    stream[(string)parent.Tag] = GetControlValue(parent);

    References:

    While reading more about this, I learned it is called “Indexed Properties”.

    http://msdn.microsoft.com/en-us/library/aa288464(VS.71).aspx

    For preliminary on Indexers (like operator [] in C++):

    http://msdn.microsoft.com/en-us/library/aa288465(VS.71).aspx

    XML Configuration File for .Net Projects

    ConfigurationManager class is used to load settings from an XML file at the start of an application. Usually people edit it outside the application (manually with a text editor), however, it is possible to change configuration inside the program:

    http://blog.sb2.fr/post/2008/11/29/HowTo-Modify-Configuration-File-Programmatically-with-C.aspx

    The Jabber-Net library uses this function to update its configuration file instead:

    /// <summary>

    /// Write the current connection properties to an XML config file.

    /// TODO: Replace this with a better ConfigFile implementation that can write.

    /// </summary>

    /// <param name=”file”></param>

    public void WriteToFile(string file)

    {

    XmlDocument doc = new XmlDocument();

    string name = “JabberClient”;

    if (m_xmpp != null)

    name = m_xmpp.GetType().Name;

    XmlElement root = (XmlElement)doc.CreateElement(name);

    doc.AppendChild(root);

    WriteElem(root, this);

    foreach (DictionaryEntry ent in m_extra)

    {

    root.AppendChild(doc.CreateElement((string)ent.Key)).InnerText = ent.Value.ToString();

    }

    XmlTextWriter xw = new XmlTextWriter(file, System.Text.Encoding.UTF8);

    xw.Formatting = Formatting.Indented;

    doc.WriteContentTo(xw);

    xw.Close();

    }

    More:

    More advanced configuration library: http://www.codeproject.com/KB/cs/SysConfiguration.aspx

    The Promise of Open Source for our Project

    The XMPP protocol has many implementations in many projects, sometimes together with other protocols. Which implementation is the best to build up on.  Among c open source implementations listed, jabberd14 and jabberd2, latter seems to be more recent, more widely adopted, and hence have better community support,  so I played with jabberd2 for a while. Then I also looked at Java implementations. Openfire seems to be more complete than Tigase. It also has a company behind it, rather than a single developer. So currently I am using Openfire.

    On the client side development I plan to continue implementing from scratch. Because client program is to be distributed to users and except LGPL opensource, using an open source code would require me to open my source as I had mentioned here. Still, when I am stuck about solving an issue, I can check how they had solved it in one of the open source clients. A well established XMPP client project is: Empathy but it is targeting Linux where as we target customers on Windows initially . LGPL is more common among softare libraries, and there are a few XMPP libraries with LGPL, I initially considered the only C++ one, QXMPP, but now I am using jabber-net and ported my C++/CLI client code to C# as well since utilizing examples for this C# library was easier when I coded in C# as well.

    libjingle is a library implementing a useful extention of XMPP protocol, named jingle. Jingle is for initiating and managing peer-to-peer media sessions between two XMPP entities to be used for a wide variety of application types (e.g., voice chat, video chat, file transfer). Luckily, libjingle is made available under a Berkeley-style license, which means you are free to incorporate it into commercial software. Using libjingle, I won’t waste time on the obstacles I would face, like reverse NAT traversal problem I had faced with my own client. As an example, (as described here) libjingle already implements STUN to solve this problem.

    Resources:

    Comparison of XMPP and other IM Protocols

    jabberd2 home page.

    Developer documentation for jabberd2.

    jabberd2 install guide.

    jabberd2 architecture doc. Especially required database tables given at the end.

    precompiled windows binaries and suse rpms.

    All server implementations list from official website.

    Brief info about some Open Source Licences

    I was initially thinking I would have to make my program open source if I was using GPL source. GPL requires you to make your source code available only if you are distributing your program. This is a loop-hole benefitting people developing server software for their own use. This loophole is later filled by AGPL, but most software still uses GPL, including XMPP servers I am inquiring about. So I can develop our server on top of open source projects. I would gladly send them patches when I make improvements to their code. I only like not being forced to open all of my source since this might cause security flaws in my code to be detected by hackers.

    There is also LGPL, which allows proprietary code to be built upon open code even if you are distributing your program to users. This licence is much less commonly used.

    Standard Protocols, Libraries and APIs for Instant Messaging

    I will be reading RFCs from IETF standardization committee to learn about the XMPP protocol. However there are preceding protocols to read about. For a few days you will be seeing short summaries from those protocols I will read. Later you may see some info about open source implementations of XMPP.