PHPStaticRender is a Python tool that converts dynamic PHP projects into static HTML websites. It recursively traverses a directory, executes PHP files using the system's interpreter, and saves the output as HTML, while directly copying static files. Ideal for performance optimization and hosting on servers without PHP.
- Complete Rendering: Processes an entire PHP project recursively.
- Automatic PHP Detection: Finds the PHP executable on the system (XAMPP support on Windows).
- Link Conversion: Automatically converts internal
.phplinks to.htmlin generated HTML. - Text Replacement: Custom find-and-replace patterns via TOML configuration (URLs, placeholders, etc.).
- Static File Copying: Keeps CSS, JS, images, and other files intact.
- Ignore System: Configurable prefixes to ignore files (e.g.,
__header.php). - Flexible Configurations: Customize output folders, extensions, and more via TOML file or script constants.
- Detailed Reports: Processing statistics and error handling.
- Compatibility: Works on Windows, Linux, and macOS.
- Python: 3.6 or higher.
- PHP: Installed on the system (CLI) with command-line execution support.
- Operating System: Windows, Linux, or macOS.
-
Clone the repository:
git clone https://github.com/gmasson/phpstaticrender.git cd phpstaticrenderor download the ZIP file from the repository and extract it.
-
Ensure Python 3.x is installed:
python --version # Should show 3.6+ -
Check if PHP is installed:
php --version
- On Windows, install XAMPP if necessary.
-
Copy the
phpstaticrender.pyscript to the root directory of your project (e.g.,index.php,about.php, etc.). -
Run the script:
python phpstaticrender.py
-
Done! The static site will be generated in the
_PHPStaticRenderfolder.
my-project/
├── index.php
├── about.php
├── css/
│ └── style.css
├── js/
│ └── script.js
└── phpstaticrender.py
After execution:
my-project/
├── _PHPStaticRender/
│ ├── index.html
│ ├── about.html
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── script.js
└── ...
Create a PHPStaticRender.toml file in your project root to customize settings per project.
This file is completely optional - the script works perfectly without it using default settings.
[config]
output_folder = "_PHPStaticRender"
ignore_prefix = "__"
php_extension = ".php"
encoding = "utf-8"
safe_mode = false
manual_php_path = "" # Auto-detect by default
ignore_system = [
".git", "node_modules", ".env"
]
# Replace patterns in generated HTML
[replace]
"http://localhost" = "https://example.com"
"http://127.0.0.1" = "https://example.com"
"/assets/" = "https://cdn.example.com/assets/"
"COMPANY_NAME" = "My Company Inc."Minimal Configuration: Define only what you need:
[config]
output_folder = "dist" # Only change output folder
[replace]
"http://localhost" = "https://mysite.com" # Only one replacementAll other parameters use default values from the script.
Benefits:
- Project-specific configurations
- No need to edit Python code
- Easy text replacements (URLs, paths, placeholders)
- Version control friendly
Requirements: Install TOML library for Python < 3.11:
pip install tomlEdit the constants at the top of phpstaticrender.py:
CONFIG_OUTPUT_FOLDER: Destination folder (default:_PHPStaticRender)CONFIG_IGNORE_PREFIX: Prefix to ignore files (default:__)CONFIG_PHP_EXTENSION: PHP extension (default:.php)CONFIG_IGNORE_SYSTEM: Folders/files to ignore (e.g.,.git,node_modules)CONFIG_ENCODING: Encoding (default:utf-8)CONFIG_MANUAL_PHP_PATH: Manual PHP path if detection failsCONFIG_SAFE_MODE: Safer PHP execution (default:False)
For detailed configurations, see DOCUMENTATION.md.
- Error: "PHP executable not found": Install PHP or configure
CONFIG_MANUAL_PHP_PATH - PHP files not processed: Check if the extension is
.php(case-sensitive) - Includes don't work: Ensure relative paths are correct in PHP code
- Encoding issues: Change
CONFIG_ENCODINGtocp1252on legacy Windows
For detailed solutions, see DOCUMENTATION.md.
Contributions are welcome! See CONTRIBUTING.md for guidelines.
- DOCUMENTATION.md - Complete technical documentation
This project is licensed under the MIT License - see LICENSE for details.