What am I missing? This is my first time trying to use Django. The server that is built into Django will serve the file locally just fine, but I can't get Apache to do the same. The following is what I'm doing from a brand new, clean, Linux 2 instance.
sudo yum update
sudo yum install -y python3
sudo yum install httpd-devel
sudo yum install -y mod_wsgi
cd /etc/httpd/modules (verify that mod_wsgi is there)
cd /var/www/
sudo mkdir myApp
sudo chown ec2-user myApp
cd myApp
sudo pip3 install virtualenv
virtualenv myprojectenv
source myprojectenv/bin/activate
sudo pip3 install django==2.1.1
django-admin startproject myApp
cd myApp
python manage.py migrate
python manage.py runserver
wget http://127.0.0.1:8000/ (works correctly as it should and I receive test page)
python manage.py startapp hello
cd myApp
vim settings.py
settings.py: edit this part to look like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'hello.apps.HelloConfig',
]
.
vim urls.py
urls.py: entire file looks like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('hello.urls')),
]
.
cd ..
cd hello
vim views.py
views.py: entire file looks like this
from django.shortcuts import render
# Create your views here.
# hello/views.py
from django.http import HttpResponse
def homePageView(request):
return HttpResponse('Hello, World!')
.
vim urls.py
hello/urls.py: entire file looks like this:
# hello/urls.py
from django.urls import path
from .views import homePageView
urlpatterns = [
path('', homePageView, name='home')
]
.
cd ..
python manage.py runserver
wget http://127.0.0.1:8000/ (works correctly as it should, now gets “Hello World!”)
Now for the Apache part:
sudo vim /etc/httpd/conf/httpd.conf
Paste the following to the bottom of httpd.conf:
WSGIScriptAlias / /var/www/myApp/myApp/myApp/wsgi.py
WSGIPythonHome /var/www/myApp/myprojectenv
WSGIPythonPath /var/www/myApp
<Directory /var/www/myApp/myApp/myApp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
.
sudo service httpd restart
wget http://127.0.0.1
Connecting to 127.0.0.1:80... connected. HTTP request sent, awaiting response...
and that is all it does until it times out. Connecting to the public IP address through a browser does the same thing; it connects and just sits there waiting for a response.
Apache error log (/var/log/httpd/error_log) says this:
Django ImportError: No module named site
A quick search suggests that this is because mod_wsgi is using a different version of python than my virtual environment. I'm using python3.7
cd /etc/httpd/modules
ldd mod_wsgi.so
outputs
linux-vdso.so.1 (0x00007ffd7dec3000)
libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x00007fe35815d000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe357f3f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fe357d3b000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007fe357b38000)
libm.so.6 => /lib64/libm.so.6 (0x00007fe3577f8000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe35744d000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe358755000)
Clearly that is a different version. I've uninstalled it, and installed it again while in the python3.7 virtual environment, but the result is the same. It still says "libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0".