Overview
Craft CMS is a flexible, user-friendly content management system built for developers and content creators who want complete creative freedom without compromise. Unlike traditional CMSs that force you into rigid content structures, Craft gives you the tools to build any type of website or application with custom content models, powerful querying, and an intuitive control panel that clients actually enjoy using.
What makes Craft exceptional is its content-first philosophy. Instead of blog posts and pages, Craft thinks in terms of flexible content structures called "sections" and "fields." You define exactly what content your site needs - whether it's products, recipes, real estate listings, or anything else - and Craft provides a beautiful interface for managing it. Content creators get structured editing experiences tailored to their workflow, while developers get the freedom to implement any design without fighting the CMS.
The Matrix field is one of Craft's most powerful features, allowing you to build flexible, modular content layouts without page builders or shortcodes. Editors can mix and match content blocks (text, images, videos, quotes, galleries) in any order, giving them creative freedom while maintaining design consistency. It's like having a page builder built into your CMS, but with full developer control over markup and styling.
Craft's templating uses Twig, PHP's elegant and powerful template engine. Twig is designer-friendly with clean syntax that separates logic from presentation, yet powerful enough for complex data transformations. The template system is intuitive for front-end developers coming from other platforms, with excellent documentation and a logical structure that makes sense from the first project.
Multi-site capabilities are built into Craft's core, making it perfect for managing multiple websites, languages, or regional variations from a single installation. Content can be shared across sites or localized per site, with fine-grained control over what differs between sites. Localization is straightforward, with field-level translation support and flexible locale configurations that handle complex multi-language scenarios.
The control panel is genuinely a pleasure to use. It's fast, intuitive, and thoughtfully designed for content editors. Live Preview shows changes in real-time before publishing, the image editor handles basic transformations without leaving the CMS, and the asset manager makes organizing media files effortless. Clients can be trained on Craft in minutes, not hours, because the interface is that intuitive.
Craft's plugin ecosystem provides solutions for e-commerce (Craft Commerce), SEO, forms, calendars, and hundreds of other features. The plugin architecture is well-documented and follows modern PHP standards, making it straightforward to extend Craft or build custom plugins. Whether you need a simple contact form or a complete e-commerce platform, there's likely a plugin or you can build exactly what you need.
Performance is excellent out of the box, with intelligent caching, lazy-loading, and optimization features built in. Craft scales from small marketing sites to high-traffic platforms, with support for read replicas, Redis caching, and CDN integration. The system is built on Yii2, a mature PHP framework known for performance and security, giving Craft a solid foundation for production deployments.
Key Features
Flexible Content Modeling
Create custom content structures with sections, entries, fields, and Matrix blocks for any type of content
Matrix Field System
Build flexible, modular page layouts with reusable content blocks editors can arrange freely
Twig Templating Engine
Designer-friendly templates with powerful syntax, clean markup, and excellent documentation
Multi-Site Management
Manage multiple sites, languages, and locales from single installation with shared or localized content
Intuitive Control Panel
Beautiful, fast admin interface with live preview, asset manager, and image editing that clients love
Powerful Plugin Ecosystem
Extensive plugins including Craft Commerce for e-commerce, SEO tools, forms, and custom development
Slučajevi upotrebe
• **Corporate Websites**: Build flexible marketing sites with custom content models and multi-language support
• **E-commerce Platforms**: Craft Commerce provides full-featured online stores with product catalogs and checkout
• **Publishing & Media**: News sites, magazines, and blogs with complex content workflows and editorial calendars
• **Portfolio Websites**: Showcase work with custom project types, case studies, and flexible layouts
• **Multi-Site Networks**: Manage multiple brands, regional sites, or language variations from single installation
• **Web Applications**: Build custom web apps with Craft as headless CMS or full-stack solution
• **Membership Sites**: Create member portals with user-generated content and access control
Installation Guide
**Installation on Ubuntu 22.04 LTS:**
**1. Install PHP and Extensions:**
```bash
sudo apt update && sudo apt upgrade -y
sudo apt install php8.1 php8.1-{fpm,cli,mysql,gd,mbstring,xml,curl,zip,intl,imagick} -y
```
**2. Install Composer:**
```bash
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
```
**3. Install MySQL:**
```bash
sudo apt install mysql-server -y
sudo mysql
CREATE DATABASE craftcms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'craftuser'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON craftcms.* TO 'craftuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```
**4. Create Craft Project:**
```bash
cd /var/www
composer create-project craftcms/craft mysite
cd mysite
```
**5. Set Permissions:**
```bash
sudo chown -R www-data:www-data /var/www/mysite
sudo chmod -R 755 /var/www/mysite
sudo chmod -R 777 /var/www/mysite/storage
sudo chmod -R 777 /var/www/mysite/config
sudo chmod -R 777 /var/www/mysite/web/cpresources
```
**6. Configure Environment:**
```bash
cp .env.example .env
nano .env
```
Set configuration:
```env
ENVIRONMENT="production"
SECURITY_KEY="generate-via-php-craft-setup-security-key"
DB_DRIVER="mysql"
DB_SERVER="127.0.0.1"
DB_PORT="3306"
DB_DATABASE="craftcms"
DB_USER="craftuser"
DB_PASSWORD="secure_password"
DB_SCHEMA="public"
DB_TABLE_PREFIX=""
PRIMARY_SITE_URL="https://yourdomain.com"
```
**7. Configure Nginx:**
```bash
sudo nano /etc/nginx/sites-available/craftcms
```
Add:
```nginx
server {
listen 80;
server_name yourdomain.com;
root /var/www/mysite/web;
index index.php index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
client_max_body_size 100M;
}
```
Enable site:
```bash
sudo ln -s /etc/nginx/sites-available/craftcms /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```
**8. Get SSL Certificate:**
```bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com
```
**9. Run Craft Setup:**
```bash
php craft setup/security-key
php craft install
```
Follow prompts to:
- Set admin username and password
- Set site name and URL
- Configure email settings
**10. Access Craft:**
- Frontend: https://yourdomain.com
- Control Panel: https://yourdomain.com/admin
- Login with admin credentials from setup
Configuration Tips
**Essential Configuration:**
**1. General Config (config/general.php):**
```php
<?php
use craft\helpers\App;
return [
'*' => [
'defaultWeekStartDay' => 1,
'omitScriptNameInUrls' => true,
'securityKey' => App::env('SECURITY_KEY'),
'cpTrigger' => 'admin',
],
'production' => [
'devMode' => false,
'allowAdminChanges' => false,
'enableTemplateCaching' => true,
],
'dev' => [
'devMode' => true,
'allowAdminChanges' => true,
'enableTemplateCaching' => false,
],
];
```
**2. Database Config (config/db.php):**
```php
<?php
return [
'driver' => App::env('DB_DRIVER'),
'server' => App::env('DB_SERVER'),
'port' => App::env('DB_PORT'),
'database' => App::env('DB_DATABASE'),
'user' => App::env('DB_USER'),
'password' => App::env('DB_PASSWORD'),
'schema' => App::env('DB_SCHEMA'),
'tablePrefix' => App::env('DB_TABLE_PREFIX'),
];
```
**3. Twig Template Example:**
```twig
{# templates/index.twig #}
{% extends "_layout" %}
{% block content %}
<h1>{{ entry.title }}</h1>
{# Matrix field #}
{% for block in entry.contentBlocks.all() %}
{% switch block.type %}
{% case "text" %}
<div class="text-block">
{{ block.text|raw }}
</div>
{% case "image" %}
<figure>
<img src="{{ block.image.one().url }}" alt="{{ block.image.one().title }}">
<figcaption>{{ block.caption }}</figcaption>
</figure>
{% case "gallery" %}
<div class="gallery">
{% for image in block.images.all() %}
<img src="{{ image.url }}" alt="{{ image.title }}">
{% endfor %}
</div>
{% endswitch %}
{% endfor %}
{% endblock %}
```
**4. Querying Entries:**
```twig
{# Get all blog posts #}
{% set posts = craft.entries()
.section('blog')
.orderBy('postDate desc')
.limit(10)
.all() %}
{% for post in posts %}
<article>
<h2>{{ post.title }}</h2>
<p>{{ post.summary }}</p>
<a href="{{ post.url }}">Read more</a>
</article>
{% endfor %}
{# Get related entries #}
{% set relatedPosts = craft.entries()
.section('blog')
.relatedTo(entry)
.limit(3)
.all() %}
```
**5. Asset Transforms:**
```twig
{# Define image transform #}
{% set thumb = {
mode: 'crop',
width: 300,
height: 300,
quality: 80
} %}
<img src="{{ image.url(thumb) }}" alt="{{ image.title }}">
{# Or use named transforms (config/image-transforms.php) #}
<img src="{{ image.url('thumbnail') }}" alt="{{ image.title }}">
```
**6. Multi-Site Configuration:**
```php
<?php
// config/general.php
return [
'*' => [
'siteUrl' => [
'en' => 'https://example.com',
'fr' => 'https://example.com/fr',
'de' => 'https://example.de',
],
],
];
```
**7. Custom Module Example:**
```bash
# Generate module
php craft make module
# config/app.php
return [
'modules' => [
'my-module' => \modules\Module::class,
],
'bootstrap' => ['my-module'],
];
```
**8. Caching:**
```php
<?php
// Enable Redis caching
// config/app.php
use craft\helpers\App;
return [
'components' => [
'cache' => [
'class' => yii\redis\Cache::class,
'redis' => [
'hostname' => 'localhost',
'port' => 6379,
'database' => 0,
],
],
],
];
```
**9. CLI Commands:**
```bash
# Clear caches
php craft clear-caches/all
# Backup database
php craft backup/db
# Restore database
php craft restore/db path/to/backup.sql
# Run migrations
php craft migrate/all
# Generate security key
php craft setup/security-key
# Create admin user
php craft users/create
# Project config sync
php craft project-config/apply
```
**10. Performance Optimization:**
```php
<?php
// config/general.php
return [
'production' => [
'enableTemplateCaching' => true,
'cacheDuration' => 3600,
'maxCachedCloudImageSize' => 2000,
'optimizeImageFilesize' => true,
'transformGifs' => false,
],
];
```
**Best Practices:**
- Use environment variables for sensitive configuration
- Enable `allowAdminChanges => false` in production
- Implement proper image transforms for responsive images
- Use eager loading for related entries to avoid N+1 queries
- Enable template caching in production
- Regular database backups with `php craft backup/db`
- Use Project Config for version controlling settings
- Implement Redis/Memcached for high-traffic sites
- Keep Craft and plugins updated regularly
- Use Matrix fields for flexible content layouts