Saturday, October 24, 2009

How To Install PHP on Apache on Windows XP

Before proceeding, here's what you'll need.

1.) PHP Installer, use the Non-thread Safe Version
2.) Apache Tomcat Installer
3.) Java Bridge Template to enable PHP on Apache
4.) Java JRE

If you haven't installed Java on your system yet, do it now. Apache needs Java Runtime Environment to run since all of its components are java-based.

Install Apache first to default location

Install PHP. Choose "Other CGI" when presented with choices. It is recommended that the installation directory of PHP is "C:\PHP" rather than "C:\Program Files\PHP", or it's better now to include spaces with PHP's installation directory.

After these installations, reboot your system.

Now, copy the downloaded JavaBridgeTemplate file to the webapps folder of your Apache Installation.

Try browsing "http://127.0.0.1:8080/JavaBridgeTemplate554" and "http://127.0.0.1:8080/JavaBridgeTemplate554/test.php" to see if PHP is already recognized by Apache. You should see PHP information by now.

Now, to allow or to support PHP in all Apache Tomcat's applications, or to allow PHP files to be saved directly to ROOT and not limited to JavaBridgeTemplate554 folder, copy all contents of "webapps\JavaBridgeTemplate554\lib" to "Tomcat\lib" or similar. This will make all necessary files for ROOT to run PHP available.

Now to enable directives to the Apache Engine, add these lines to "Tomcat\conf\web.xml" right before "" at the bottom: (make a backup of this file in case you'll mess it up)

<listener><listener-class>php.java.servlet.ContextLoaderListener</listener-class></listener>


<servlet><servlet-name>PhpJavaServlet</servlet-name><servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>

</servlet>

<servlet><servlet-name>PhpCGIServlet</servlet-name><servlet-class>php.java.servlet.PhpCGIServlet</servlet-class>


<init-param><param-name>prefer_system_php_exec</param-name><param-value>On</param-value></init-param>

<init-param><param-name>php_include_java</param-name><param-value>On</param-value></init-param>


</servlet>

<servlet-mapping><servlet-name>PhpJavaServlet</servlet-name><url-pattern>*.phpjavabridge</url-pattern> </servlet-mapping>

<servlet-mapping><servlet-name>PhpCGIServlet</servlet-name><url-pattern>*.php</url-pattern></servlet-mapping>





Now, save it.

Now, try to launch a PHP file directly from ROOT folder. Try making a php file if you haven't done so for example:

<html><body>
<?php echo phpinfo(); ?>
</body></html>

Don't forget the .php file extension. Now try running the file directly at "http://127.0.0.1:8080/filename.php", you should see now the PHP information and you're done!