Dynamic Page Serving

Dynamic Page Serving

generates web pages in HTML format by default. This allows you to view your pages in your browser offline by clicking on them or accessing them through the application View menu. Gigatrees can create thousands of separate files which make deployment to online servers a bear. I used to recommend users zip up their entire website before uploading it to the hosting service, and then extracting it after it has been upload, now I recommend dynamic page serving.

Comparitively, very few websites are deployed in HTML format anymore (at least that is my impression). Instead, pages are usually served from a database requiring a dynamic programming language to access and serve the pages.

Dynamic page serving means that rather than building thousands of static HTML pages, Gigatrees can store those web pages inside an SQLite3 database, reducing the footprint to less then 40 files, and then serve those pages from the database. This will require that your web server supports SQLite3 and PDO extensions. This is standard for Apache servers and easily enabled if not done so by default. Consult your server documentation for instructions.

In order setup dynamic page serving, you need to make several changes to their configuration. First, you need to open the Extension option and select the "PHP extension" option and deselect "Link Extension". This first of these will cause your generated web pages to be generated in PHP format rather than HTML and the second will leave of the ".php" extension in hyperlinks making your URLs SEO friendly and obfuscating the undelying file structure.

"Set the PHP Extension"
Set the PHP Extension

The second change you need to make is to Menu Bar option. There you will need to deselect the "Link Index" option. When deselected, instead of linking to the index file in a folder, hyperlinks will be created to just the folder name. This is generally how web server's are setup, but you will need to make sure your's is setup appropriately.

"Disable Link Index"
Disable Link Index

Next you will need to make changes to the Database option. There you will need to select "Enable Server Database". You also need to give your database a filename. Any valid filename will do. The extension should be ".sqlite". For example: my-database.sqlite. You will also need to use the "Local Database Path" option to select a folder on your computer where you want the database stored. This is necessary for the application to find and use when building your website. Lastly, you will need to set the path on your server where you will be storing your database. This is your server path, so make sure you get your slashes correct. A trailing slash is required. Generally, you do not want to store your database into a public folder on your server, lest someone try to download it directly, although you can prevent this by disallowing direct access to the file. I will be discussing this a bit later.

"Database Setup"
Database Setup

Now that you have your setup complete, you will want to save your configuration and then launch your application. The first time you run the application it will ask you to create the database - do so. When the application finishes, your output folder will include several PHP files and an HTACCESS file. The HTACCESS file is an Apache Web Server specific file. If you are using a different server, you will need to convert this file to a similar file compatiable with your server.

The HTACCESS file is the first thing loaded by the Apache server when get a web page request from a browser. Your HTACCESS file contains three small sections of server code. The first section prevents direct access to itself, your database file and your configuration file, though I would not recommend uploading your configuration file to your server. The second section prevents visitors from viewing the content of your server's directories. The last section forwards all request to URLs that are not otherwise found, to the "router.php" file for processing. If a file is found, it will be called directly. This allows you to include other web pages within your website structure.

## Prevent direct access to private files
<FilesMatch "\.(htaccess|sqlite|xml)$">
  order allow,deny
  deny from all

## Prevent direct access to directories
Options +SymLinksIfOwnerMatch -MultiViews -Indexes

## Redirect missing files and directories to router
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ router.php

The Router is the primary handler for your application generated web pages, which are now contained in your database. Its function is to parse the URL, extract the web page filename, lookup that filename in the database, read out the contents, assemble the page (prepending the Header, appending the Footer, and making any last minute macro substitutions) and then send it to the requesting browser. At the top of the Router file, are included two other files: "includes.php" and "pdodriver.php". The Includes file simply defines the database server path that you setup in your configuration, for instance define ('GIGATREES_PAGES_DB', '/databases/my-database.sqlite');. This allows the router to use a named constant to locate the database. The PDO driver file provides handlers that allow the router to read data from the SQLite3 database using PDO extensions. The Header (header.php) and Footer (footer.php) files were created from your Metadata and Plugins configuration and are kept separate allowing for last minute changes without rebuilding your website. Also when the applications runs, it does not overwrite pages that have not changed making the build process much faster. Keeping the Header and Footer separate means that you can change them without affecting the changed status of your page. The same holds true for making changes to stylesheets.

All that is left to do, is to deploy your website. This generally means you will use FTP or some type of SSH connection to copy your website into a folder on your server. This will include your database file, the HTACCESS file, the 5 PHP support files, the "assets" folder [1], the "plugins" folder (if you have any), and if you have a blog, the "blog" folder, which contains your "feed.rss" file. Once deployed, you should be able to load your website using the your domain name and the folder name you selected in your URL, for example: http://domain.com/website.

 [1]Mine has 26 files
Built with Innuendo 1.0.4