Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, December 30, 2007

Installing PHP 5.2.5 on Windows XP for Tomcat 6.0.13 - Issues resolved

I was playing around with the idea of doing a small personal PHP project, and I decided to do a fresh install of the latest version of PHP, which is 5.2.5. Since I'm already using the Apache Tomcat 6.0.13 server, I decided to run PHP on that instead of setting up the Apache HTTP server. I've done something similar before, so I didn't think it would be much of a problem. However, it is a bit more tricky than expected.

Windows PHP installer is broken

Initially, I used the Windows installer. The PHP install directory used was "C:\Program Files\PHP". Installing was a breeze and I could even use the php5srvlt.jar and put it into the WEBINF\lib directory without doing anything. The reflect.properties and servlet.properties files already have the line

library=php5servlet

instead of

library=phpsrvlt

So I followed the steps outlined. When I tried to access the test page, I got this.
HTTP Status 500 -
type Exception report

message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: Servlet.init() for servlet php threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
.....(edited for brevity)

root cause
java.lang.UnsatisfiedLinkError: C:\Program Files\PHP\php5servlet.dll: Can't find dependent libraries
java.lang.ClassLoader$NativeLibrary.load(Native Method)
.....(edited for brevity)

I checked the install directory and php5servlet.dll was there. What are the dependent libraries? After reading some of comments on Angusman's site and some discussions on Java forums, it turns out that the problem is due to missing DLLs. I downloaded a tool called Dependency Walker. It is very useful, I loaded php5servlet.dll and got the following.

Dependency Walker says php5ts.dll is missing

So php5ts.dll is missing. Searched for the file on PECL4WIN but could not find it. So I downloaded the zipped PHP files, then I noticed that there is an error in the original installer for PHP 5.2.5. Apparently the updated installer still has issue.

Steps I took to get it working

  1. Uninstall the initial install and remove all the files in the install directory

  2. Unzip the downloaded PHP zipped file into the install directory.

  3. Download php5servlet.dll from PECL4WIN and put it in the install directory. If you don't have it you will get an error message like:
    exception
    javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    .....(edited for brevity)

    root cause
    java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path
    java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
    .....(edited for brevity)


  4. Edit the following paths in the php.ini file: include_path = "C:\Program Files\PHP\PEAR", doc_root = "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.13\webapps", extension_dir = "C:\Program Files\PHP\ext"

  5. Uncomment a few extensions in php.ini and ensure the DLLs are in the extension directory, eg curl or bz2

  6. Save the php.ini file.

  7. If you right-click and php.exe, php-cgi.exe and php-win.exe and see the properties, you will see this message "Security: This file came from another computer and might be blocked to help protect this computer." I chose to unblock, but I'm not sure if there's any issue leaving it on.
    Security message

  8. Create web.xml, php5srvlt.jar and test page like what Angusman says in the appropriate directory in the webserver. If php5srvlt.jar is not in the correct directory you'll get an error message like this:
    exception
    javax.servlet.ServletException: Wrapper cannot find servlet class net.php.servlet or a class it depends on
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    .....(edited for brevity)

    root cause
    java.lang.ClassNotFoundException: net.php.servlet
    .....(edited for brevity)

    I already have them so I skipped this.

  9. Create the following environment variables PHP_HOME="C:\Program Files\PHP", PHP_HOME_EXT="%PHP_HOME%\ext", PHPRC="%PHP_HOME%". PHPRC is used to determine the location of the php.ini file but it is not the only place where it can be set. The locations being searched for the php.ini file follows a certain order. For my purpose this setting PHPRC is sufficient. If this is not set, the default location will be used, and may result in php.ini not being loaded, which in turn results in the configuration settings being set to some unexpected values, modules not being loaded as seen in phpinfo(), etc. Some examples.

    Wrong include path
    Wrong include path
    Wrong extension directory
    Wrong extension directory

  10. Append the environment variables to the PATH environment variable.

  11. Reboot so that the PATH changes are set. If not, you'll get some error like this where the environment variable appears correctly on it's own but not in the PATH.
    Computer needs to be rebooted for PATH changes to be effected

Sunday, December 17, 2006

phpBB forum - using the default DB object

Have been doing a little freelance lately, mainly involving integrating new functionality with phpBB.
Using the existing code speeds up development and minimizes redundant code. Below is the code needed to use the default database object in phpBB.

[php]
define('IN_PHPBB', true);
$phpbb_root_path = './../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$sql = "SELECT * FROM " . A_TABLE . "
WHERE rank_special = 1
ORDER BY a_title";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR,
'Could not obtain ranks data', '', __LINE__, __FILE__, $sql);

}
else echo "Query successsful";

Tuesday, November 21, 2006

phpBB mod uninstallation - tedious

I was experimenting with phpBB (a PHP-based forum board) recently and was doing some mod installation via easyMOD. It was a breeze, though you have to watch out for occasional errors. Manually installing a large number of mods, backing up can be a real pain. You also have to careful and not screw up. Here's what they have to say about installing mods safely.
Installing a mod, whatever size it is and whatever your skills in HTML/PHP/phpBB are is always a very risky operation. Doing it live, even if the mod has no bugs and even if you use easyMOD to be sure to make no errors while applying a mod sounds so like a little crazy.

If you're going to manually uninstall mods, you might go a little crazy. Uninstalling via easyMOD is somewhat easier, but you have to take note of the order that the mods were installed, as the changes are applied in a stack-based fashion, first-in-last-out.
What this means is that you have to carefully consider what you are going to install and in what order to install them. If you have installed 10 mods and want to uninstall the 3rd mod (based on time of installation), then you have to do 7 un-installations and 6 installations. Yeah, that's tiring. I'm guessing this can be automated though.

Wednesday, October 25, 2006

Running php 5.x on windows using tomcat 4.x or 5.x

A very useful guide here.

http://blog.taragana.com/index.php/archive/running-php-5x-on-windows-using-tomcat-4x-or-5x/

Notice that there are about 200 comments with a lot of them asking for help. The guide's actually quite easy to follow once you get it to work the first time. Then you'll be wondering why you needed 2-3hrs to get it right, like me.

Sunday, August 27, 2006

Syntax Highlighting with GeSHi and csh_geshi plugin

Pasting code in Wordpress is not an easy task, Wordpress will tend to mess it up by applying filters to it. The GeSHi (Generic Syntax Highlighter) project not only prevents that, but also provides syntax highlight as well. To use it, you will need a Wordpress plugin. The WordPress csh GeSHi Plugin does that job well, the syntax is easy and is easily configurable. You will have to disable Wordpress's rich text editor though, at least when you need to paste code samples.

Some examples of the combination in action.

Simple:
[js]
function square(num)
{
return num*num;
}


With line numbering:
[java,Y]
public class Student
{
private String name;
private String matricNo;


public Student(String name, String matricNo)
{
this.name=name;
this.matricNo=matricNo;
}
}
Start line numbering from 10
[sql,Y,10]
select * from product where price>100 and type='ELECTRONICS';
select * from staff where name like '%JOHN%';
select * from store where manager='HENRY LEE';