Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
88 lines (56 sloc) 2.7 KB

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

  1. 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;
    postgres=# \c zotonic
    postgres=# CREATE LANGUAGE "plpgsql";
  2. Edit your /etc/hosts file, adding an entry for yoursite.dev (the site hostname) to point at your local host:

    127.0.0.1   yoursite.dev
  3. Finally, create a new Zotonic site, based on the ‘blog’ skeleton site:

    $ bin/zotonic addsite -s blog yoursite

    Note

    Zotonic has to be running for the addsite command to succeed.

  4. Then rebuild Zotonic:

    $ cd dir/to/zotonic
    $ make
  5. And (re)start Zotonic:

    $ bin/zotonic debug
  1. Finally, point your browser to http://yoursite:8000 to see your new site. You can log into the admin at http://yoursite:8000/admin with the password that you can find in your site’s configuration file: :file:`yoursite/priv/zotonic_site.config` in the :term:`user sites directory`.

    Note

    If anything goes wrong, see the :ref:`ref-troubleshooting-installation`.

Anatomy of a site

A Zotonic site is a folder which lives in the :term:`user sites 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 :ref:`module <guide-modules>`. Like modules, sites usually contain additional resources such as :ref:`templates <guide-templates>`, :ref:`dispatch rules <guide-dispatch>` and :ref:`data <guide-modules-versioning>` . Unlike modules, however, sites have their own hostname and database connection.

Next steps