[KUBE](../README.md)  /  Site # Site ## Site Creation Stages of Site Creation: ### 1. Configuration. The configuration, as a file (`/config/.config`), contains the connection parameters for `MariaDB` and `Redis`. The configuration can be prepared before starting the site creation or will be generated automatically. Example configuration file: ``` databaseName=example_com databaseUser=example_com redisUser=example_com databasePass=qwerty redisPass=qwerty ``` Fields not specified will be generated automatically. The names of the database, database user, and `Redis` user are generated based on the domain using the functions `mariadbDomain2id` and `domain2redis`. ### 2. Initial Check. Before starting the site creation, some configuration checks are performed: * Check for absence of the vhost directory for the domain (`/path/to/vhosts/example.com`) * Check for absence of the domain entry in the `OpenLiteSpeed` configuration * Check for absence of the specified database * Check for absence of the specified database user * Check for absence of the specified `Redis` user ### 3. Distribution Check. When creating a site, you can specify the source for the site files as `pathF` and the source for the database as `pathD`. `pathF` can be a directory or an archive file. `pathD` can be a SQL file for import as is, or an archive file. If a file source `pathF` is specified, its presence is checked. Otherwise, the default distribution is used: * for `Wordpress`: the directory `/vhost.wordpress` (if the directory is missing, the file `/vhost.wordpress.tar.gz` is used) * for `non-Wordpress`: the directory `/vhost.default` (if the directory is missing, the file `/vhost.default.tar.gz` is used) If the specified data sources are not found, or the default resources are not found, the process is aborted. ### 4. Site Creation. When a site is created, the following steps occur: * creation of the site directory structure `//{www,tmp,session}` * copying site files from the source to the site directory * creation of an OS user for the site files and changing access rights * creation of a record in the `OpenLiteSpeed` configuration * creation of a database and database user in `MariaDB` * creation of a `Redis` user * importing the database from the source, if specified * writing database connection parameters (for `Wordpress`) * writing Redis connection parameters (for `Wordpress`) * writing to hosts (?!) * restarting `OpenLiteSpeed` *** ## Site on Wordpress creation * MariaDB > The database name and database user name are formed on the basis of domain conversion, where all `.-` are replaced by `_`. If necessary, the conversion rule can be changed (mariadbDomain2id function). When generating connection parameters, the database password is saved to the `data/.mariadb` file. Example for `example.com`: ```php define( 'DB_HOST', 'mariadb-master' ); define( 'DB_NAME', 'example_com' ); define( 'DB_USER', 'example_com' ); define( 'DB_PASSWORD', 'qwerty' ); ``` * Redis > Redis username is generated based on domain conversion, where all `.-` are replaced by `_`. The conversion rule can be changed if necessary (`domain2redis` function). When generating connection parameters, the database password is stored in the `data/.redis` file. Example for `example.com`: ```php define( 'WP_REDIS_HOST', 'redis-0.redis' ); define( 'WP_REDIS_PORT', '6379' ); define( 'WP_REDIS_PASSWORD', ['example_com', 'qwerty'] ); define( 'WP_REDIS_PREFIX', 'example_com:' ); ``` > [!NOTE] > A separate Redis user is created for each Wordpress and a PrefixKey is also specified to separate keys in Redis. *** ## Commands ### `--site add [pathF] [pathD]` Adding a site Example: ```bash sudo kube.sh --site add example.com sudo kube.sh --site add example.com /path/to/files /path/to/database ``` *** ### `--site wp