fegg-cli
fegg-cli is the command line entry point in the project root. Run it from there:
./fegg-cli <command> [arguments]
The file only defines the paths (see Directory structure); the commands are in htdocs/_fegg/core/src/Command/. Commands exit with code 1 when they find a problem, so they can be used in CI.
| Command | What it does |
|---|---|
migration | Create or change the tables (SQLite or MySQL) from the YAML schema files |
migration:db2schema <file> | Write the structure of the current database to a YAML file |
db:schema [table] [--json] | List tables and columns from the YAML schema files |
template:lint [file ...] | Check templates without running them |
site:create NAME PATH | Add a site (its folder and its lines in sites.php and route.php) |
site:list | List the sites, their paths and folders |
user:create LOGIN [NAME] | Add a CMS user |
user:password LOGIN | Set a new password for a CMS user |
user:list | List the CMS users |
user:hash | Print a password hash for FEGG_CMS_INITIAL_PASSWORD_HASH |
core:status | Show the core version and core files changed in this project |
core:update [vX.Y.Z] [--dry-run] [--force] | Update the core from the skeleton repository |
doctor [URL] | Check that _fegg/ cannot be read from the web |
dummy:create TABLE [COUNT] | Add dummy rows to a CMS table, not in production (see Dummy content) |
dummy:remove TABLE [COUNT] / dummy:count TABLE | Remove or count the dummy rows (a title starting with 【DUMMY】) |
Running a command group without a sub command prints its help: ./fegg-cli core, ./fegg-cli db, ./fegg-cli template, ./fegg-cli site, ./fegg-cli user, ./fegg-cli migration:help, ./fegg-cli doctor:help.
migration
./fegg-cli migration
Compares the table definitions in the YAML files with the database (SQLite, or MySQL / MariaDB) and applies the difference (adds tables, columns and indexes).
- The core's files (
core/config/database/:cms_user,cms_file,cms_image,rate_limit) are read first, then the project's (site/config/database/). A project file with the same name replaces the core's file. With the CMS turned off ($settings['cms'] = false, see Settings)cms_user,cms_fileandcms_imageare neither created nor dropped, and no first CMS user is created. - Starts with one line naming the environment, its file and the database, e.g.
Environment: staging (site/config/env/staging.php, /var/www/vhosts/*/p[0-9]*) / DB: sqlite:...(see Environments and secrets). - Prints
Fegg-cli migration diff : Not changedwhen the database already matches,Fegg-cli migration diff : Finished migrationafter applying changes. - Then creates the first CMS user when
FEGG_CMS_INITIAL_LOGINis set andcms_userhas no users at all, withFEGG_CMS_INITIAL_PASSWORD_HASH(orFEGG_CMS_INITIAL_PASSWORD) andFEGG_CMS_INITIAL_NAME. An existing user is never changed and a deleted one is not created again, so this is safe on every deploy. Without a usable password it exits with 1 after the migration. fegg-cli core:updateruns it automatically after updating the core.- On MySQL the YAML types are mapped to MySQL types and changed tables are altered in place. See Database configuration.
/cms/migrate/in the CMS shows the same pending changes and applies them with its "Run migration" button (POST), for servers where you cannot runfegg-cli.
The YAML files are the single source of truth. A table that exists in the database but in no YAML file is dropped, and a column that is not in the YAML is removed with its data. Run it against a copy first when you are not sure that every table is defined.
To create a YAML file from an existing database:
./fegg-cli migration:db2schema htdocs/_fegg/site/config/database/dump.yaml
All tables are written to the one file. Split it into one file per table if you keep it.
db:schema
./fegg-cli db:schema # every table
./fegg-cli db:schema cms_news # one table
./fegg-cli db:schema --json # as JSON
Lists the tables, columns (type, primary key, autoincrement, not null, default) and indexes defined in core/config/database/ and site/config/database/. It reads the YAML files, not the database, so it works without a database. It also warns when a table is missing one of the columns every table needs (valid, created, modified).
cms_news (htdocs/_fegg/site/config/database/cms_news.yaml)
news_id INTEGER primary key, autoincrement, not null
visible BOOLEAN
category INTEGER
title TEXT
...
valid BOOLEAN
post_date DATETIME
created DATETIME
modified DATETIME
index NEWS_ID unique (news_id)
template:lint
./fegg-cli template:lint # every template in site/template and core/template
./fegg-cli template:lint htdocs/_fegg/site/template/main/tpl/news/detail.tpl
Checks templates without running them and reports each problem with the .tpl file and line: unknown tags, unclosed blocks or extra {{ end }}, missing include / transclude targets, undefined modifiers, and output in URL attributes, <script> or event attributes that is not escaped for that context.
htdocs/_fegg/site/template/main/tpl/news/detail.tpl:12: unknown modifier "nosuch" (define it in site/functions/*.php)
htdocs/_fegg/site/template/main/tpl/news/detail.tpl:20: {{ $page.data.url }} starts a URL: write {{ $value|feggUrl }} so javascript: URLs are refused
NG: 2 problem(s) in 1 template(s)
Prints OK: <n> template(s) when there is nothing to fix. Run it after every template change.
site:create / site:list
./fegg-cli site:create recruit /recruit/ # NAME PATH
./fegg-cli site:list
site:create copies the starting folder core/dist/site/ (tpl/ with index.tpl, not_found.tpl and template/siteframe.tpl, a FLOCSS scss/, js/, img/ and the .htaccess) to site/template/recruit/, and adds $sites['recruit'] = array('path' => '/recruit/'); to site/config/sites.php and $route['recruit/'] = 'page/render/index'; to site/config/route.php. It refuses a name or a path that is already used. site:list prints each site's name, path and folder. See Sites.
CMS users
./fegg-cli user:create admin "Site administrator" # LOGIN [NAME]; NAME defaults to LOGIN
./fegg-cli user:password admin # set a new password
./fegg-cli user:list # user_id, login and name of every CMS user
Manage the CMS users (table cms_user). Passwords are asked twice without echo (never as an argument, which would stay in the shell history), must not be empty (there is no length rule), and are stored with password_hash(). From a script, or where there is no terminal, use --password-stdin:
printf '%s\n' "$CMS_PASSWORD" | ./fegg-cli user:create admin --password-stdin
user:create refuses a login that already exists; use user:password for it. With the CMS turned off, every user:* command refuses to run.
user:hash prints password_hash() of a password (asked without echo, or --password-stdin) for FEGG_CMS_INITIAL_PASSWORD_HASH in a committed environment file.
/cms/register/ needs a CMS login and developer mode; on a production server use fegg-cli.
core:status / core:update
core:status / core:update [vX.Y.Z] [--dry-run] [--force]: see Updating the core.
core:manifest also exists, but it is for skeleton maintainers only (it rebuilds core/manifest.json).
doctor
./fegg-cli doctor # check the .htaccess files on disk
./fegg-cli doctor https://example.com # also request the live site
Without a URL, it checks the files on disk:
htdocs/_fegg/.htaccessdenies access,htdocs/.htaccesshas the rule for_fegg/and lets through the files of_fegg/assets/, of the site folders'css/js/img/font/and of_fegg/site/up_dir/,_fegg/assets/, each site folder (site/template/<site>/) and the upload directorysite/up_dir/have their.htaccess, which serve only their file types (see Upload).
With a URL, it also requests files under _fegg/ (a site's SCSS sources and the upload directory's .htaccess included) and the SQLite database (when it is under the document root) on the live site and reports any that can be read, and checks that /_fegg/assets/js/base.js is served.
Prints OK: https://example.com does not expose _fegg/, or NG with the list of problems (exit code 1). You can run it from your local machine against the production URL, which is the easiest check after an FTP upload.
It also prints Warning: lines, without failing, for outdated rules in htdocs/.htaccess: a <IfModule mod_php5.c> block (ignored by PHP 7 and 8), and Apache 2.2 Order / Deny from lines (an HTTP 500 on Apache 2.4 without mod_access_compat; use Require all denied). Compare the file with core/dist/htaccess.dist.
Developer commands in the skeleton
The skeleton repository also has Composer scripts for the test suite and code checks. Composer is only used for development; the application never loads vendor/.
| Command | What it does |
|---|---|
composer test | PHPUnit: unit and HTTP integration tests (PHP 7.4 to 8.5). test:unit and test:integration run one suite |
composer test:mysql | The MySQL tests, against the server given in FEGG_TEST_MYSQL_DSN, FEGG_TEST_MYSQL_USER and FEGG_TEST_MYSQL_PASSWORD (skipped without them) |
composer analyse | PHPStan (level 5, with a baseline) |
composer cs:check | PSR-12 check of core/src and the tests (composer cs:fix applies the fixes) |
The integration tests run with FEGG_ENV=development and a throwaway SQLite database, so they never touch site/data/db/db.db.
The skeleton also builds the core's CMS files. Projects do not run these: the files come built with core:update.
| Command | What it does |
|---|---|
npm run build:cms | The core's CMS CSS, the editor (assets/editor/) and the icons it uses, into htdocs/_fegg/assets/ (committed) |
npm run typecheck | TypeScript check of the editor's source |
npm run cms:vendor | Copy the CMS's libraries (SortableJS ...) from node_modules to htdocs/_fegg/assets/vendor/ |