Getting started
Installation
Requirements
| Component | Version / details |
|---|---|
| PHP | 8.1 or later, with pdo_mysql (or mysqli), mbstring, gd and curl |
| Web server | Apache with mod_rewrite (the project ships its own .htaccess files) |
| Database | MySQL / MariaDB. There are also PDO drivers for PostgreSQL, SQLite, SQL Server and Oracle |
| Composer | To install Smarty 4 and the other dependencies in composer.json |
| Redis (optional) | Only if you use the Redis cache engine |
Step-by-step installation
1. Code and dependencies
git clone <repository> /var/www/local.devel-mysite.com
cd /var/www/local.devel-mysite.com
composer install
webroot/index.php loads vendor/autoload.php, so composer install is required.
2. Virtual host
The site's DocumentRoot is the project folder, not webroot/. The root .htaccess sends everything that is not an existing file to webroot/, and the one in webroot/ sends it to index.php.
<VirtualHost *:80>
ServerName local.devel-mysite.com
DocumentRoot /var/www/local.devel-mysite.com
<Directory /var/www/local.devel-mysite.com>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The server name matters
Koshkil picks its configuration from $_SERVER['SERVER_NAME']. The virtual host's ServerName must match the name of the config/domains/<domain>/ folder.
3. Setup script
app/bin/setup.sh automates preparing a domain. It takes the domain name from the project folder, asks for the production domain and the database details, and then:
- creates
tmp/cache/{models,view,plugins},tmp/logs,tmp/sessionsandapp/tmp, writable by thewww-datagroup; - creates the MySQL database and user;
- generates
config/domains/<domain>/datasources.php.
./app/bin/setup.sh
To do it by hand, create the tmp/ folders with write permission for the web server, and the connection file:
<?php
// config/domains/local.devel-mysite.com/datasources.php
$CONFIG = [
'Database' => [
'AutoUpdateSchema' => true,
'master' => [
'Driver' => 'MySQLi',
'Host' => 'localhost',
'User' => 'user',
'Password' => 'password',
'Name' => 'mysite_db',
],
],
];
4. Domain configuration
Create config/domains/<domain>/config.php with, at least, the site's theme:
<?php
$CONFIG = [
'System' => ['DefaultController' => 'index'],
'Templates' => ['Theme' => 'mytheme'],
'Web' => ['SiteName' => 'My site'],
'Debug' => ['Level' => 2],
];
5. First run
The first time the site is opened, with AutoUpdateSchema enabled, the core tables (users, roles, rules, sessions, gallery…) are created and filled with their initial records, such as the Superusuario, Administrador, Cliente and Subusuarios roles.
The admin panel is at /admin.
After every deployment
Warm the caches so the first visit doesn't pay for reading schemas and translations:
./app/bin/warm-cache.sh # everything
./app/bin/warm-cache.sh --domain=models --verbose
php app/bin/warm-cache.php --force # clear and rebuild
See Cache, logs and debugging.
Command-line use
Without a web server, SERVER_NAME is empty and Koshkil reads its configuration from config/domains/cli/. To run framework code from a script, set the server variables first:
<?php
$_SERVER['SERVER_NAME'] = 'local.devel-mysite.com';
$_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__);
define('IS_CLI', true); // do not register the HTML error handler
require_once __DIR__ . '/core/Koshkil.php';
require_once __DIR__ . '/vendor/autoload.php';
Koshkil::getDatabase();
Koshkil::UsesModel('usuarios');
echo TMUsuarios::where('usr_estado', '1')->get()->count();