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