The Control Panel now features a recently introduced Python Manager

November 25, 2016
In response to input from web developers, we have incorporated an additional feature into the Advanced segment of the Hepsia Control Panel – the Python Manager.

This newly introduced Python Manager enables users to modify the existing Python version and activate Python-compatible applications for their projects. Positioned adjacent to PHP Settings, it provides effortless access to a range of Python management choices with just a single click.

What Does Python Entail?

Python stands as a highly significant language for application development, boasting an extensive history.

Its standard library encompasses support for numerous Internet protocols, encompassing JSON, FTP, IMAP, HTML, and XML.

Python-based software assumes various forms:

For web development, this includes:

  • Frameworks like Django and Pyramid;
  • Micro-frameworks such as Flask and Bottle;
  • Advanced content management systems like Plone and django CMS;
  • Asynchronous networking libraries like Tornado, particularly suited for applications requiring persistent connections like long polling and WebSockets;
  • Full-stack frameworks (e.g., web2py) designed for rapid creation of database-driven web-based applications.

For scientific and numerical computing:

  • Open-source packages like SciPy, Matplotlib, and NumPy, prevalent in mathematics, science, and engineering;
  • Pandas, a BSD-licensed library for robust data analysis and modeling;
  • iPython, a potent command shell that simplifies editing and documenting work sessions while supporting interactive data visualization and parallel computing;
  • Software Carpentry Course, an educational resource teaching scientific computing fundamentals and offering open-access learning materials.

For software development:

  • Buildbot and Apache Gump, used for automating software build, testing, and release procedures;
  • Roundup and Trac, tools designed for issue tracking and project management.

For system administration:

  • Ansible, a user-friendly IT automation engine streamlining configuration management, application deployment, and cloud provisioning;
  • Salt, a robust open-source platform facilitating IT automation and orchestration;
  • OpenStack, a high-performance platform encompassing computing, storage, and networking capabilities.

Python proves to be beginner-friendly, fostering ease of learning and application, whether one is new to programming or an adept developer.

Supported by a thriving community, Python enjoys the organization of conferences and workshops, collective code development projects, comprehensive documentation tailored for newcomers, and actively maintained mailing lists to keep users well-informed.

How to Utilize the Python Manager?

Within the Control Panel's Python Manager segment, you can configure the Python version for your account. You have the option to select from Python 2.7, Python 3.1, and the most recent release – Python 3.5.

How to Deploy a Python-Based CMS on Our Platform (Tutorial)?

To provide you with a more comprehensive understanding of how Python-based applications function on our servers, we will guide you through the process of installing the Mezzanine CMS, which is powered by the Django framework. This installation will be carried out via SSH.

Step 1: Generate a virtual environment (venv) within the root directory of your account. In our context: /usr/local/python-3.5/bin/virtualenv /home/venv/

Step 2: Access the freshly established virtual environment with this command: source /home/venv/bin/activate

Step 3: Navigate to the "www" folder of your hosting account: cd /home/www/

Step 4: Install the Mezzanine CMS binaries along with the corresponding modules fastcgi support and flup6:

  • pip install git+https://github.com/NetAngels/django-fastcgi
  • pip install flup6
  • pip install mezzanine

NOTE: Ensure the "Outgoing Connections" option is disabled to prevent module installation failure.

Step 5: Establish the Mezzanine project within a chosen custom directory, in our case "mydjangocms": mezzanine-project mydjangocms

Step 6: Set up a domain or subdomain for the newly installed CMS. Deactivate the Jail host option to ensure proper module functionality.

Point your newly created domain or subdomain to the project path, in our example: "/www/mydjangocms".

Step 7: Access the recently created Mezzanine CMS folder: cd mydjangocms

Step 8: Set up a database for your CMS. In our scenario, we'll employ the sqlite3 database for simplicity (alternatively, you can configure a MySQL/PostgreSQL database by adjusting the Python setup file): python manage.py createdb

Follow the prompts to provide domain and user information. These credentials are for the CMS system, not the database. Optionally, you can choose to include demo content.

Step 9: Establish an .htaccess file in your project folder with the following entries:

  • RewriteEngine On
  • RewriteCond %{REQUEST_FILENAME} !-f
  • RewriteCond %{REQUEST_FILENAME} !-d
  • RewriteRule ^(.*)$ /index.fcgi/$1 [QSA,L]

Step 10: Create an index.fcgi file in your project folder with the following code (this will serve as the entry point for all CMS requests). Ensure to replace "mydjangocms" with your project name:

  • #!/home/venv/bin/python3.5
  • # -*- coding: utf-8 -*-
  • import os
  • import sys
  • activate_this = '/home/venv/bin/activate_this.py'
  • exec(open(activate_this).read(), dict(__file__=activate_this))
  • cms_path = '/home/www/mydjangocms/'
  • sys.path.insert(0, cms_path)
  • os.chdir(cms_path)
  • os.environ['DJANGO_SETTINGS_MODULE'] = "mydjangocms.settings"
  • from django_fastcgi.servers.fastcgi import runfastcgi
  • from django.core.servers.basehttp import get_internal_wsgi_application
  • wsgi_application = get_internal_wsgi_application()
  • runfastcgi(wsgi_application, method="prefork", daemonize="false", minspare=1, maxspare=1, maxchildren=1)

Step 11: Make the index.fcgi file executable: chmod +x index.fcgi

Step 12: Edit the settings file within "mydjangocms/settings.py" and replace: ALLOWED_HOSTS = []

With your actual host name: ALLOWED_HOSTS = ['mydjangocms.my-best-domain.net']

Step 13: Collect static files with this command: python manage.py collectstatic

Now, your site should be operational. In our example, the Mezzanine CMS can be accessed at: http://mydjangocms.my-best-domain.net/

You can now log into the Mezzanine CMS Admin Panel using the credentials established in step 8 and start creating content, such as a new blog.