Appendix B. Setting Up the Code Examples

A SINGLE PACKAGE CONTAINING ALL CODE FOR CHAPTER 2 AND THE AJAX PATTERNS DEMOS AS WELL IS at http://ajaxify.com/run. Inside there is a INSTALL.txt file containing installation instructions. These instructions are reprinted below, but if you have any trouble, please do check the electronic version as it may include updates.

INSTALLING PHP
==============

* If you don't have it already, install PHP5 and integrate with Apache (or
  another web server). The demos rely on the PHP5 OO features, and won't work
  with PHP4 or below.

  There are various installers available that will create an "AMP" (Apache,
  PHP, and MySQL) setup for you (You'll need MySQL for the wiki demo - see
  below). e.g. XAMPP for all major platforms
  (http://www.apachefriends.org/en/xampp.html).  For Apple, consider
  http://www.entropy.ch/software/macosx/php/. For Linux, you may try the
  appropriate Redhat/Debian packages. Alternatively, try the compilation
  instructions at http://dan.drydog.com/apache2php.html.

SETTING UP AJAX DEMOS
=====================

* Unzip the package to a temporary location and copy run/, tutorial/, and
  records/ to the apache document root. Assuming the doc root is
  /apache/document/root:

    cp run tutorial records /apache/document/root.

  (Alternatively, if you have sufficient access, set up a new virtual host in
  apache's httpd.conf and point it to the root of the unzipped directory,
  ajaxdemos/).

* Ensure the server can write to (the initially empty) records/ directory. The
  easiest (though not the most secure) way is:

    chmod 777 apache/document/root/records

* Open up run/.htaccess and follow instructions there to set the library path.

* Finished! Visit http://localhost/run/ and http://localhost/tutorial. If you
  can access http://localhost/run/index.phtml but not http://localhost/run/,
  read the following note.

NOTE ON CONFIGURATION: You hopefully won't need any configuration because
run/.htaccess and tutorial/.htaccess contain the relevant settings. But some
apache installations will ignore those settings (depending on the AllowOverride
directive), so be ready to transfer some of the contents of run/.htaccess into
httpd.conf.  (run/.htaccess is a superset of tutorial/.htaccess.) Specifically,
modify the existing DirectoryIndex directive to include index.phtml, and add a
new type for phtml as in .htaccess. If the PHP include_path isn't working,
you'll probably need to modify it in php.ini according to the setting in
.htaccess.

SETTING UP THE WIKI DATABASE
============================

NOTE: The wiki demo and its refactorings are the only demos that require a
database. The setup isn't particularly difficult, but if you don't want to mess
with MySQL, you can still run all the other demos.

* Install MySQL if necessary
* Prepare for database access.
  * Enter mysql as power user, e.g.:
          mysql -u root
  * Create "ajaxify_wiki" power user with password "ajaxify_wiki", e.g.:
      GRANT ALL PRIVILEGES ON *.* TO 'ajaxify_wiki'@''localhost'
          IDENTIFIED BY 'ajaxify_wiki';
  * If you'd prefer to use an existing account instead, set the details in
    Model/DAO.php for any wiki demo you wish to run.
* Run run/wiki/Model/freshDB.sh. You only need to do this once, as the tables
  can be shared by all versions of the wiki. NOTE: Ensure your command-line
  path is set up so that "php" will resolve to php5.
* Point your browser at the wiki, e.g. http://localhost/run/wiki/, and you
  should see three fresh messages.

TROUBLESHOOTING
===============
If you run into any problems:
* Check the section below, as some demos require some extra setup.
* Try the tutorial demo first. It's less error-prone because there's no library
  path involved.
* Verify file permissions are correct. The easiest way is to run "chmod 755
  document/root". In addition, ensure the records/ directory is writable.
* For the wiki, manually check the database is ready and can be accessed with
  the settings in DAO.php.
* Verify your PHP setup - create a file with "<? php_info ?>" and see if you
  can access it from the browser.
* Ensure you're using PHP 5 (or later).
* Check that you can run a test file, with both .php and .phtml suffixes.
* Check that index.phtml is recognised as a valid directory index. (Check this
  by visiting path/index.phtml instead of just path/.)
* Check that you set the library in .htaccess.
* Check remoting is working as expected with a traffic sniffing tool. (See
  those listed in the Traffic Sniffing pattern).
* Inspect log files. Your PHP log might be different to your Apache error log,
  depending on your setup.
* If problems persist, mail michael@mahemoff.com.

DEMOS REQUIRING EXTRA SETUP
===========================

These demos won't work unless you do some extra setup.

* As mentioned earlier, all the wiki demos (/wiki/..) (but nothing else) require a
MySQL database.
* For all portal (/portal/..) and reader (/reader/..) demos, you need net
  access. For the portal synclinks demo (/run/portal/drilldown/syncLinks/), you
  also need to run prepareDrilldown.php first.
* For the shop demo, if you want to run the whole lazy registration process,
  you'll need some form
* For the progress indicator in the Ajaxagram tutorial
  (/tutorial/ajaxagram/..), you either need to run it with net access, or
  change the image source in index.html to point to "/resources/progress.gif".

Get Ajax Design Patterns 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.