ServersPHP on Apache: The Definitive Installation Guide Page 5

PHP on Apache: The Definitive Installation Guide Page 5

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

    % cat  script-test.php3
    > #!/usr/local/bin/php -q
    >  echo "PHP script interpreter is OK!n"; ?>
    > EOP
    % chmod 755 script-test.php3
    % ./script-test.php3
    PHP script interpreter is OK!

The '-q' switch tells the interpreter to suppress the
'Content-type: text/html' line it ordinarily prints by
default (because it assumes it's being run as a CGI script).

If PHP was built as an Apache module, the simplest way to test it is to
create a file in the DocumentRoot that contains this single line:

     phpinfo(); ?>

and then fetch it in a browser. It should display a long and detailed Web
page describing the PHP module, the extensions that were included when it was
built, and the Apache environment as well.

Going Further

With PHP installed and working, what do you do then? Well, that's really up
to you--but for a couple of examples of what's possible, check out the
PHP site itself and the
ApacheCon 2000 site. The PHP site is
totally driven by the software; as you browse through the online documentation,
you can see that not only is it 'live,' meaning that you can comment on it or
make suggestions for improvements, but you can also see what other
people have suggested. The ApacheCon 2000 site uses PHP to display the very
latest information on sessions, speakers, sponsors, and other aspects of the
conference, building each page when it's requested from the data, stored in a
MySQL database.

The documentation link at the PHP site is invaluable. While it doesn't give
a lot of guidance on how to accomplish things, it's very complete when it comes
to descriptions of the PHP functions. For more, check USENET or the PHP mailing

One final trick, which is illustrated at the PHP site, is to add the 'show
me the source' feature to your server. Add a line like this to your
/usr/local/web/apache/conf/httpd.conf file:

    AddType application/x-httpd-php3-source .phps

and then soft-link .php3 files to the same name with a
.phps extension, as with

    % ln -s some-php-file.php3 some-php-file.phps

Requesting the .phps file in a Web browser will display the
source of a PHP (or PHP-enabled HTML) file, nicely color-coded.

In Conclusion

If running the Apache Web server and wanting to make your Web pages more
interactive, responsive, personalised or otherwise to "spice them
up," PHP is an easy and excellent way to do it. The software is under
constant intense scrutiny by dozens of developers, so problems are fixed quite

Got a Topic You Want Covered?

If you have a particular Apache-related topic that you'd like covered in a
future article in this column, please let me know at coar@Apache.Org>. I do read and
answer my email, usually within a few hours (although a few days may pass if
I'm travelling or my mail volume is way up). If I don't respond within what
seems to be a reasonable amount of time, ping me again!

Appendix A: Building Apache at Lightspeed

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories