Search The Hostwinds Guides Knowledge Base

Install and Configure Mezzanine (Ubuntu 19.10)

Share This Article

Mezzainine is a Content Managment system written in Python. It’s a great alternative to the popular WordPress, and offers a similar interface. 

You will need:

To get all of this running, use the command:

sudo apt install python3 python3-pip postgresql nginx libpq-dev

Then, use pip in install virtualenvwrapper*:

sudo pip3 install virtualenvwrapper

Normally, it’s a bad idea to use pip3 in install software, but virtualenvwrapper is one of the few packages that it makes sense to install system-wide.

Now, set up an environment for mezzanine and install it:

mkvirtualenv my_site

workon my_site

(my_site) pip3 install mezzanine uwsgi pillow

With all the dependencies installed, we need to set up the database.

Setting up the Postgresql user

Configuring a user for postgresql requires onlt a few SQL statements you8 can run from the psql command line. to start the psql shell:

sudo su postgres -c psql

In the psql shell, run these 3 lines:

These commands will create a database and user to interact with it.

Now, we may need to grant access to that user. Use this command to edit the pg_hba.conf, that’s what postgresql uses to verify access:

sudo nano /etc/postgresql/11/main/pg_hba.conf

Mke sure this line is present in the file:

host all all 127.0.0.1/32 md5

Once you’ve edited the file, restart the databse to apply the changes:

sudo systemctl restart postgresql

Setting up Mezzanine

Now that the databse is set up, we can move on to configuring Mezzanine. To start a Mezzanine project use the command:

(my_site) mezzanine-project my_site

cd mysite

In the my_site directory, you’ll find another directory called “my_site”. You’ll need to edit a file called settings.py:

nano mysite/settings.py

There are two things to set up in that file.

  • Database configuration, use the same user and passwords from the SQL user we created earlier:
  • Allowed hosts:

ALLOWED_HOSTS = ['my_site.com', 'www.my_site.com']

Once those are ready, save the settings.py file. 

The aptly named manage.py script is used to set up and manage your server. Now that Mezzanine has the database user properly configured, we can add the tables using the createdb command like so:

python manage.py createdb

Then, add an admin user to help manage your site:

python manage.py createsuperuser

Finally, build the assests, like javascript and css using:

python manage.py collectstatic

Deploying the application using uWSGI

For our web site to come up, you’ll need to configure a Python loader to run the code, and a web server to communticate with outside world. Let’s start with the Python loader. For this setup, we’ll use the uWSGI runner.

In your my_site/my_site directory, create a file called my_site.ini, using nano:

You can set up uWSGI to run at boot by creating a service file in /usr/lib/systmd/system/my_site.service:

Finally, run the command:

sudo systemctl enable my_site

And:

sudo systemctl start my_site

That will configure your python runner to start on boot, and start it right now.

NGINX configuration

One last task to round all of this out: set up the webserver. NGINX is a popular choice for python projects, because of its reverse proxy capabilities.

To configure it, just add this file into /etc/nginx/sites-enabled:

Then to apply this configuration, run the command:

sudo systemctl restart nginx

Related Articles