In my Beyond Frameworks talk, I explained how a component-based architecture can help answer some of the important (i.e. expensive!) questions you might face when creating long-lived apps that rely on a PHP framework. In this series of blog posts, I’m going to look at how to go about creating and working with components.

I’m now going under the bonnet of our components, and looking at the different file roles that the PEAR installer expects to find when we distribute our component as a PEAR-compatible package. It isn’t very often that a component needs to ship web pages too, but should the need arise, here’s how to do it.

What Is A Web Page?

A web page (the ‘www’ file role supported by the PEAR Installer) is any sort of content meant to be served up by web server software such as Apache. This can be a HTML file, a PHP script, CSS files, Javascript files, images … you name it.

Where Do Web Pages Go Inside Your Component’s Structure?

If we look at the PhpInfo component, you’ll find that the web pages live in the src/www/ folder:

src/www/ is meant to be a folder that holds all of the web pages (and related content) that you want installed into the computer system.

Where Does The PEAR Installer Install The Web Pages?

When you use the PEAR installer to install your component:

$ pear install phix/PhpInfo

all of the web pages get installed into /usr/share/php/www/ on your computer:

The PEAR installer’s behaviour here is almost identical to command-line scripts; the installer installs your web pages directly into the main www_dir folder. This does create the potential for clashes, where two or more packages want to install files with identical names. In practice, PHP components include web pages so rarely that the problem is unlikely to happen.

The test file src/www/phpinfo.php therefore ends up installed onto your computer as /usr/share/php/www/phpinfo.php.

There’s always the possibility that some Linux distros (and Mac OS X) will install doc files into a different folder. You can see where the PEAR installer will put these files on your computer by running:

$ sudo pear config-show | grep www_dir
PEAR www files directory   www_dir          /usr/share/php/www

How Do I Get Apache To Serve These Files?

By default, and for very good reasons, Apache does not serve content directly from /usr/share/php/www/. You will need to copy any files from /usr/share/php/www/ to your website folders (normally found under /var/www/) before they can be used.

4 Comments

  1. Christian Weiske says:
    August 16th, 2011 at 6:41 am

    > Where Does The PEAR Installer Install The Tests?
    > all of the test files get installed into /usr/share/php/www/
    wtf?

  2. Massimiliano Arione says:
    August 16th, 2011 at 12:07 pm

    Maybe you did too much copy&paste: “Where Does The PEAR Installer Install The Tests?” should be something with “pages” instead of “tests” ;-)
    Same for sentence “all of the test files get installed…”

  3. Stuart Herbert says:
    August 16th, 2011 at 2:49 pm

    @Massimalliano, @Christian thanks – fixed that error.

  4. Stuart Herbert On PHP – » PHP Components: Shipping Web Pages With … | Linux Blog says:
    August 17th, 2011 at 4:40 am

    [...] you might face when creating long-lived apps that rely on a PHP framework. … Read more: Stuart Herbert On PHP – » PHP Components: Shipping Web Pages With … This entry was posted in Uncategorized and tagged answer-some, beyond-frameworks, explained-how, [...]