Ways to deploy a Django site on a host's shared server

Source: Internet
Author: User
Tags touch command shared hosting
Many shared hosting service providers do not allow you to run your own service processes or modify the httpd.conf file. Nonetheless, it is still possible to run Django through a child process generated by the Web server.

Recording

If you want to use the server sub-process, you do not need to start the fastcgi server yourself. Apache will automatically generate a number of sub-processes, and the resulting quantity will vary according to requirements and configuration.

Under your Web root directory, add the following to the. htaccess file:

AddHandler fastcgi-script. Fcgirewriteengine onrewritecond%{request_filename}!-frewriterule ^ (. *) $ mysite.fcgi/$1 [ QSA,L]

Next, create a script that tells 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 newly generated process server

If you change any of the Python code on the site, you need to tell fastcgi. However, this does not need to restart Apache, but only need to re-upload mysite.fcgi or edit the file, so that the change time has changed, it will automatically help you restart the Django application. You can re-upload the mysite.fcgi or edit the file to change the timestamp of the file. When the Apache server discovers that the document is updated, it will restart your Django app for you.

If you have executable permissions on the UNIX system command line, simply use the Touch command:

Touch mysite.fcgi
  • 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.