How to Deploy Mezzanine CMS to Jelastic
In this post, we have a look at how to deploy the Django-based Mezzanine CMS to Jelastic Cloud. Read on to see how it's done!
Join the DZone community and get the full member experience.Join For Free
mezzanine cms (content management system) is a powerful and easy-to-use solution for content management and blogging which is built on top of django—python-powered, web-development framework. this bsd-licensed, open-source platform is free and easily customizable. the most required and widely-used cms functionality is provided by default, so it can cover the majority of common needs. at the same time, there exist a huge number of third-party extensions, widgets, modules, themes, etc. which can be used to broaden mezzanine possibilities.
both developers and content managers should be pleased with such awesome advantages of this platform as:
- wysiwyg editor with the drag-and-drop page ordering and visual content editing
- scheduled publishing
- huge amount of ready-to-use themes
- rich api
- out-of-the-box django internationalization, twitter bootstrap, disqus, akismet spam filter, twitter feed, and google analytics support, as well as embedded integration with social networks, search engines, seo functionality, and huge amounts of modules
so, today we’ll consider how such a great application can be easily hosted at jelastic paas&caas—the step-by-step instruction below will pass you through the mezzanine cms deployment process inside jelastic cloud .
create python environment
to start with, you need to create an environment with the appropriate application and db server. in our case, the apache python server is needed (with the python 2.7 engine version as recommended).
1. to create such, log in to your dashboard and press the new environment button.
2. switch to the python tab. here, with the appropriate application server being already chosen, you need to state the suitable python version. then, define the needed environment region (in case of using the multi-region cloud ) and adjust the domain name.
jelastic provides both
python 2 (2.7)
python 3 (3.3, 3.4, 3.5)
versions; herewith, 2.7 is the most suitable one for mezzanine cms deployment (though python 3 is supported by this app as well).
to find out the details on possible compatibility issues, please read the official documentation at mezzanine cms community.
- in case you are going to deploy a large and highly visited application, it makes sense to add a separate db node to your environment; otherwise, you can use the default sqlite database, located inside the application server container – both of these options will be described further down this guide.
finally, click create at the bottom right corner of the frame.
3. just in a minute your environment will appear at the dashboard.
now, you are ready to proceed to the actual mezzanine cms application deployment.
build and deploy mezzanine cms
1. in order to install mezzanine cms from the scratch, you need to access your application server via the jelastic ssh gateway first.
tip: if you haven’t performed such operations before, you need to:
however, in case you are not able to connect to your account via ssh (e.g. due to your hosting provider restrictions), you may proceed with deployment of the preliminary prepared mezzanine 4.1 archive, provided at the very end of this article.
2. after entering the apache python server by means of terminal, you will find yourself in the jelastic user home directory. now, to run the python web application, the isolated virtual environment needs to be created.
tip: a virtual environment is a tool for keeping the dependencies, that are required by different python projects, in separate places. in addition, it gives the ability to install the required packages without having the administrator privileges.
so, in order to create such an environment, simply run the following command via your console:
3. to be used, the newly created virtual environment needs to be activated by executing the next command:
4. now, the mezzanine cms installer can be downloaded with the help of the python package manager (pip) :
pip install mezzanine
wait for a couple of minutes before this operation is completed.
5. since we are going to install our application to the root context, the existing root folder with the default application should be preliminary removed:
rm -rf root
after that, you can run the installer:
the next required action is creation of the application database schema.
mezzanine cms, as all django-based applications, supports different sql dbs. you can choose the one according to your purposes and preferences, so within the instruction below we’ll reveal how to configure our app to work with:
- inbuilt sqlite database
- a separate sql server (either mysql-based or postgresql )
for the embedded sqlite db
being fast, simple and lightweight, sqlite represents a great solution for development and testing purposes.
tip: for production environments, it’s recommended to use either mysql-based or postgresql node, as they provide the sufficient level of scalability and security for real-life cases (the detailed instruction for these servers is provided right down the article)
1. the db connection settings can be seen within the local_settings.py file inside the ~/root/root folder. here, you’ll find the dedicated database configuration section with the parameters being stated for the sqlite db engine usage by default, so you can leave them unchanged in this case.
2. after you’ve reviewed the settings, execute the following line from inside the ~/root directory (i.e. one level above the local_settings.py script location) in order to create a new sqlite database:
python manage.py createdb --noinput
tip: at this step, the default administration account (with admin / default as credentials), site record and some demo pages are created. if you’d like to specify the data for these options manually, simply run the command above without the ‘–noinput ‘ option.
the db itself will be stored in ~/root/dev.db .
3. after the db is created, you can proceed to the configuring apache section of this article a little bit below.
for a separate sql server
at jelastic, mezzanine can be configured to work with any of the provided mysql-based servers (i.e. mysql itself, mariadb or perconadb – the settings are completely the same for all of them). also, you can use postgresql as an option.
here, we’ll consider the required configuration with the example of perconadb 5.6 , whilst providing the corresponding settings for postgres alongside if they differ.
1. so, if you prefer to use a separate db server – navigate back to jelastic dashboard, choose the change environment topology option for your mezzanine environment, pick up the desired node within the sql wizard section and click on apply .
- note: percona db is an optional node, since it is based on cartridge packaging model . in case you’d like to use it but can’t find this server in the sql section of your wizard, send a request to your hosting provider for its enabling.
2. after the node is successfully added to your environment, select open in browser next to it for the phpmyadmin page to be opened. log in with the credentials you’ve received via email during server installation:
3. once you’re inside, navigate to the users tab in order to create a separate account for interaction with mezzanine cms database. in the opened frame, click on add user and specify the appropriate username and password.
also, tick the create database with the same name and grant all privileges and grant all privileges on wildcard name (username\_%) options to get a db with the required privileges. then press the go button
for that, after being logged in, select the create database link. within the appeared input form, specify the name for your new db, leaving all the rest of settings unchanged, and click on the create button.
4. after the successful db creation, return to your console with the opened ssh connection to the apache python server and navigate to the local_settings.py file inside the ~/root/root folder. here, you need to specify the following configurations:
- engine – django.db.backends.mysql (or django.db.backends.postgresql_psycopg2 for postgresql database)
- name – type the name of the previously created database ( mezzanine in our case)
- user and password – enter the ones you’ve specified during the db creation (or state the default credentials if using postgresql)
- host – internal ip of the chosen db server
- tip: in order to find out the server’s ip address, expand the additional list next to it at the jelastic dashboard:
- port – specify the 3306 port number (or 5432nd one if working with postgresql)
as a result, the databases section should look similar to the following:
5. then, in order to make the server to work with mysql-based db, the appropriate connector needs to be installed via pip :
pip install pymysql
tip: to get python connector for postgresql server, the next command should be run:
path=$path:/usr/pgsql-9.4/bin/ pip install psycopg2
please also note that you may need to modify the pgsql-9.4 string according to the provided version of postgresql server at your jelastic platform.
6. once the required sql module is installed, you can proceed with db schema creation:
python manage.py createdb --noinput
after the db is created, let’s ensure the application is operable and apply some additional application server configurations.
running mezzanine application
so, the main steps of mezzanine cms application installation are completed now. in order to quickly make sure that everything was accomplished successfully, just stop the default apache python process:
sudo service cartridge stop
and then start the app itself (from inside the ~/root folder):
python manage.py runserver 0.0.0.0:8080
now, you can open your environment in browser via jelastic dashboard to access the application start page:
such kind of application running is suitable for development and testing purposes. however, for production environments with a big number of concurrent users, it’s more preferable to launch apache web server (which will be used for the static content serving) in a bundle with mod_wsgi module (required for hosting of python web applications with the wsgi specification support and for implementing interaction with python backend).
so, to handle the mezzanine application with mod_wsgi , do the following:
1. first of all, you need to generate a wsgi handler. for that, enter the
directory via console (upon ssh protocol) and create the
file there with such content:
import os,sys virtenv = os.path.expanduser('~') + '/virtenv/' virtualenv = os.path.join(virtenv, 'bin/activate_this.py') try: if sys.version.split(' ').split('.') == '3': exec(compile(open(virtualenv, "rb").read(), virtualenv, 'exec'), dict(__file__=virtualenv)) else: execfile(virtualenv, dict(__file__=virtualenv)) except ioerror: pass sys.path.append(os.path.expanduser('~')) sys.path.append(os.path.expanduser('~') + '/root/') sys.path.append(os.path.expanduser('~') + '/root/root/') os.environ['django_settings_module'] = 'root.root.settings' from django.core.wsgi import get_wsgi_application from mezzanine.utils.conf import real_project_name application = get_wsgi_application()
save the newly created file.
2. then, set the symlink, which will point to the file we’ve modified above, by executing the following line:
ln -sft ~/root/root/wsgi.py ~/root/application
3. also, as we are going to serve static content with the help of apache, the appropriate data needs to be collected beforehand (the command should be run under the ~/root directory):
python manage.py collectstatic
as a result, all of the static content for current app will be stored in the ~/root/static directory.
4. the only thing that left to be adjusted is to substitute the allowed_hosts setting value at the ~/root/root/settings.py config with your jelastic environment domain name (which can be seen within the dashboard):
after that, run the apache process by:
sudo service cartridge start
5. that’s all! now, you can return to the dashboard and press open in browser button next to your environment with mezzanine cms (similarly to the way you’ve done this while checking its operability). as a result, you’ll see the application’s welcome page.
here, you can login to admin panel using your credentials (i.e. admin/default in case of the –noinput option usage, or your custom ones otherwise)
once inside, you are able to proceed with modifying your site and filling it with the required content.
deploying pre-configured mezzanine cms archive
for the case you have a trial-type account and/or do not have the possibility to access your environment via ssh, the archive with pre-configured mezzanine cms application can be deployed directly via the jelastic dashboard. as an example, you can use our ready-to-go mezzanine 4.1 package.
note: in case of deploying your custom mezzanine distribution, please ensure it contains the following files in its root:
- requirements.txt file with the names of all the python modules the application requires. this file will be read by deployment script in order to automatically install the listed modules with the help of the pip manager.
- application file with the entry point script for running your application inside a virtual environment by means of apache mod_wsgi .
with our package, sqlite is used for serving data storing by default, so only app server is needed to be comprised within an environment. and the whole deployment procedure can be performed just in a few steps, described below:
1. upload the package with your mezzanine cms application to the jelastic dashboard via deployment manager .
2. press the deploy to button and choose the target environment.
3. once this operation is finished, select the open in browser button next to your environment.
4. that’s all! now you can enjoy working with your mezzanine cms application.
as you can see, it’s quite easy to deploy mezzanine cms (as well as any other django-based application) with jelastic python hosting. nevertheless, in case you face any issues with this instruction, feel free to appeal for our technical experts’ assistance at stackoverflow .
and don’t forget to keep an eye on new articles within our blog – here you can find the variety of instructions and solutions you can benefit on with your own account at any of jelastic cloud installations. so stay tuned!
Published at DZone with permission of Tetiana Markova, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.