2.6. Testing PHP

To test whether PHP is installed and working, follow these steps:

  1. Find the directory in which your PHP programs need to be saved.

    This directory and the subdirectories under it are your Web space. Apache calls this directory the document root. The default Web space for Apache is htdocs in the directory where Apache is installed. For IIS, it's Inetpub\wwwroot. In Linux, it might be /var/www/html. The Web space can be set to a different directory by configuring the Web server. If you're using a Web hosting company, the staff will supply the directory name.

  2. Create the following file somewhere in your Web space with the name test.php.

    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <p>This is an HTML line</p>
    <?php
       echo "<p>This is a PHP line</p>";
       phpinfo();
    ?>
    </body></html>

    The file must be saved in your Web space for the Web server to find it.

  3. Run the test.php file created in Step 2. That is, type the host name of your Web server into the browser address window, followed by the name of the file (for example, www.myfinecompany.com/test.php).

    If your Web server, PHP, and the test.php file are on the same computer that you're testing from, you can type localhost/test.php.

    For the file to be processed by PHP, you need to access the file through the Web server — not ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® 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.