Appendix A. Installing and Configuring the PHP Engine

If you want to write some PHP programs, you need a PHP engine to turn them from punctuation-studded text files into actual interactive web pages. The easiest way to get up and running with PHP is to sign up with a cheap or free web-hosting provider that offers PHP—but you can run the PHP engine on your own computer, too.

Using PHP with a Web-Hosting Provider

If you already have an account with a web-hosting provider, you probably have access to a PHP-enabled server. These days, it is the odd web-hosting provider that doesn’t have PHP support. Usually, hosting providers configure their servers so that files whose names end in .php are treated as PHP programs. To see whether your hosted website supports PHP, first save the file in Example A-1 on your server as phptest.php.

Example A-1. PHP test program
<?php print "PHP enabled"; ?>

Load the file in your browser by visiting the URL for your site (e.g., http://www.example.com/phptest.php). If you see just the message PHP enabled, then your website host supports PHP. If you see the entire contents of the page (<?php print "PHP enabled"; ?>), then your hosting provider probably doesn’t support PHP. Check with them, however, to make sure that they haven’t turned on PHP for a different file extension or made some other nonstandard configuration choice.

Installing the PHP Engine

Installing the PHP engine on your own computer is a good idea if you don’t have an account ...

Get Learning PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.