Categories
PHP
Javascript
MySQL
C#
VB
VB.NET
ASP.NET
Regex
Packaging & compression
General Web Tech
Tech Speak


Google


This website looks best on firefox.
 
Resource Center : PHP : <apache, php installation and config issues -for windows>

apache, php installation and config issues -for windows

Posted by: Floresense Team

If you are developing PHP websites or applications on an apache based webserver.. then this installation note might help troubleshoot a core installation issue.

Apache and PHP installation are straight forward.. atleast on windows.

Troubles and troubleshooting options discussed below are based out of numerous painful attempts and the learning curve in setting up a php environment on a windows machine. Below notes are not intended for linux users.

For windows, You just need to download a .msi file and double-click to install.

Installing apache as a service:

The apache msi installation most often successfully installs apache as a windows service.

If not, the only possible errors are:

Issue 1.
A windows service already exists from a previous apache installation and has the same name as the one current installation wants to use.

Issue 2.
You don't have rights to install apache, or install a windows service on the machine.

For issue 2: ask a system administrator to install apache for you.

For issue 1: uninstall any previous versions of apache, make sure the old apache service is not in the 'services' administrative panel. If uninstallation doesn't remove the service and you still see the service in the 'services' administrative panel.. open regedit go to HKLM/Software, browse all 'current control set' services keys.. remove all with name 'Apache'.

Now reinstall new apache (if u had to manually delete it from registry..

restart machine before reinstalling).

PHP installation:

PHP 4 and above have .msi file installations.. but this is only for basic installation.. if you want extensions and more advanced php libraries, you need to donwload a win32 binary of the php version you want to install.

* Extract the win32 binary.. or zip folder to say c:/php441 if your ver is php 4.4.1 * rename php.ini-recommended as php.ini - you will need this for configuring various php extensions and for configuring the php environment. * actually that's it.. you are only left with adding a few lines to apache configuration to tell apache that php is available.

Apache - PHP configuration:

Although its just a 2 or 3 line configuration that is needed, this can be quite a tricky part.. (or is it that all open source software have always kept configuration tricky . and only understandable by fellow geeks..whatever)

As php manuals say.. you need to add the below lines on the httpd.conf file in apache /conf folder

I generally open the httpd.conf folder in my apache installation, from /conf directory, and search till i find a set of 'LoadModule' lines. At the end of the lines, I add the new loadmodule for php

#For php4, 
LoadModule php4_module "C:/Program Files/Apache Group/Apache2/bin/php4apache2.dll"
#For php5,
LoadModule php5_module "D:/php5/php5apache.dll"

#Ini directory pointer.. 
PHPIniDir "c:/php441"

If you have php.ini in your windows directory, that php.ini in c:/windows is loaded and you dont need the PHPIniDir line

Firstly, just add the loadmodule and restart apache service.. if it starts then continue with php ini config..

Because of a problem with LoadModule, Apache might fail with 'Could not service', or 'Service start failed'.
This simply means the dll we are pointing for the loadmodule is faulty or has dependencies which are not to be found. If you are a go-for-it person, download windows 'dependency checker' from microsoft.com or from here.

Open depends.exe and open the php4apache2.dll or php5apache2.dll as the case may be. if you see red messages or notifications that one or more libraries could not be loaded. pat yourself, you just found out what it is. For example, if it says an error across 'php4ts.dll', then your php4apache2.dll should be in same directory as php4ts.dll.

If it says erors with libHTTPD.dll, or libAPR.dll, then you need to copy php4apache2.dll and php4ts.dll into the bin directory in your apache installation and point your loadmodule appropriately.

To test, you can load php4apache2.dll in depends.exe from the new location and you will see some or all 'could not load'/missing errors gone.

If you have something like lipapr.dll missing, and your apache bin directory has only libapr1.1.dll then you are using incompatible php and apache versions. either you need to go back a version on your php or install a higher version in apache.

This is all because apache and php are developed by different people and these people would create the dlls which in turn uses a version of php4ts.dll, libapr.dll, etc., and interestingly you cant download php4apache2.dll and all its dependencies from one location either apache.org or php.net So all this ends up with users having to download and check compatible versions, or read the not-so-carefully written php manuals carefully and donwload the proper versions.

But there's some help.. there are people who donwload both apache, php, mysql, phpmyadmin, etc., and do all this compatibility study and make one big wrapped installation package, which is to install all of them. You could do a google search for such full packages by searching with words like 'WAMP -for windows, apache, mysql, and php', 'LAMP - linux, apache, mysql, and php', or 'xampp - for windows/linux, apache, mysql, php, phpmyadmin, perl, and a lot more'

But even in these packages, if you need advanced php settings like enable some php extensions, or adding new ones, or download new pear components, upgrading pear ..etc., all that you have to do with command line. Because packaged installers will obviously do only a default configuration, if you need better or little config then you have to take that command line overhead.

PHP extensions:

Coming back to php.ini and extensions.

You will need php extensions if you work with xml dom, or webservices, or some advanced date functions.

Like mentioned earlier, first you need to either put the php.ini in c:/windows or use the PHPIniDir directive to mention itse location in the apache httpd.conf file.

next restart apache.. if it starts normal.. good.. 
if it doesn't:

issue 1: your extension_dir setting in the ini is not proper. 

check this.. search for 'extension_dir' in php.ini and point it to 'extensions' directory in you php installation. for me it was 'c:/php441/extensions/' (mind the / at the end .. its required)

restart apache

issue 2:
php.ini has extensions enabled (which is default), and some extensions are missing or not loadable. if such is the case, check whether its an extension you need, if it is not needed add a ';' infront of the line 'extension=php_dbase.dll'.. if you dont need to use dbase functions in your php code php_dbase.dll

restart apache

issue 3:
apache starts but extension is not loaded.. or you get 'undefined function' errors in your php code though you know you have the extension included.

sometimes, due to some unhandled error in the lines before extension settings in php.ini, the rest of php.ini seems to be ignored by the loader and so extensions are not loaded.

You can test this by renaming your favorite extension say php_domxml.dll to php_domYxml.dll, and restarting apache. Apache should say that extension could not be loaded.. if not apache is just not reading that line at all in php.ini

If figured out that sometimes, the settings on top of the php.ini file, like

- error_reporting = E_ALL        [Code Cleanliness, Security(?)]
cause the problem.

Don't ask me why, but only after i disabled error_reporting, my extensions were loaded.

; - error_reporting = E_ALL   (commented)

Though everything seems set now, apache is running, its loading php module, and its recognizing and loading php extensions that are needed.

But because i had to comment error_reporting in the ini, i now have a php environment for version php 4.4.1 which doesn't report any errors.. it just stops working where the error occurred and i have to echo here and there to find out even missing parantheses problems.

But i think mine is a strange case of too many trials and incompatibles fixed later, and for the good i hope you may not have the problem.

If you do, with either error_reporting or some other ini setting.. then you can still load the ini setting right at the beginning of your .php script by using ini_set() function in php.

Hope this doc helped. It definitely helps me remember the travails of issues with apache and php, and does help to be a document on the web for issues which probably are fixed in newer apache and php versions.

Thanks, Harish, Floresense.com


Advertisement

2005 - 2008 © Floresense.com