faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 12 people (58%) answered Yes
Recently 6 of 10 people (60%) answered Yes


PHP/Apache setup/config problems... Also: PHP script showing up blank or displaying actual PHP source
PHP/Apache setup/config problems... Also: PHP script showing up blank or displaying actual PHP source
PHP/Apache setup/config problems... Also: PHP script showing up blank or displaying actual PHP source

Mar 28th, 2008 16:55
ha mo, Rob Tyson,

If, while installing PHP with a web server (Apache for instance) you
have no problem, then kudos.  It seems like you're the lucky one.  For
the rest of us, the fact that there are several similar ways of setting
up PHP to work with a web server like Apache seems to have left many
newer developers feeling like the process is a bit 'trial and error'.  
I've seen a number of 'help' pages where contributors almost come off as
criticizing anyone that doesn't have PHP working on their server.  A
standard response seems to be "You don't have it set up right...Go do it
right" which doesn't help anybody figure out what they were doing wrong.
I've also seen pages upon pages of tutorials where people argue over
small details that they figure makes their method 'right'.  Ironically,
most of these pages seem to suggest almost the exact same thing as the
installation instructions for PHP off www.php.net.
In the most simple terms, the process of setting up PHP with Apache is
as follows:
Install Apache and PHP
1) Make sure your system is clean (ie no files or services left as
artifacts from previous Apache or PHP installations)
2) Install Apache (In most cases, you don't need to modify the Apache
config yet)
3) Verify that Apache can serve html pages
4) Install PHP 
Get PHP working with Apache
5) Add the PHP folder to your Windows Path Environment so that Apache
will be able to 'see' the core PHP dll file (Consult the webpages below
for details)
6) Use "php.ini-recommended" and quickly ensure the correct path is
being used for extension_dir (ie 'extension_dir = "C:\PHP5"').  While
you're at it, quickly check to see that other paths such as doc_root are
pointing to the right place. Save the file as "php.ini"
7) Add lines to the bottom of the Apache config file to load the PHP
module, recognize what extensions to parse for PHP, and point to the
path for "php.ini"
For the details surrounding this process, I present two webpages that
are both very straightforward and extrememly helpful:
This page has helped many people.  It also enables you to use PHP5 with
Apache2.2.2 without waiting for official support from www.php.net:
(Follow this page *step-by-step*)
If you are still having problems, read this page.  It is written for
people with no experience and actually describes a couple simple ways of
testing what might be going wrong.
If you have verified that:
1) Your Apache server is installed properly (and can serve html pages)
2) PHP is installed properly
...but your *.php pages are still showing up as blank or as the actual
PHP source, then consider the following potential culprits:
- Incorrect use of the 'AddType' directive in the Apache config file
(should be something like "AddType application/x-httpd-php .php .html")
- Incorrect encoding either in your config file or your browser (This
shouldn't be a problem if you stick with the default install/config
instructions that come with PHP5/Apache)
- ***The sneakiest culprit ever*** Some text editors (Notepad is a
notorious for this) will insert a non-viewable character
in front of your code.  You can't view it, but it's enough to invalidate
your "<?php" tag.  The remedy is to find a different text editor that
doesn't insert any characters into your document.  I myself used
Programmer's Notepad (http://www.pnotepad.org/)