Jelastic is a multilingual platform as a service. Java support was added first, then PHP and Ruby, but the developers didn’t stop there. Month after month, the new for Jelastic platform was being worn out - Python. This article will explain how to deploy Django CMS on Infobox Jelastic.
At the end of the article information on how to get 300 rubles to the account for experiments with
Infobox Jelastic .
Python FAQ in Jelastic
Jelastic supports Apache web server for hosting Python applications. Implemented Apache + mod_wsgi support.
You can use one of the 3 versions of Python:
All versions are pre-installed in Python containers. The user can select the desired version when creating the environment and change, if necessary, in the process.
Deploying Applications
You can simply deploy a Python application:
')
1.
using an archive or link
2.
Through GIT / SVN
You can only deploy one Python application per environment. It will be deployed to the default ROOT. 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 required by the application;
- application - entry point script for launching your application with Apache mod_wsgi
Package / Module Management
To successfully deploy and run a Python application, you may need some additional modules or other packages. The management of the required software is organized through pip, a 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 with pip automatically;
- Connect to your container via SSH and use the following commands:
pip install {package_name} - to install the required 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 the preferred modules and versions, configure dependency resolution, show information about installed modules, or search for the
PyPI required in the repository. For further acquaintance with pip we recommend
the user's guide .
Log monitoring
Jelastic creates the following log files available in Python WSGI:
- access_log- {date}
- error_log- {date}
You can view logs by clicking the Log button on an Apache container in your environment. Here you can follow all the actions performed with your Python environment.
Available frameworks
Currently Jelastic supports the following Python frameworks:
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).
Deploying DjangoCMS
Django is an open source framework for Python applications. It helps simplify the process of creating complex web applications, each of which can consist of a set of plug-ins. Let's look at the advantages of using Django in Infobox Jelastic and bundles of Apache + mod_wsgi on the example of hosting an application on Django CMS.
Creating the environment
Let's create environment for Python in Infobox Jelastic. Register an account at
http://infobox.ru/hosting/cloud/ (a trial version is activated for free), login 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, allowing you to pay for consumed resources after the fact without the need to reserve resources), enter the environment name (for example, “django”) and click
Create .
- You can also choose one of the provided versions of Python: 2.7, 3.3, 3.4. When choosing, consider the Django compatibility information .
- If you are deploying a large and visited application, we recommend adding a separate container with a database for your application. In other cases, you can use the embedded SQLite database, which will be located inside the application container.
Within minutes, an environment will be created in your control panel.
Now we can proceed directly to deploying DjangoCMS in one of the following ways:
- building and deploying a new application;
- Deploy an existing application.
Build and Deploy 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 logging into 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 the need for 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
In a few minutes the operation will complete.
7. Erase the pre-installed application by default 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 about setting up a new application.
Pay particular attention to database configuration:
- 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 embedded SQLite database, enter the following line:
sqlite: //localhost/ROOT/project.db
Complete the remaining steps of the installation wizard by entering the required parameters or leaving the default parameters (displayed at the end of the line in square brackets).
9. When the application is configured, you will be asked for your username, password and email address for the CMS.
10. Enter the following command to create a new file and specify the entry point for the mod_wsgi module:
vim ROOT/application
Press "i" to switch to 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'), )
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 to the end of the environment URL. For access, use the root credentials you entered when installing Django CMS.
Deploy an existing Django application
If you have pre-built and packaged a Django application, the deployment procedure 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 in the previous section.
1. Download the package with the Django application to 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 Django app.
Conclusion
We are very happy to present you Python support in Infobox Jelastic with the possibility of flexible scaling of applications and Jelastic automation. We have tried to simplify the development and launch of Python applications on the Infobox Jelastic platform without Vendor – lock on fast and reliable equipment.
Try now and get 300 rubles to Infobox Jelastic account.
Register and at the end of the trial, click "Go to the paid version." Fill out information about yourself.
Send your login to us and we will give you a bonus (from bonus articles you can get 1 time for 1 account).
Successful use of
Infobox Jelastic !