How to deploy a Django site on a shared server of a host provider

Source: Internet
Author: User
Tags touch command
This article describes how to deploy a Django site on a shared server of a host provider. Django is the most popular Python framework, for more information, see service providers of shared hosts. They are not allowed to run your own service processes or modify httpd. conf file. However, it is still possible to run Django through sub-processes generated by the Web server.

Record

If you want to use the sub-process of the server, you do not have to start the FastCGI server on your own. Apache automatically generates some sub-processes. The number of sub-processes generated varies according to requirements and configurations.

Add the following content to the. htaccess file under your Web root directory:

AddHandler fastcgi-script .fcgiRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]

Next, create a script to tell Apache how to run your FastCGI program. Create a mysite. fcgi file and put it in your Web directory to open executable permissions.

#!/usr/bin/pythonimport sys, os# Add a custom Python path.sys.path.insert(0, "/home/user/python")# Switch to the directory of your project. (Optional.)# os.chdir("/home/user/myproject")# Set the DJANGO_SETTINGS_MODULE environment variable.os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"from django.core.servers.fastcgi import runfastcgirunfastcgi(method="threaded", daemonize="false")

Restart the new process server

If you change any python code on the site, you need to inform FastCGI. However, you do not need to restart Apache. Instead, you only need to re-upload mysite. fcgi or edit and modify the file so that the modification time changes. It will automatically restart the Django application. You can re-upload mysite. fcgi or edit the file to change the timestamp of the file. When the Apache server finds that the document has been updated, it will restart your Django application for you.

If you have the executable permission for the Unix system command line, you only need to simply use the touch command:

touch mysite.fcgi
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.