PHP as Apache module

This simple extract shows how to run PHP as an Apache module on windows with just 4 lines of code. PHP configuration will be covered in another article. You will need the following set up to try this at home.

Requirements:

  • Windows 2000 or XP
  • Administrator access on said Operating System
  • Apache 2.0x
  • PHP, any version (4x +) but not the installer package


Steps:

  • Download Apache web server for windows (2.0.59 recommended)
  • Follow the default installation steps
  • Download the PHP binaries for Windows
  • Extract all the files into a folder of your choice


Once these tasks have been completed you should have Apache running as a service and all files will be located in X:\Program Files\Apache Group\Apache2 - X being your default hard drive.

You can really extract PHP to any location you wish, but in this example I have extracted php-5.2.0-Win32 to the following directory: X:\Program Files\Apache Group\php\php-5.2.0-Win32.

Next step is to open up your httpd.conf file in a text editor, wordpad or notepad, and add a few lines. The file, from the default installation is found in the X:\Program Files\Apache Group\Apache2\conf folder.

Do a search from "LoadModule" and you will see a list of modules that Apache tries to initiate when starting up. At the foot of this section, add the following 4 derivatives - each on a separate line: LoadModule; PHPIniDir; AddType; second AddType.

LoadModule php5_module "X:/Program Files/Apache Group/php/php-5.2.0-Win32/php5apache2.dll"
PHPIniDir "X:/Program Files/Apache Group/php/php-5.2.0-Win32"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

That's it. Left-click the Apache monitor icon that should be in your task-bar and press restart. You can create a php page to test if the installation has worked. Save the following as info.php in your X:\Program Files\Apache Group\Apache2\htdocs folder assuming you haven't modified your document root.

<?php
phpinfo();

Open up http://localhost/info.php in your favorite web browser. You should now see your PHP information nicely displayed on screen. You will notice some irregularities on the page, but that will be covered in the next article.

Comments

thanks very much for the

thanks very much for the information

Thank You .. I've got

Thank You .. I've got win2000 sp4 and loaded apache 2.2 and php 5.2.1 and with your code above got it working after seeing "Forbidden" for 2 days.

Thanks Again……

when i start up apache, it

when i start up apache, it says cannot find the php4apache2.dll module, although it is in the folder i have told it to look in. is there something else i need to do?

Tweak php.ini?

Hi Brad,

Assuming that you have changed the relevant settings to point to PHP4 etc,
then you will probably need to tweak php.ini in the folder that you have pointed Apache to.
See this post for more details…. with particular reference to the extension directory - "extensions" in php 4 IIRC.

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

Apache/2.2?

If you're running Apache2.2, make sure you have the lastest version of PHP http://snaps.php.net and you change php4apache2.dll (in the file path) to php5apache2_2.dll.

Hi,

Hi,
when I open http://localhost/info.php I get a popup screen which says that it is a php script and asks if i want to download it or I want to open it. When I open it it opens up in Dreamweaver…
Have I missed a step somewhere?

-Durdane-

I found a syntax error

I found a syntax error; I didnt put a " before the path.

Although I dont get a download popup, my browsers displays the following text:

What is the error you are getting?

What is the error you are getting?
Reply to post with your e-mail address and I can follow this up with you directly..

Please note that Wordpress seems to f%ck up the coding syntax…

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

Same issue as michael

After doing the configurations as mentioned above I am opening a file with the below code..

Hello World 1
<?php
echo "Hello World2";
?>
Hello World 3

When I use Internet Explorer I am getting the same error as Michael mentioned - get a pop up "Do you want to Open or Save the file ?"
When I use Firefox, I can see Hello World 1 Hello World 3. But I cannot see Hello World 2.

Please advise.
Thanks
Santosh

As previously stated ....

.. this has not been tested in Apache 2.2 and
please ensure that the path to the dll and the main PHP directory are correct.
You may also have to restart your PC - Windows can be a bitch like that sometimes.

Addition steps of editing "environment" settings may also be required.

Also, you are sure that you have download the correct type of PHP?
If you have got the CGI version, you cannot run it as a module.

You would want something like:

ScripAlias /php/ "c:php/"
Action application/x-httpd-php/php/php/php-cgi.exe
AddType applicaion/x-httpd-php .php

Again, make sure the paths are correct...

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

Thanks. I wonder why it is

Thanks. I wonder why it is not at any HowTo.
Thanks a ton.

Regards.
Harsh

I have installed MySql 5.0,

I have installed MySql 5.0, Apache 2.2, and PHP 5.2.1.

After updating the httpd.conf and php.ini files with all of the different reccomendations... i continue to get the same error when restarting the apache service:

The Apache service named reported the following error:
>>> directive requires additional arguments

and

The Apache service named reported the following error:
>>> Syntax error on line 163 of C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf:

I have made your changes and still get this. If i remove these changes and go back to the original settings, the apache service won't start back up.

When i use php5apache2.dll in the LoadModule section it tells me it can't find the module... so i use php5apache2_2.dll and thats when i get the above to error messages in the application log.

Any ideas would be great...!

Regards,

John

this is just some more

this is just some more information...

here is what lines 163 - 169 show

Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all

Not been tested

This has only been tested on Apache/2.0.59 (Win32) and various flavors of PHP.
Note that Wordpress seems to be f%cking up the coding syntax…

Make sure that you have PHP configured correctly first, things like environment variables too.

I am moving back to Drupal in a couple of days.

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

Thanks a lot for this. It

Thanks a lot for this. It helped me get apache2/php up and running very quickly. Your php.ini setup article was excellent as well. :)

I would really like to see an article on integrating MySQL as well!

Matt D.

Apache 2.2.4 and PHP 5.2.3 "blank screen"

i have these two installed on my Winxp machine and have the following snipt saved has phpinfo.php:

<?php
echo "Hello World";
?>

I am getting a blank screen still after adding the following lines to my httpd.conf file:

#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
#ScriptAlias /php/ "C:\\Program Files\\PHP\\"
#PHPIniDir "C:\\Program Files\\PHP\\"
LoadModule php5_module "C:\\Program Files\\PHP\\php5apache2_2.dll"
PHPIniDir "C:\\Program Files\\PHP\\"
AddType application/x-httpd-php .php
#Action application/x-httpd-php "C:\\Program Files\\PHP\\php-cgi.exe"
#LoadModule php5_module "C:\\Program Files\\PHP\\php5apache2.dll"
#PHPIniDir "C:\\Program Files\\PHP\\"
#LoadModule php5_module "C:\\Program Files\\PHP\\php5apache.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

I think I am missing something but don't really know...I think it may have to do with my dns server...

A few things

Sorry for the delay in the reply. I have been back in Scotland and away from the web for a while.
There are a few things I would suggest, though you probably have this sorted already by now...

1) Make sure that you have not used the installer for PHP.
2) Make sure that php5apache2.dll actually exists - note the name
3) Try changing your back slashes to forward slashes
4) Check your apache error logs and also turn up error_reporting in your php.ini file

Hope that helps.

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

BIG THANKS..

I would like to thank you. the trick was not using the MSI installer. just following the manual installation did the trick. thanks again.

Basic

Please be patient, thanks.

I run Windows XP2
Goal is to build a website with lots of forms and data collection. I have to have a working combo of Apache, PHP, MySQL. I cannot get anything to work.

1. I get all the errors from blank phpinfo() pages to where the local server cannot find the page saved as .php
2. And yes I have used <?php

phpinfo();

?>

with notepad. Some of the pages bring back part of the source code. Even when alone they check out ok, it is in real coding that everything breaks down.

3. So I tried the manual install. I entered the following on the command prompt

bin\Apache -k install
bin\Apache -k start

Fact is I think I entered it all wrong or my prompt does not work the same. Maybe someone can show me
exactly how to enter this kind of info on the DOS prompt.

Please assume no programming background. I was hoping to start learning code throgh this download but I am almost giving up.

Is anyone out there from around dallas? I sure would like to ask a few pointed questions on this subject from time to time...wont nag or bother you but just a few well thought out ??s.

Please help...

And thanks in advance.

Gegala.

Can you specify

Hi,

Can you please specify the steps you have taken ....
Do normal HTML pages work?

To get this to work you must:

1: Download and install Apache 2.x, see recommendations at the top of the page (default install is OK)
2: Download and install MySQL (default install is OK)
3: Install and extract a "non-windows installer" version of PHP
4: Create php.ini file and uncomment or add php_mysql.dll extension and any other settings you wish. See PHP ini settings for more
5: Edit httpd.conf as detailed above, ensuring paths point to your PHP extraction
6: Ensure that MySQL is running as a service (should be set up as service with default install)
7: Restart Apache, use the console or the shortcut created during installation.

Additional:

a) You may need to copy some dlls for PHP from the extensions directory to the main folder that you extracted PHP to
b) See the comments about Environment Variables in the linked page too
c) Make sure that your firewall isn't blocking connections

Please let us know how you got on...

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

question

I install apache2.2.4 and php5.2.4
on the run...I get error message

httpd.exe syntax error on line 115 of c:/program files/Apache Software Foundation/Apache2.2/conf/httpd.conf can not load c:/program files/Apache Software Foundation/Apache2.2/php/php5apache2.dll into server: The specified module could not be found.

on line 115 the code is
LoadModule php5_module php/php5apache2.dll

can anyone help me please.

The error means ...

The error means that the file isn't there.
Make sure that the path is correct and that there are "quotes" around the "path/to/file"...

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

If you are sure that the

If you are sure that the path to php5apache2.dll is valid it could be possible that some dlls are missing in your system. Check php5apache2.dll with DependencyWalker (http://www.dependencywalker.com/) and copy missing dlls into windows/system32 folder. Problem should disappear :)

Syndicate content