简体   繁体   中英

Unabled to deploy django + apache on aws Ubuntu server

I am trying to deploy a Django Application using Apache on an Ubuntu Server, I am having a weird error (500 internal error server error) when using port:80.

I made some test using port:8000 running the command:

python3 manage.py runserver 0.0.0.0:8000

And the application is working without any problem there, but when I try to access the application using port 80 it does work.

My apache config file looks like this:

<VirtualHost *:80>


Alias /static /home/ubuntu/gh_system/static
<Directory /home/ubuntu/gh_system/static>
    Require all granted
</Directory>

<Directory /home/ubuntu/gh_system/HRSYSTEM>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess HRSYSTEM python-home=/home/ubuntu/gh_system/env python-path=/home/ubuntu/gh_system>
WSGIProcessGroup HRSYSTEM
WSGIScriptAlias / /home/ubuntu/gh_system/HRSYSTEM/wsgi.py

I reviewed the apached2 errors logs, and I am getting a: No module named 'django', my wsgi files is:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "HRSYSTEM.settings")

application = get_wsgi_application()

After some research, testing and reviewing the apache logs with:

sudo tail -100 /var/log/apache2/error.log

I found that the problem was related to this line:

WSGIDaemonProcess HRSYSTEM ***python-home=/home/ubuntu/gh_system/env*** python-path=/home/ubuntu/gh_system>

Basically, apache was trying to read the packages inside of the virtual environment but I did install them using the command:

sudo pip3 install -r requirements.txt

Apparently, using the "sudo" command was installing the packages outside the virtual environment, it is so weird; but without "sudo" the console logs the error permission denied, so I give chmod 700 permission to the virtual environment and install again the packages without the "sudo", and then it works!

Some of the things I learned about the errors:

Problem: Not module 'encodings' --> this problem occurs when apache can not access your packages, usually for a bad path specified in the config file.

Problem: Not module 'x module, could be django' means you need to install the package using pip3.

Hope it helps someone, and just to point out, something I have been learning lately: is, when you spend too much time trying to solve a problem, and there is not much information about it on inte.net, it means that something really; really basic is failing in your project, for example, installing the packages outside the virtual environment without even realizing it. just like I did.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM