Python on Infobox Jelastic Cloud Hosting: Launching Django CMS

Jelastic is a multi-language platform as a service. First Java support was added, then PHP and Ruby, but the developers did not stop there. Month after month, a new platform for Jelastic was developed - Python. This article will show you how to deploy Django CMS on Infobox Jelastic.


At the end of the article, information on how to get 300 rubles into the account for experiments with Infobox Jelastic .

Python FAQ in Jelastic


Jelastic supports the Apache web server for hosting Python applications. Implemented support for Apache + mod_wsgi.
You can use one of the 3 versions of Python:
  • 2.7
  • 3.3
  • 3.4

All versions are pre-installed in Python containers. The user can select the necessary version when creating the environment and change, if necessary, in the process.

Application Deployment

You can simply deploy a Python application:

1. using an archive or link





2. Through GIT / SVN,

GIT Infobox Jelastic

you can deploy only one Python application to the environment. It will be deployed to ROOT by default. Of course, you can use SSH to deploy the application.

When you deploy a package, its root should contain the following files:
  • requirements.txt with the names of all the Python modules needed by the application;
  • application - entry point script to run your application with Apache mod_wsgi


Package / Module Management

To successfully deploy and run a Python application, some additional modules or other packages may be required. Required software management is organized through pip, the popular Python package management system.

There are two ways to download and install Python modules:
  • Write a list of required modules in requirements.txt and put the file in the root of the package with the project. The deployment script will read the file and install the necessary modules using pip automatically;
  • Connect to your container via SSH and use the following commands:

pip install {package_name} - to install the necessary module;
pip uninstall {package_name} - to remove the installed module;
pip install –upgrade {package_name} - to upgrade a specific module to the latest version;
pip install -r requirements.txt - to install all modules from requirements.txt;
pip list - to view already installed modules.

Using additional commands and their parameters, you can specify preferred modules and versions, configure dependency resolution, show information about installed modules, or search for the necessary in the PyPI repository . For further familiarization with pip, we recommend a user manual .

Log monitoring

Jelastic creates the following log files available in Python WSGI:
  • access_log- {date}
  • error_log- {date}

You can view the logs by clicking on the Log button on the Apache container in your environment. Here you can follow all the steps that are taken with your Python environment.

Available frameworks

Jelastic currently supports the following Python frameworks:
  • Django
  • Flask

You can deploy various Python applications based on these frameworks. Below we show how to deploy DjangoCMS, and in the next article we will look at Quokka CMS (based on Flask).

DjangoCMS Deployment


Django is an open source framework for Python applications. It helps simplify the process of creating complex web applications, each of which may consist of a set of plug-ins. Let's look at the advantages of using Django in Infobox Jelastic and the Apache + mod_wsgi bundle using the example of hosting an application on Django CMS.

Environment creation

Create an environment for Python in Infobox Jelastic. Register an account at http://infobox.ru/hosting/cloud/ (the trial version is activated for free), log in to the control panel and click the "Create Environment" button.



Go to the Python tab. Apache will be selected automatically. Specify the minimum and maximum limits of available resources (Jelastic autoscaling works with Python, which allows you to pay for consumed resources after the fact without the need to reserve resources), enter the name of the environment (for example, "django") and click Create .



  • You can also choose one of the available versions of Python: 2.7, 3.3, 3.4. When choosing, consider Django compatibility information .
  • If you are deploying a large and visited application, we recommend adding a separate database container for your application. In other cases, you can use the built-in SQLite database, which will be placed inside the application container.

Within a minute, an environment will be created in your control panel.

Infobox jelastic django

Now we can directly begin to deploy DjangoCMS in one of the following ways:
  • building and deploying a new application;
  • Deploy an existing application.

Building and Deploying Django CMS

1. Generate and add a public SSH key to your control panel.

2. Establish an SSH connection with the Apache container of your environment.

3. After entering the container, make sure that you are in your user's home directory:
cd ~

4. You must create a virtual environment for your application inside the container. This will allow you to isolate the Python environment and install packages without having to gain administrator privileges.
virtualenv virtenv

5. Activate and switch to the created virtual environment.
source virtenv/bin/activate

6. Now, let's install the set of modules required by Django.
pip install django django-cms   djangocms_video  djangocms_teaser djangocms_picture djangocms_link  django-reversion djangocms_inherit  djangocms_googlemap djangocms_flash djangocms_file  djangocms_column djangocms-installer  djangocms_text_ckeditor djangocms_style

After a few minutes, the operation will end.
7. Erase the default preinstalled application and create a new one for Django CMS.
rm -rf ROOT; djangocms -p . ROOT

8. After executing the above command, you will be asked a few additional questions on setting up a new application.
Pay particular attention to setting up the database:
  • If you chose to use a separate database (MySQL container when creating the Jelastic environment), specify the connection string:
    mysql: // mysql- {env_name} .app.jelasticloud.com , where {env_name} is the name of the database container.
  • If you prefer to use the built-in SQLite database, enter the following line:
    sqlite: //localhost/ROOT/project.db

Complete the remaining steps of the installation wizard by entering the necessary parameters or leaving the default parameters (displayed at the end of the line in square brackets).

Infobox Jelastic Django hosting

9. When the application is configured, you will be asked for the username, password and email address for the CMS.

Infobox Jelastic Python Django CMS admin credentials
10. Enter the following command to create a new file and specify an entry point for the mod_wsgi module:
vim ROOT/application

Press “i” to enter edit mode and insert the following lines:
import os,sys
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
        execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
        pass
sys.path.append('/opt/repo')
sys.path.append('/opt/repo/ROOT')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ROOT.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Save the changes and close Vim by pressing Esc and writing ": wq".

12. Enter the command:
vim ROOT/settings.py

In the file that opens, find and replace the line:
STATICFILES_DIRS = (
        os.path.join(BASE_DIR, ‘ROOT’, ‘static’),
)

the following content:
STATICFILES_DIRS = (
        os.path.join(BASE_DIR, ‘ROOT’, ‘static_local’),
)

Save the changes and close Vim.



Create a new subdirectory for static content:
mkdir ROOT/static_local

and finally start resource synchronization:
./manage.py collectstatic

Enter “yes” if the system asks for confirmation.

It's all! Now you can click “Open in Browser” and enjoy Django CMS.



You will see a welcome screen.



To access the Django CMS admin panel, add / admin at the end of the environment URL. For access, use the superuser credentials that you entered during the installation of Django CMS.



Deploying an Existing Django Application

If you built and packaged the Django application in advance, the deployment process can be completed in just a few steps, as shown below.

Do not forget about the need for requirements.txt and application files in the package. An example is in the previous section.

1. Download the package with the Django application in the Distribution Manager.



2. Click "Deploy to ..." and select the desired environment.



3. Wait a minute for the deployment to complete and click Open in Browser.



It's all! Enjoy working with the application on Django.


Conclusion


We are very happy to introduce you to Python support in Infobox Jelastic with the flexibility to scale applications and Jelastic automation. We tried to simplify the development and launch of Python applications on the Infobox Jelastic platform without Vendor – lock on fast and reliable equipment.

Try it now and get 300 rubles to your Infobox Jelastic account. Register and, at the end of the trial, click the "Switch to paid version" button. Fill in the information about yourself. Send your username to us and we will credit you a bonus (from articles a bonus can be received 1 time per 1 account).

Successful use of Infobox Jelastic !

Also popular now: