Friday, June 29, 2018

django windows apache tell if apache is working


Hi,

I'm new to this group, and also new to Python, and Django.  Seems like lots of good info for django on this group.

Sorry for long, detailed descriptions, below, but I am stuck trying to verify wamp, apache and django are working as a production server on a Windows 7, 32-bit machine.

I am hung on last mile part (way below), or how to see something in the browser using apache, not the dev runserver.  The dev server seems to work fine at this point showing default django startup page.

I'm not sure how to proceed with verifying apache is working as a production server.  If all is working, should apache show the same Python default start page as the dev server?  Or what simple web pages should I implement to verify the apache connection is actually working on the server?

Wamp is also working fine with it's own www directory and local webpages etc. using apache.


Wampserver 3.0.6 32bit, with apache2.4.23
---------------
PYTHON AND APACHE:

Python 3.6.5 32bit, with Django 2.0.6

Tried following Eastwood description for Django setup for Wamp
https://ericeastwood.com/blog/3/django-setup-for-wamp
---------------
MOD_WSGI:

Could not pip install mod_wsgi, and needed to download VisualStudio build tools and upgrade framework to 4.7.1.

Downloaded mod_wsgi-4.5.24+ap24vc14-cp36-cp36m-win32.whl
https://www.lfd.uci.edu/~gohlke/pythonlibs/
to work with apache 2.4.23, VC++14, and python3.6

then did >> pip install C:\Users\Administrator\Downloads\mod_wsgi-4.5.24+ap24vc14-cp36-cp36m-win32.whl.  Did not get mod_wsgi.so in apache modules folder, but did get a .pyd in: c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd

Could then run mod_wsgi-express.

From cmd prompt in apache bin dir used >httpd -t -D DUMP_MODULES to show wsgi_module (shared) is present.
---------------
VIRTUALENV:

Per Eastwood description (above), inside c:/wamp created a new directory www-src next to www which is where our other wamp sites are located. Inside c:\wamp\www-src ran >virtualenv django_project, then django_project\Scripts\activate.  See (django_project) as prefix to cmd prompt. With virtual environment active did >pip install django.  Then (django_project_ c:\wamp\www-src > django-admin.py startproject django_project .  to setup up project in current or www-src directory.

c:\wamp\www-src\django_project
c:\wamp\www-src\static
c:\wamp\www-src\db.sqlite3
c:\wamp\www-src\manage.py

and in c:\wamp\www-src\django_project have settings.py, urls.py, and wsgi.py, etc.
---------------
SETTINGS.PY

in settings.py change STATIC_URL to:

STATIC_ROOT = 'C:/wamp/www-src/static'
STATIC_URL = 'http://XXXmyipXXX/static/'


also added localhost, and my local IP to ALLOWED_HOSTS in settings.py
---------------
MIGRATIONS:

then from c:\wamp\www-src run
(django_project) c:\wamp\www-src >manage.py makemigrations
then
(django_project) c:\wamp\www-src >manage.py migrate

also ran >(django_project) c:\wamp\www-src >manage.py collectstatic
although static dir is empty at this point.
---------------
DEVELOPMENT SERVER:

(django_project) c:\wamp\www-src >manage.py runserver 0.0.0.0:8000

From the browser > http://localhost:8000 this initially caused windows firewall error to appear but an exception was added to allow it to continue.

Can see python default page, and also localhost:8000\admin too on Dev server.  Dev server can be seen by other machines on the network too.
----------------
CONFIGURE APACHE:
for production server using wamp instead of dev server.

using mod_wsgi-express settings in httpd.conf.
Apache httpd.conf is in:
C:\wamp\bin\apache\apache2.4.23\conf\httpd.conf

Apache httpd-vhosts.conf is in:
C:\wamp\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf

added to httpd.conf:
LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll"
LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"

WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"
WSGIScriptAlias /django-project "C:/wamp/www-src/django_project/wsgi.py:C:/wamp/www-src/django_project/wsgi_app.py"
WSGIPythonPath "C:/wamp/www-src/django_project/:C:/wamp/www-src/django_project/Lib/site-packages"

<Directory "C:/wamp/www-src/django_project/">
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files>
    <Files wsgi_app.py>
        Order deny,allow
        Require all granted
    </Files>
</Directory>


added to httpd-vhosts.conf:
<VirtualHost *:80>
Alias /static c:/wamp/www-src/static
<Directory c:/wamp/www-src/static>
        Require all granted
    </Directory>
</VirtualHost>

...restarted apache
----------------------------

CONFUSED FROM HERE...or last mile to verify production server can run django from virtual environment.

If try localhost:8000 in browser see ERR_CONNECTION_REFUSED.
If try localhost/wsgi and have wsgi_app.py in django_project, see requested URL not found.

wsgi_app.py

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World from django_project!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

--
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+unsubscribe@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/99fc6ee8-b5b3-4da0-b11d-e5d34eff6076%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment