Sites

Zotonic has the capability of serving more than one site at a time. You can have multiple sites enabled, each with its own set of templates, database and dispatch rules. Each site has its own hostname.

Create a site

First, prepare the database. In your terminal, connect to PostgreSQL:

$ sudo -u postgres psql (enter your OS password)

And create a database user for Zotonic. You may want to change the password:

postgres=# CREATE USER zotonic WITH PASSWORD 'zotonic';

Now, either give this user create rights to have Zotonic automatically create the database for you (recommended):

postgres=# ALTER USER zotonic CREATEDB;

Or create the site database manually:

postgres=# CREATE DATABASE zotonic WITH OWNER = zotonic ENCODING = 'UTF8';
postgres=# GRANT ALL ON DATABASE zotonic TO zotonic;

And quit postgres:

postgres=# \q

Now that there is a database Zotonic can be started. We do this in debug mode so that all console output is visible:

$ bin/zotonic debug

In a new terminal window, edit your /etc/hosts file, adding an entry for yoursite.test (the site hostname) to point at your local host:

127.0.0.1   yoursite.test

Create a new Zotonic site, based on the ‘blog’ skeleton site:

$ bin/zotonic addsite -s blog yoursite

Finally, point your browser to https://yoursite.test:8443 to see your new site. The browser will ask to accept a self-signed certificate. Zotonic generates a self-signed certificate for every site. These are stored in ~/.config/zotonic/security (on macOS ~/Library/Application Support/zotonic/security).

You can log into the admin at https://yoursite.test:8443/admin using the username admin with the password that you can find in your site’s configuration. Use for this the command:

$ bin/zotonic siteconfig yoursite

The configuration is stored in the file apps_user/yoursite/priv/zotonic_site.config in the zotonic user directory.

You can stop Zotonic by typing twice Ctrl-C at the Erlang command prompt.

If you want to start Zotonic in the background then use:

$ bin/zotonic start

This can be stopped with:

$ bin/zotonic stop

Anatomy of a site

A Zotonic site is a folder which lives in the zotonic user directory and contains at least:

  • a priv/zotonic_site.config file: sets the site’s hostname and other parameters
  • a src/sitename.erl file: initialises the site.
  • a src/sitename.app.src file: an OTP app source file

In fact, a site is a special type of module. Like modules, sites usually contain additional resources such as templates, dispatch rules and data . Unlike modules, however, sites have their own hostname and database connection.

Next steps

Directory structure Developer Guide The Status site

Referred by

Getting Started

You have two options for running Zotonic: to get started quickly, start our Zotonic container. Or you can install…

Templates

Templates are text files marked up using the Zotonic template language. Zotonic interprets that mark-up to dynamically…

mod_email_receive

Enables the Zotonic site to receive emails for the site’s users. The user’s email address is username@hostname , where…

mod_acl_user_groups

This module adds rule-based access control.

Reset a user’s password

Emergency password reset when you can’t get into the admin interface.

mod_email_relay

Enables the Zotonic site to relay emails for the site’s users to their real email addresses.

Dispatch rules

Dispatch rules route incoming requests to controllers.