Directory structure
Fegg 5 separates, by directory, the core shared by every project from the site that belongs to one project.
There is only one rule: do not edit htdocs/_fegg/core/ or htdocs/_fegg/assets/. fegg-cli core:update replaces them. If you edit them, fegg-cli core:status lists the changed files and core:update stops. Anything you want to change goes on the site/ side (see Overriding the core).
# Project root (does not need to be uploaded to the server)
fegg-cli # project: CLI entry point (path definitions only)
docs/ tests/ package.json composer.json ...
assets/ # skeleton only: sources of the core's CMS files (SCSS, the editor), built into _fegg/assets/
htdocs/ # document root
index.php # project: web entry point (path definitions only)
.htaccess # project: template is _fegg/core/dist/htaccess.dist
_fegg/ # never readable from the web, except assets/, the sites' css/ js/ img/ font/ and up_dir/
.htaccess # core: deny all
assets/ # core: the CMS's CSS, JS, images, icons and libraries (built; {{ $site.cms_assets }})
core/ # core: DO NOT EDIT (replaced on update)
src/ # Fegg\ every class of the core: Application, Model, Database\Pdo, Cms\Helper, Tool\* ...
Controller/ # Fegg\Controller\ Controller (base class), Cms\Login, Cms\Media, Cms\Image ...
Command/ # Fegg\Command\ fegg-cli commands
template/cms/ # CMS foundation templates
functions/ # template modifiers (feggDate, getImageUrl, ...)
config/ # default settings, YAML for the core tables (cms_user, cms_file, cms_image, rate_limit)
bootstrap/ # web and CLI start-up, autoloader
vendor/ # PHPMailer
dist/ # templates for the project-owned entry files, and the starting folder of a new site (dist/site/)
VERSION manifest.json UPGRADE.md
site/ # project: edit freely (never touched by updates)
src/ # Site\ every class of the project
Controller/ # Site\Controller\ Controller (project base class), Index, News, Cms\News ...
template/
main/ # the site at / (one folder per site, see site/config/sites.php)
tpl/ # its templates (every template path is relative to it)
scss/ # its styles, built into css/ by npm run build:scss
css/ js/ img/ # served from /_fegg/site/template/main/ ({{ $site.assets }})
cms/ # the CMS, the same shape: tpl/ (post types, overrides of core/template/cms/), scss/unique.scss
functions/ # project template modifiers (loaded automatically)
config/ # settings.php, env.php (per server, not committed), route.php, database_config.php, site_info.php, cms_menu.php ...
database/ # YAML table definitions for the project's tables
up_dir/ # files uploaded from the CMS (not tracked by git), served at /_fegg/site/up_dir/
data/ # db/, log/, cache/, core-backup/ (not tracked by git)
The skeleton's sample code (site/src/Controller/Index.php, News.php, Contact.php, Cms/News.php, ...) is project code. Change or delete it as the project needs.
A project can hold several sites (a recruiting site at /recruit/, landing pages), each with its own folder in site/template/: see Sites.
Namespaces
Classes are loaded by the core's own autoloader (core/bootstrap/autoload.php). Composer is not required; in the skeleton it is only used for the test suite.
There are two namespaces, each in one folder. The path below the folder is the rest of the namespace (PSR-4):
| Namespace | Directory | Example |
|---|---|---|
Fegg\ | core/src/ | Fegg\Controller\Cms\Image is core/src/Controller/Cms/Image.php |
Site\ | site/src/ | Site\Controller\Cms\News is site/src/Controller/Cms/News.php; a class of your own, Site\Shop\Cart, is site/src/Shop/Cart.php |
URLs reach only the controllers (Site\Controller\, then the core's Fegg\Controller\): your other classes in site/src/ can never be called from a URL.
Every PHP file under htdocs/_fegg/ must start with defined('FEGG_CORE_DIR') || exit;. It stops the file from doing anything when it is requested directly from a URL.
Overriding the core
The site is searched first, then the core. This works like a WordPress child theme.
| What | How | Example |
|---|---|---|
| Templates | Put a file in site/template/cms/tpl/ at the path it has under core/template/cms/ | site/template/cms/tpl/login.tpl is used instead of core/template/cms/login.tpl |
| Config files | Put a file with the same name in site/config/ | site/config/validation_error_message.php replaces the core's messages |
| Settings | Write only the keys you want to change in site/config/settings.php | $settings['developer_ip'] = array(...); |
| CMS screens | Put a class that extends the core controller in site/src/Controller/, with only the methods you change | See Controller |
| CMS menu | Add one block to site/config/cms_menu.php | When you add a post type |
| DB tables | Put a YAML file in site/config/database/ (a file with the same name wins over the core's) | cms_news.yaml |
Entry files and layout
htdocs/index.php and fegg-cli belong to the project. They only define three paths and then load the core:
<?php
define('FEGG_HTML_DIR', __DIR__); // document root
define('FEGG_CORE_DIR', __DIR__ . '/_fegg/core'); // core
define('FEGG_SITE_DIR', __DIR__ . '/_fegg/site'); // site
require FEGG_CORE_DIR . '/bootstrap/web.php';
fegg-cli defines the same three constants and requires core/bootstrap/cli.php. Always keep the paths in the two files consistent. Templates for both are in core/dist/.
| Layout | Entry file |
|---|---|
Standard: htdocs/_fegg/ (always inside the document root: the CMS's CSS and JS are served from _fegg/assets/) | core/dist/index.php.dist |
The document root has a different name (public_html, etc.) | Keep the standard one. Only fix FEGG_HTML_DIR in fegg-cli |
Installed in a subdirectory (https://example.com/sub/) | Keep the standard one. The URL base is detected from SCRIPT_NAME |
Protecting _fegg/
In the standard layout _fegg/ is inside the document root. It is protected in layers:
htdocs/_fegg/.htaccessdenies all requests._fegg/assets/.htaccessand the.htaccessof each site folder (site/template/<site>/) let only CSS, JS, images and fonts through;site/up_dir/.htaccessonly the file types that can be uploaded (see Upload).htdocs/.htaccessreturns 403 for/_fegg/(except the CSS, JS, images and fonts of_fegg/assets/and of each site folder'scss/js/img/font/, and the files of_fegg/site/up_dir/), dotfiles and hidden directories (.git/;.well-known/stays reachable), and denies.db,.sqlite,.yaml,.tpl,.log,.md,.jsonand.distfiles.- Every PHP file under
_fegg/and every compiled template starts with the guard line (see Namespaces). fegg-cli doctor https://example.comchecks over HTTP that nothing under_fegg/(a site's SCSS sources included) and no database file can be read (see fegg-cli). Run it from your local machine after every upload: many FTP clients skip.htaccess. The CMS dashboard also warns about problems it can detect from the files, such as a missing.htaccess.- If the server allows it, put the SQLite database outside the document root (see Settings).
On nginx, where .htaccess is not used, add equivalent rules:
# The CMS's files (_fegg/assets/) and each site's (_fegg/site/template/<site>/{css,js,img,font}/) first
# (nginx uses the first regex that matches)
location ~* ^/_fegg/(assets|site/template/[a-z0-9-]+/(css|js|img|font))/[^?]+\.(css|js|map|png|jpe?g|gif|svg|webp|woff2?|ico)$ { }
# The uploaded files (_fegg/site/up_dir/): the uploaded file types only, never scripts; a missing image
# size and /file/<id>/ go to PHP. ^~ keeps the regex locations below (and the PHP handler) out
location ^~ /_fegg/site/up_dir/ {
location ~* \.(jpe?g|png|gif|webp|pdf|docx?|docm|dotx|dotm|xlsx?|xlsm|xltx|xltm|xlsb|xlam|pptx?|pptm|ppsx|ppsm|potx|potm|ppam|sldx|sldm|thmx|one|zip|txt|csv)$ { try_files $uri /index.php?$query_string; }
location ~ /\. { deny all; }
location ~* \.[a-z0-9]+$ { deny all; }
rewrite ^ /index.php last;
}
location ~ (^|/)_fegg(/|$) { deny all; }
location ~ /\.(?!well-known/) { deny all; }
location ~* \.(tpl|db|sqlite|ya?ml|log|md|json|dist)$ { deny all; }