Instead of allowing for all possibilities, the emphasis here is on providing a simple set of instructions that always work (fingers crossed). From this foundation, experimentation can occur in a controlled manner.
Step 1 – Get Apache 2.x.x installed (without PHP modules) – tested on 2.0.52 and 2.2.3
Step 2 – Get PHP 5.x.x working – tested on 5.1.4, and 5.2.0
Step 3 – Get mysqli module working (assumed to need MySQL) – tested on 4.1.9
Gotcha: in the Apache config file, change backslashes to forwards slashes – e.g “C:/PHP”. In the PHP config file leave backslashes as they are: “C:\Program Files etc”.
1 – Apache
Uninstall any previous version after backing up httpd.conf somewhere.
Install Apache (e.g. 2.2.2)
Having trouble finding a Windows binary? Check this out:
Annoyed at how uncertain the process of getting a Windows binary can be? Read:
Edit httpd.conf esp:
- ServerAdmin email@example.com
- ServerName localhost:80
- DocumentRoot “C:/Projects” (or wherever you want to store web pages)
# This should be changed to whatever you set DocumentRoot to.
- DirectoryIndex ………. index.php (usually index.html etc first)
- # WINDOWS REQUIREMENTS ###
Make sure Apache is running BEFORE adding PHP functionality.
If you see a red dot instead of a green triangle, apache is not running successfully.
If you have problems check out:
2 – PHP
Create a “C:\PHP” folder
Extract the PHP windows binary file (preserving folder structure) to “C:\PHP”
Do NOT use the windows installer, just the zip file – extract to C:\Program Files\PHP maintaining the folders.Â All dlls are correctly brought across (unlike installer).
Save “php.ini-recommended” as “php.ini” in “C:\PHP”.
“13. How do I know if my “php.ini” is being found and read?
It seems like it isn’t as my changes aren’t being implemented.
To be sure your “php.ini” is being read by PHP, make a call to phpinfo() and near the top will be a listing called “Configuration File (php.ini)”. This will tell you where PHP is looking for “php.ini” and whether or not it’s being read. If just a directory PATH exists then it’s not being read and you should put your “php.ini” in that directory. If “php.ini” is included within the PATH then it is being read. If “php.ini” is being read and you’re running PHP as a module, then be sure to restart your web server after making changes to “php.ini” http://www.php.net/manual/en/faq.installation.php
Anyhow, you need to edit php.ini, esp:
- display_errors = On (NB this machine must only be used as a development machine)
- include_path = “.;c:\php\pear” (NB the . tells PHP to look in its own folder first – don’t overlook it!)
- extension_dir = “c:\php\ext”
Edit httpd.conf, so it will run PHP as a module:
- # PHP ##########################
LoadModule php5_module “c:/php/php5apache2.dll”
AddType application/x-httpd-php .php
The location of the loaded modules seems to result in numerous problems for people. Sometimes it is not because a file is missing, but because the file needs a companion file to operate. The Apache error message is probably misleading.
PHP searches for php.ini in the following locations (in
* PHPIniDir directive (Apache 2 module only)
* The PHPRC environment variable (possibly only relevant for CGI)
* Directory of PHP (for CLI), or the web server’s directory (for
* Windows directory (c:\windows or c:\winnt)
If you are running Apache 2, the simpler option is to use the
NB set the PATH in Windows to look at “c:\php”. Set this in Control Panel> System> Advanced> Environment Variables> System Variables> Path.
Plus set the PHPRC variable:
- Go to Control Panel and open the System icon (Start -> Settings -> Control Panel -> System, or just Start -> Control Panel -> System for Windows XP/2003)
- Go to the Advanced tab
- Click on the ‘Environment Variables’ button
- Look into the ‘System variables’ pane
- Click on ‘New’ and enter ‘PHPRC’ as the variable name and the directory where “php.ini” is located as the variable value (e.g. “c:\php”
- Press OK and restart your computer
A reboot is needed for this to take effect. This will enable PHP to locate files such as “php5ts.dll”
“NB the order of the paths in “Path” will be the order in which Windows looks for files. If you have multiple versions then make sure the correct version will be found first. Depending on your setup there is a good chance php.ini, or php5apache2.dll in “C:\Windows\System32” will take precedence over the one in “c:\php” if you have multiple.
One possible gotcha – if you have put copies of files such as php5apache2.dll, libmysql.dll, and php5ts.dll in “c:\Windows\System32” or “c:\Windows” in previous installation attempts, you will need to remove them (reboot in Safe Mode using F8) or overwrite them with newer versions. It seems that only files from the same PHP installation should be used in conjunction with each other.
“Don’t mix up your installation with DLL files from different PHP versions. You have the only choice to use the DLL’s and extensions that ship with your downloaded PHP version.”
Although lots of bulletin boards recommend putting files in the WINDOWS or SYSTEM32 directories, don’t.
“Previous editions of the manual suggest moving various ini and DLL files into your SYSTEM (i.e. “C:\WINDOWS”) folder and while this simplifies the installation procedure it makes upgrading difficult. We advise you remove all of these files (like “php.ini” and PHP-related DLLs from the Windows SYSTEM folder) before moving on with a new PHP installation. Be sure to backup these files as you might break the entire system. The old “php.ini” might be useful in setting up the new PHP as well. And as you’ll soon learn, the preferred method for installing PHP is to keep all PHP related files in one directory and have this directory available to your systems PATH.”
“The PHP manual used to promote the copying of files into the Windows system directory, this is because this directory “c:\Windows”, “c:\WINNT”, etc.) is by default in the systems PATH. Copying files into the Windows system directory has long since been deprecated and may cause problems.”
Restart Apache from the Apache Service Taskbar icon in the tray so it will take on board the changes to the Apache and PHP config files.
Create a small file with as the contents, and save it as “c:\projects\testphp.php”.
In your browser type in “http://localhost/testphp.php” and enter. Hopefully, you will see the phrase “PHP is working – Phew!!!”.
3 – MySQL
Add the following to php.ini:
extension=php_mcrypt.dll (nothing to do with MySQL but I usually add it for encryption needs while I’m there!)
mysqli.default_host = localhost
mysqli.default_user = xxxxx (whatever your user is)
PHP >= 5.0.0, requires “libmysql.dll” (libmysqli.dll in PHP <= 5.0.2) (bundled) PLUS: 2. COPY (do not move) libmysql.dll into the Apache2\bin directory (Even though there's no reference to this file in ANY error message I or my students have received, I have spent an interminable amount of time over the past seven weeks chasing this particular problem. All the references are to missing mysql functions when called from a PHP script and, literally, the only "mysql" dll that was not available in the extension_dir was libmysql.dll, so we tried putting libmysql.dll into the php\ext directory with no mas. Then, we put it into the Apache2\bin directory and we had connectivity! This goes against my natural inclinations to have a tidy installation, but it works, so I've passed it out to my students and the folks at the local LAMP that I've helped with their installations.) HTH. drj http://www.notestips.com/80256B3A007F2692/1/TAIO-64MEGD