# koha-create

koha-create

8

koha-create

Create a new Koha instance.

UNIX/Linux

          koha-create
          --create-db|--request-db|--populate-db|--use-db
          --marcflavor marc21|unimarc
          --zebralang el|en|es|fr|nb|ru|uk
          --memcached-servers server:port
          --memcached-prefix namespace_prefix
          --elasticsearch-server server:port
          --defaultsql /path/to/some.sql
          --configfile /path/to/config
          --passwdfile /path/to/passwd
          --dbhost host
          --database database
          --adminuser n
          --enable-sru
          --sru-port port
          --template-cache-dir directory
          --timezone time/zone
          --upload-path directory
          --tmp-path directory
          --letsencrypt
          --smtp-host host
          --smtp-port port
          --smtp-timeout n
          --smtp-ssl-mode disabled|ssl|starttls
          --smtp-user-name user
          --smtp-password  pass
          --smtp-debug
          --mb-host host
          --mb-port port
          --mb-user user
          --mb-pass pass
          --mb-vhost vhost
          --help|-h

          instancename

### Options

`--create-db`

- Create a new database on localhost. If the database you want to use does not reside on localhost, you can use `--request-db` and `--populate-db`, see below. If the database already exists, you can use `--use-db`, see below.

`--request-db`

- This option will create a file called `instancename-db-request.txt` in your current directory that contains information about how the database needs to be set up.

`--populate-db`

- When you have run koha-create with the `--request-db` option, and a database has been set up, you can finish your installation by running `koha-create` with this option.

`--use-db`

- When the database you want to use has already been populated, you can run `koha-create` with this option to take care of all the other set-up configuration.

`--configfile`

- Path to an alternative config file. This file can hold the same variables as the default config file, see below for details.

`--database`

- MySQL database to use.

`--dbhost`

- Database server hostname/IP to use.

`--defaultsql`

- Path to an SQL-file other than the one pointed to in the default or alternative config file. Corresponds to the DEFAULTSQL config file variable.

`--adminuser`

- Specify the borrowernumber of the user that should have a new, random password set as part of setting up the new instance. The password will be reported as part of the output of the current script. If --adminuser is not specified, the user with borrowernumber = 1 will be updated. If an SQL file is not used to populate the database of the newly created instance, no admin user will be created.

`--marcflavor`

- Specifies format of MARC records to be indexed by Zebra. Corresponds to the ZEBRA_MARC_FORMAT config file variable.

`--passwdfile`

- Path to an alternative passwd file. This file is in the same format as the default (Koha) passwd file, see below for details.

`--zebralang`

- Primary language for Zebra indexing. Corresponds to the ZEBRA_LANGUAGE config file variable.

`--memcached-servers`

- Specify a comma-separated list of host:port memcached servers for using with the created Koha instance. Defaults to `127.0.0.1:11211`, the needed configuration for a locally installed memcached server.

`--memcached-prefix`

- Specifiy a `namespace prefix` for memcached. You usually leave this option alone to avoid namespace collisions. It defaults to `koha_`.

`--elasticsearch-server`

- Specifiy a `server:port` Elasticsearch server configuration. It defaults to `localhost:9200`.

`--enable-sru`

- Enable the Z39.50/SRU server for the created instance.

`--sru-port`

- Specifiy a `TCP port number` for the Z39.50/SRU server to listen on.

`--template-cache-dir`

- Specify a `directory` for storing the template cache files of the instance. It defaults to `/var/cache/koha/instance/templates`.

`--timezone`

- Specify a `timezone` for the created instance. e.g. America/Argentina

`--upload-path`

- Specify a `directory` for storing the permanently uploaded files of the instance. It defaults to `/var/lib/koha/instance/uploads`.

`--tmp-path`

- Specify a `directory` for storing the temporary files. For example temporarily uploaded files of the instance. It defaults to `/var/lib/koha/instance/tmp`.

`--letsencrypt`

- Set up a https-only website with letsencrypt certificates

`--smtp-host`

- Specify the SMTP server `hostname`. (default: localhost)

`--smtp-port`

- Specify the SMTP server `port`. (default: 25)

`--smtp-timeout`

- Timeout for outbound SMTP connections. (default: 120)

`--smtp-ssl-mode`

- Set the SSL mode. Options are `disabled` (default), `ssl` and `starttls`.

`--smtp-user-name`

- Specify the user name to use for SMTP. (default: empty)

`--smtp-password`

- Specify the password for SMTP. (default: empty)

`--smtp-debug`

- Enable debug mode.

`--mb-host`

- Specify the host name for the RabbitMQ server. (default: localhost)

`--mb-port`

- Specify the port for the RabbitMQ server. (default: 61613)

`--mb-user`

- Specify the user to connect to the RabbitMQ server. (default: guest)

`--mb-pass`

- Specify the password to connect to the RabbitMQ server. (default: guest)

`--mb-vhost`

- Specify the vhost to use on the RabbitMQ service. (default: koha_instance)

`--help`,`-h`

- Print usage information.

### Description

`koha-create` creates a new Koha instance. It is meant for a site that provides Koha hosting, and serves several sites from the same host.

The name of the instance is used as the domain name for Apache, Unix user and group names, and MySQL username and database names are derived from it. Unix user and group are named instance-koha. MySQL username is koha_instance, and database is koha_instance.

The Unix user has logins disabled. The password for MySQL is generated randomly, and printed to the terminal.

The instance name is used as the domain name (ServerName) for Apache. The public catalogue (OPAC), for library customers, is on port 80. The staff interface is configured similarly, depending on the settings in `/etc/koha/koha-sites.conf` or alternate config file.

After the Koha instance is created, it is ready to be used, but the librarian needs to log in via the intranet and configure things.

Several configuration variables are available for adjusting this behavior. The variables are put into `/etc/koha/koha-sites.conf`. The following variables are obeyed:

`DOMAIN`

- The domain to append to the instance name, for Apache ServerName. Default is empty. The value must begin with a period.

`OPACPORT`

- The port for the OPAC.

`OPACPREFIX`

- This is inserted before the instance name when forming Apache ServerName. For subdomains, make sure it ends with a period.

`OPACSUFFIX`

- This is inserted after the instance name, but before the domain name, when forming Apache ServerName.

`INTRAPORT`

- The port for the intranet. If you set this to empty or 80, then you must also define INTRAPREFIX or INTRASUFFIX.

`INTRAPREFIX`

- This is inserted before the instance name when forming Apache ServerName. For subdomains, make sure it ends with a period.

`INTRASUFFIX`

- This is inserted after the instance name, but before the domain name, when forming Apache ServerName.

`DEFAULTSQL`

- An SQL file (compressed with gzip) that can be fed to mysql(1) to initialize the database after it has been created. Might be created using koha-dump-defaults(8).

  If the SQL file contains users, the user with borrowernumber = 1 will have a new, random password set. This password will be reported in the output of the script. If another user than borrowernumber 1 should have its password set, the borrowernumber of this user can be set with the --adminuser command line option.

`MEMCACHED_SERVERS`

- A comma-separated list of valid memcached servers. Usually in the form of `host:port`. If not present koha-create will default to `127.0.0.1:11211`. Also, this will be overriden by the arguments of the `--memcached-servers` switch.

`MEMCACHED_PREFIX`

- A prefix for all new Koha instances to use in memcached. If not present koha-create will default to `koha_`. Also, this will be overriden by the arguments of the `--memcached-prefix` switch.

`ZEBRA_MARC_FORMAT`

- Specifies format of MARC records to be indexed by Zebra. Possible values are 'marc21' and 'unimarc'.

`ZEBRA_LANGUAGE`

- Primary language for Zebra indexing. Possible values are 'en', 'es', 'fr', 'nb', 'ru' and 'uk'.

Order of precedence for config options, from lowest to highest:

1. The defaults set in the code of `koha-create`

2. `/etc/koha/koha-sites.conf`

3. Config file specified with `--configfile`

4. Individual command line options

### Files

``/etc/koha/koha-sites.conf``

- Configuration variables are read from this file, if it exists.

``/etc/koha/passwd``

- Pre-selected database credentials are read from this file, if it exists. The format for this file is instancename:username:passwd:database:dbhost. Database is optional, but the other three are required if you want to use pre-determined database user credentials.

### Bugs

The program is a bit fragile. If something goes wrong, it does not clean up after itself.

Bugs can be reported here: http://bugs.koha-community.org/bugzilla3/

### Example

To create a new Koha instance:

`koha-create --create-db hslibrary`

The public catalog is now at http://hslibrary/ and the librarian interface at http://hslibrary:8080/.

To use full domain names, and have the intranet interface on port 80, but on a different domain name, add the following variables to the configuration file:

- DOMAIN=".example.com"

- INTRAPORT=""

- INTRASUFFIX="-intra"

This will result in the addresses for the public and intranet interfaces becoming these:

- http://hslibrary.example.com/

- http://hslibrary-intra.example.com/

Configuration changes only apply to instances created afterwards.

### See also

- `koha-remove(8)`