I am using django and apache in a debian 8 and 9 server and everything is
working fine.

Firstly, don't use /var/www/html for python files.

In my server, we have a ordinary user that host python files in his home
dir.

I will try enumerate some steps used in one of my projects:
 - with your ordinary user, create your virtualenv
 - put your project in a folder  (sub folder in home of that user)
 - install and secure mysql
 - configure your settings (db settings, settings.py, create database if
needed)
 - test your db connection and make migrations, load fixtures and others.
 - install apache2 (in debian libapache2-mod-wsgi-py3 was required)
 - configure apache (for me just a single file
/etc/apache2/sites-available/your-site-name.conf was sufficient)
 - adjust directory permissions if needed (/var/www or others)
 - restart apache and all is working..

You can read this link to see more info:
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/
Hope it helps you.


2017-08-03 2:29 GMT-03:00 surajit mishra <surajitmis...@gmail.com>:

> I have developed a project (named pubnet) in django and is trying deploy
> it on production server(currently my ubuntu 14.04 machine for user
> testing). The project did work on built-in django server during development
> but on deploying, it fails to work. All it displays is the apache
> index.html page on localhost and not the django welcome page.
>
> Here are the steps that I have performed:
> *INSTALLATIONS:*
>
>    - installed apache2
>    - installed
>    ​lib​
>    apache2-mod-wsgi
>    - installed mysql-server
>    - created a database named pubnet
>    - created a django project named pubnet inside /var/www/html/
>
>
> *FILES CREATED/ALTERED:*
>
>    - *vi /etc/apache2/sites-available/pubnet.conf*
>
>  <VirtualHost *:80>
>
> ServerName pubnet
> ServerAlias pubnet.com
> ServerAdmin root
>
> DocumentRoot /var/www/html/pubnet
>
> Alias /media/ /var/www/html/pubnet/media/
> Alias /static/ /var/www/html/pubnet/static/
>
> <Directory /var/www/html/pubnet>
>     require all granted
> </Directory>
>
> WSGIDaemonProcess pubnet.com processes=2 threads=15 display-name=%{GROUP}
> WSGIProcessGroup pubnet.com
>
> WSGIScriptAlias / /var/www/html/pubnet/pubnet/pubnet.wsgi
>
> <Directory /var/www/html/pubnet/pubnet>
>    require all granted
> </Directory>
>
> ErrorLog /var/www/logs/error.log
> CustomLog /var/www/logs/custom.log combined
>
> </VirtualHost>
>
>    - *vi /var/www/html/pubnet/pubnet/pubnet.wsgi*
>
> import os
> import sys
> sys.path = ['/var/www/html/pubnet'] + sys.path
> os.environ['DJANGO_SETTINGS_MODULE'] = 'pubnet.settings'
>
> from django.core.wsgi import get_wsgi_application
> application = get_wsgi_application()
>
>    - *vi /var/www/html/pubnet/pubnet/wsgi.py:*
>
> import os
> import sys
> import django.core.handlers.wsgi
>
> # Calculate the path based on the location of the WSGI script.
> apache_configuration= os.path.dirname(__file__)
> project = os.path.dirname(apache_configuration)
> workspace = os.path.dirname(project)
> sys.path.append(workspace)
> sys.path.append(project)
>
> # Add the path to 3rd party django application and to django itself.
> sys.path.append('/var/www/html/pubnet')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'pubnet.apache.override'
>
> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pubnet.settings")
> from django.core.wsgi import get_wsgi_application
> application = get_wsgi_application()
>
>    - *vi /etc/hosts:*
>
> *127.0.0.1       localhost*
> *192.168.13.80   pubnet.com <http://pubnet.com>*
>
>    - *sudo a2ensite pubnet*
>    - *sudo service apache2 reload*
>    - *sudo service apache2 restart*
>
>
>    - *settings.py:*
>
> ALLOWED_HOSTS = ['localhost', '127.0.0.1', '127.0.1.1', '192.168.13.80', '
> pubnet.com']
>
> DATABASES = {
>     'default': {
>         'ENGINE': 'django.db.backends.mysql',
>         'NAME': 'pubnet',
>         'USER': 'root',
>         'PASSWORD': 'PASSWORD',
>         'HOST': '127.0.0.1',   # Or an IP Address that your DB is hosted on
>         'PORT': '3306',
>     }
> }
>
> *​NOTE: *While working on it last Saturday, it started working and I was
> also able to display the django admin page on the browser. However, very
> strangely on Monday it failed to work. Since then I have tried almost all
> links and the suggestions in google, installed, uninstalled everything but
> failed to make it work.
>
> Any help would be highly appreciated.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5d36aaf5-01de-402e-9a1a-02fd6c61bdbf%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5d36aaf5-01de-402e-9a1a-02fd6c61bdbf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACTnJ031zLenHPjwwiU1EKtryW6ffaejNJhsVyG6Cr-_E%2BM7iQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to