StaticPHP Docs

Getting Started

Your next project begins here.

All Steps

Step One: Download and Install

Create a new folder/directory for your project (e.g. mysite). Download the latest version of StaticPHP to your project folder/directory. It is recommended to download the launcher instead of StaticPHP itself, as this will keep you up-to-date with the latest StaticPHP features and provide easy customization options.

All Steps

Step Two: Setup Your Project Structure

Inside your project folder/directory, decide what you want to call the folder/directory where your source files will be located (e.g. src) and create it.

Decide on the name of the folder/directory where your generated output files will be located (e.g. public) and create it.

If you are using, or plan to use, Git source control software, you may also want to create a .gitignore file now in the root of your project folder/directory.

Example .gitignore file:


# Ignore Generated Output Files
public
# Ignore StaticPHP File
StaticPHP.php

The above example will ensure that only the source files are commited to Git because the generated output files can be regenerated anytime, so make sure to replace public with your chosen folder/directory name. It also includes an entry to ignore StaticPHP.php which is recommended when using the launcher to ensure the main StaticPHP file does not get commited too. If you are not using the launcher, you may want this file included, so simply remove that line. Lines that start with a hash symbol # are comments.

All Steps

Step Three: Develop Your Website

Start creating HTML and PHP files, and let StaticPHP handle the rest. Ensure that any file paths, such as those for including other files, are relative to the location of the StaticPHP file.

Refer to the MetaData feature to explore additional capabilities for your website files.

All Steps

Step Four: Build and Deploy

Run StaticPHP to generate the static version of your website in the output folder/directory.

Make sure you have PHP installed where you want to run StaticPHP, whether it be your local machine, or a remote server. You can find out more about installing and using PHP on their website at www.php.net.

While there is no specific PHP version requirement for StaticPHP, it is recommended to use the latest PHP version for best results.

If using the launcher, simply run the following command:


php StaticPHP-Launcher.php

For those using the StaticPHP file itself, there are two options:

Using Command-Line Parameters

This method is less recommended due to the potential difficulty in remembering configuration options. However, for those who prefer this approach, there are two ways to do it.

Firstly, you need to know what each configurable option does when defined via command line arguments.

To define these options via command line arguments, make sure you have a terminal open with the path set to your project directory/folder.

Now choose which command line argument method you wish to use.

Named Flags Method

Named flags make it easy to define your configurable options via command line arguments in absolutely any order you choose. They look like --configurable-option=value.

Form a command similar to the following...


php StaticPHP.php [named-flags]

Now replace [named-flags] with your list of flags in the format of --configurable-option=value, where configurable-option is the name from the above list, and value being what you want to set that configurable option to.

Example Named Flags Command

Here is an example command usage where the source directory path and output directory paths are defined...


php StaticPHP.php --source_dir_path=src --output_dir_path=public

You can define as many or as few options as you want. There are safe defaults set inside StaticPHP which will be used for any configurable option you have not specified your own value for.

Positional Arguments Method

This is the very first way StaticPHP came into operation, and was used mostly for internal testing. It's recommeended to be used due to its complexity and how messy it is, but it has been left intact incase it is needed during testing, or someone else wishes to use it too.

You simply define the above options in order by just specifying their value in the order they appear.

Syntax of Positional Arguments Command

php StaticPHP.php source_dir_path output_dir_path items_to_ignore friendly_urls metadata_delimiter minify_html minify_css minify_js minify_html_tags_to_preserve bulk_redirects_filename redirection_template_filename minify_css_inplace items_to_passthrough generate_standard_redirects_file generate_htaccess_redirections minify_js_files_inplace
Example Positional Arguments Command

Here is an example command usage where the source directory path and output directory paths are defined...


php StaticPHP.php src public

You can define as many or as few options as you want. There are safe defaults set inside StaticPHP which will be used for any configurable option you have not specified your own value for.

Using a Custom Launcher Script

You can create a custom launcher script for more flexibility. Here is an example:


<?php

$source_dir_path = __DIR__ . DIRECTORY_SEPARATOR . 'src';
$output_dir_path = __DIR__ . DIRECTORY_SEPARATOR . 'public';
$items_to_ignore = array( '_includes' );
$friendly_urls = true;
$metadata_delimiter = '---';
$minify_html = true;
$minify_css = true;
$minify_js = true;
$minify_html_tags_to_preserve = array();
$bulk_redirects_filename = "_bulk_redirects";
$redirection_template_filename = "_redirection_template.html";
$minify_css_inplace = true;
$items_to_passthrough = array();

include __DIR__ . DIRECTORY_SEPARATOR . 'StaticPHP.php';

new StaticPHP
(
    $source_dir_path,
    $output_dir_path,
    $items_to_ignore,
    $friendly_urls,
    $metadata_delimiter,
    $minify_html,
    $minify_css,
    $minify_js,
    $minify_html_tags_to_preserve,
    $bulk_redirects_filename,
    $redirection_template_filename,
    $minify_css_inplace,
    $items_to_passthrough
);

All Steps

Step Five: Commit to Git

This step is optional, but if you are using Git source control, you may want to commit it now to make sure your progress is saved.

Add All Files to Git

git add .

Commit Changes to Local Repository

git commit -m "Commit Message Goes Here"

Push to Remote

git push origin master

All Steps

Conclusion

By following these steps, you can get started with StaticPHP and easily build and deploy your static websites. For more detailed information, refer to the accompanying documentation and guides.