StaticPHP

StaticPHP

Getting Started

It is super easy to get started with StaticPHP for your next website project.

Before you use StaticPHP, make sure you create your source directory (e.g. src) and put your website files in there, including your PHP files.

Use the StaticPHP Launcher (Recommended)

The recommended and easiest way to use StaticPHP is with the Launcher.

The launcher will ensure you are always running the latest StaticPHP version upon each execution, and allow you to save your build configuration for easy execution in future.

  1. Download the latest StaticPHP Launcher file from GitHub.
  2. Modify the configurable options in that file to suit your project.
    • $path_to_source_files = Set this to the path where you have put your source files. A good name for the source directory is src but this is up to you.
    • $path_to_public_files = Set this to the path where you wish your generated output files. A good name for the public files is public but this is up to you.
    • $paths_to_ignore = Modify this array to include elements that will form parts of paths you wish to ignore.
    • $friendly_urls = Setting friendly URLs to false will turn PHP files into their respective HTML files. Setting friendly URLs to true will turn PHP files into their respective directories with an index.html file inside.
    • $metadata_delimiter = This will define the start and end lines of metadata and should be set to something you do not intend to use as metadata itself, such as three hyphens (---).
  3. Execute the StaticPHP Launcher with the following command: php StaticPHP-Launcher.php
  4. Check the output log for errors and fix them. Remember to re-execute StaticPHP Launcher after each modification of the source files or the output files may not reflect the changes.

Use the Command Line

  1. Download the latest StaticPHP file from GitHub.
  2. Execute StaticPHP with the following command php StaticPHP.php PATH_TO_SOURCE_FILES PATH_TO_PUBLIC_FILES PATH_TO_IGNORE FRIENDLY_URLS_TRUE_OR_FALSE METADATA_DELIMITER_TRIPLE_HYPHENS
    • The above command explained:
      • First part is you wanting to run PHP.
      • The second part is the file you wish PHP to execute.
      • The rest are parameters/arguments with information for StaticPHP. All should be self explanatory, but note the following.
        • PATH_TO_IGNORE is treated as a string, and therefore can only contain one element.
        • FRIENDLY_URLS_TRUE_OR_FALSE is treated as a boolean, so only true or false is acceptable, anything else will be treated as false.
        • METADATA_DELIMITER_TRIPLE_HYPHENS relates to what defines the start and end lines of metadata. This should be something you don't intend to use as metadata itself, such as three hyphens (---).
  3. Check the output log for errors and fix them. Remember to re-execute StaticPHP after each modification of the source files or the output files may not reflect the changes.

Use your own Custom PHP Script

  1. Download the latest StaticPHP file from GitHub.
  2. In your custom PHP file, include the StaticPHP.php file and create a new instance with the build configuration as parameters/arguments.

    <?php
    
    include __DIR__ . DIRECTORY_SEPARATOR . 'StaticPHP.php';
    
    $path_to_source_files = __DIR__ . DIRECTORY_SEPARATOR . 'SOURCE-FILES';
    $path_to_public_files = __DIR__ . DIRECTORY_SEPARATOR . 'PUBLIC-FILES';
    $paths_to_ignore = array( 'IGNORE-FILES' );
    $friendly_urls = true;
    $metadata_delimiter = '---';
    
    new StaticPHP( $path_to_source_files, $path_to_public_files, $paths_to_ignore, $friendly_urls, $metadata_delimiter );
  3. Execute your custom script with the following command php CUSTOM-PHP-SCRIPT.php (where CUSTOM-PHP-SCRIPT is the actual filename of your custom script).
  4. Check the output log for errors and fix them. Remember to re-execute your custom script after each modification of the source files or the output files may not reflect the changes.