How to configure the Index.fcgi path?

Viewed 100

I'm finishing with setting up my Django project on my hosting using ssh. i am following an article to be able to install it correctly. Some of the steps I had to follow are as follows:

Create the . htaccess file with the settings of the FCGI Handler and redirection to the index.fcgi file that will be created:

AddHandler fcgid-script .fcgi

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.fcgi/$1 [QSA,L]

and Create the index.fcgi file in the root of your application with the following content:

#!/home/CONTA/.virtualenv/bin/python
 
import os, sys
 
from flup.server.fcgi import WSGIServer

from django.core.wsgi import get_wsgi_application
 
sys.path.insert(0, "/home/CUENTA/mydjango")

os.environ['DJANGO_SETTINGS_MODULE'] = "mydjango.settings"
 
WSGIServer(get_wsgi_application()).run()

Already having those two files in the public html and opting the permissions to the index.fcgi using chmod 0755 At the time of me see if it is running using the following command ./index.fcgi, tells me that there is no file or directory.

Which leads me to assume that I need to set a path within the index.fcgi or . htaccess but I do not know what I need to change since in the article only comes that. Thank you

1 Answers

Step 1: Set up an .htaccess file in the folder of your project with the following entries:

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

Step 2: Set up an index.fcgi file in the folder of your project using the following code (it will serve as an entry point for all requests to the CMS). Don’t forget to replace “mydjangocms” with the name of your project:

#!/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)
# Set the DJANGO_SETTINGS_MODULE environment variable.
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 3: You’ll need to make the index.fcgi file executable using this command:

chmod +x index.fcgi
Related