Installation and Configuration of Craft CMS
Craft CMS is installed via Composer. Requirements: PHP 8.2+, MySQL 8.0+ or PostgreSQL 13+, PHP extensions: imagick/gd, intl, fileinfo, mbstring.
Installation
composer create-project craftcms/craft my-project
cd my-project
php craft setup
# Answer questions: database host, name, user, password
# Creates .env and runs migrations
Project Structure
my-project/
├── config/
│ ├── app.php # application settings
│ ├── db.php # database
│ ├── general.php # main settings
│ └── routes.php # custom routes
├── modules/ # custom Yii2 modules
├── templates/ # Twig templates
│ ├── _layouts/
│ ├── _components/
│ └── index.twig
├── web/ # document root
│ └── index.php
└── .env
Main Configuration
// config/general.php
return [
'*' => [
'cpTrigger' => 'manage', // instead of standard /admin
'defaultWeekStartDay' => 1, // Monday
'omitScriptNameInUrls' => true,
'useEmailAsUsername' => true,
'translationDebugOutput' => false,
'maxRevisions' => 10,
],
'production' => [
'allowAdminChanges' => false, // forbid schema changes in prod
'allowUpdates' => false,
'backupOnUpdate' => false,
'devMode' => false,
],
'dev' => [
'devMode' => true,
'allowAdminChanges' => true,
],
];
Environment Variables (.env)
CRAFT_ENVIRONMENT=dev
CRAFT_APP_ID=CraftCMS--my-project
CRAFT_SECURITY_KEY=generated-secure-key
DB_DRIVER=mysql
DB_SERVER=127.0.0.1
DB_PORT=3306
DB_DATABASE=craftcms_dev
DB_USER=craftcms
DB_PASSWORD=password
DB_SCHEMA=public
DB_TABLE_PREFIX=
PRIMARY_SITE_URL=http://localhost:8080
ASSET_BASE_URL=https://cdn.mysite.com
Vite Setup for Assets
composer require nystudio107/craft-vite
// vite.config.ts
import { defineConfig } from 'vite';
import ViteRestart from 'vite-plugin-restart';
import { craftCmsViteConfig } from '@nystudio107/vite';
export default defineConfig({
...craftCmsViteConfig,
build: { manifest: true, outDir: './web/dist' },
server: { port: 3000, strictPort: true },
});
{# In layout #}
{{ craft.vite.script('src/js/app.ts') }}
{{ craft.vite.stylesheet('src/css/app.pcss') }}
Project Config
Craft stores structure configuration (sections, fields, entry types) in YAML files in config/project/. This allows managing structure through Git:
php craft project-config/apply # apply config from Git
php craft project-config/diff # view differences
In production allowAdminChanges: false — changes only through deploy, not UI.
Installation and basic configuration of Craft CMS takes 4–8 hours.







