NOTE: This project was primarily generated using AI. It's provided as-is for community use and contributions are welcome.
Build and use the Smarty template engine as a single, portable PHAR file.
This is a TEMPORARY solution for specific legacy scenarios only:
- ✅ Legacy systems with FTP-only access
- ✅ Quick prototyping without full development environment
- ✅ Shared hosting without Composer/SSH access
- ✅ Learning Smarty without command-line tools
NOT recommended for:
- ❌ Production web services
- ❌ Modern PHP projects with proper dependency management
- ❌ Long-term solutions
- ❌ Projects that can use Composer
For proper production applications, always use the official method:
composer require smarty/smartyThis PHAR approach is a convenience workaround for situations where Composer is not available. Migrate to Composer-based dependency management as soon as possible.
-
Download the latest pre-built PHAR from the Releases page — pick the file matching your PHP version:
Smarty-v5.x.x.phar— PHP 8.1+ (recommended for new projects)Smarty-v4.x.x.phar— PHP 7.2 to 8.xSmarty-v3.x.x.phar— Legacy PHP 5.6+ systems
PHARs are built automatically each week from the latest Smarty release for each major version.
-
Upload via FTP to your web server (e.g., into your public_html folder)
-
Create a writable directory called
templates_c(set permissions to 755 or 777) -
Use in your PHP file:
<?php
// Include the PHAR file (use the actual filename you downloaded)
require 'Smarty-v5.x.x.phar';
// Create Smarty instance
$smarty = new Smarty\Smarty();
// Configure directories
$smarty->setTemplateDir('./templates'); // Where your .tpl files are
$smarty->setCompileDir('./templates_c'); // Must be writable!
// Simple inline template (no files needed)
echo $smarty->fetch('string:Hello {$name}!', ['name' => 'World']);That's it! No Composer, no command line, no complex setup.
For Smarty usage and template syntax, see the Official Smarty Documentation.
Requirements:
- PHP with
pharextension enabled - Composer installed
- Network access (for downloading dependencies)
Basic usage:
./build-smarty-phar.shOutput: dist/Smarty-v{resolved_version}.phar
Configuration options:
| Variable | Default | Description |
|---|---|---|
SMARTY_MAJOR |
5 |
Target Smarty major version (3, 4, or 5) |
PROJECT_DIR |
build |
Temporary Composer workspace |
OUTPUT_DIR |
dist |
Where the PHAR is written |
OUTPUT_PHAR |
(auto) | Override full output path/name |
ALLOW_DIR_REUSE |
0 |
Reuse non-empty PROJECT_DIR |
ALLOW_PHAR_OVERWRITE |
0 |
Overwrite existing PHAR |
KEEP_PROJECT_DIR |
0 |
Keep temp directory after build |
COMPOSER_BIN |
composer |
Path to Composer binary |
Examples:
# Latest Smarty 5.x (default)
./build-smarty-phar.sh
# Latest Smarty 3.x, overwrite existing
SMARTY_MAJOR=3 ALLOW_PHAR_OVERWRITE=1 ./build-smarty-phar.sh
# Build all major versions
for v in 3 4 5; do
SMARTY_MAJOR=$v ALLOW_PHAR_OVERWRITE=1 ./build-smarty-phar.sh
done
# Custom output name
OUTPUT_PHAR=dist/smarty-custom.phar ./build-smarty-phar.shVerify a built PHAR works correctly:
php test.php [path/to/phar]If no path is provided, it automatically tests the newest dist/Smarty-v*.phar. The test creates a Smarty instance and renders a simple template.
- Make sure you're using
new Smarty\Smarty()(with namespace) for Smarty 4.x and 5.x - For Smarty 3.x, use
new Smarty()(without namespace)
- Ensure
templates_cdirectory exists and is writable (chmod 755 or 777) - Check that your web server has write permissions
- Use absolute paths or paths relative to your PHP file
- Example:
$smarty->setTemplateDir(__DIR__ . '/templates');
- Smarty 5.x requires PHP 8.1+
- Smarty 4.x requires PHP 7.2+
- Smarty 3.x supports PHP 5.6+
When you're ready to migrate to proper dependency management:
- Install Composer on your server
- Create
composer.json:{ "require": { "smarty/smarty": "^5.0" } } - Run
composer install - Replace
require 'Smarty-vX.X.X.phar';withrequire 'vendor/autoload.php'; - Remove the PHAR file
MIT License - see LICENSE file for details.
Note: Smarty itself is licensed under LGPL-3.0. This project only provides packaging scripts.
See CONTRIBUTING.md for guidelines.
Remember: This is a temporary workaround. For production applications and long-term projects, always use Composer for dependency management.