Reputation: 69
So I've managed to setup my django project on my server by following this tutorial. I am able to run it on port 8000 by doing
python manage.py runserver
But I now want to deploy it to the server's domain name or IP address without specifying a port.
After configuring 000-default.conf
as instructed on the tutorial I get a 500 Internal Server Error
error.log:
[Tue Mar 28 12:34:29.006570 2017] [wsgi:error] [pid 12773:tid 140065216325376] [remote 31.49.113.30:62072] mod_wsgi (pid=12773): Target WSGI script '/home/ubuntu/myproject/myproject/wsgi.py' cannot be loaded as Python module.
[Tue Mar 28 12:34:29.006623 2017] [wsgi:error] [pid 12773:tid 140065216325376] [remote 31.49.113.30:62072] mod_wsgi (pid=12773): Exception occurred processing WSGI script '/home/ubuntu/myproject/myproject/wsgi.py'.
[Tue Mar 28 12:34:29.006695 2017] [wsgi:error] [pid 12773:tid 140065216325376] [remote 31.49.113.30:62072] Traceback (most recent call last):
[Tue Mar 28 12:34:29.006714 2017] [wsgi:error] [pid 12773:tid 140065216325376] [remote 31.49.113.30:62072] File "/home/ubuntu/myproject/myproject/wsgi.py", line 12, in <module>
[Tue Mar 28 12:34:29.006718 2017] [wsgi:error] [pid 12773:tid 140065216325376] [remote 31.49.113.30:62072] from django.core.wsgi import get_wsgi_application
[Tue Mar 28 12:34:29.006733 2017] [wsgi:error] [pid 12773:tid 140065216325376] [remote 31.49.113.30:62072] ImportError: No module named 'django'
I'm new to Django and Ubuntu so I don't really understand the error, any help would be much appreciated, thanks
Upvotes: 0
Views: 71
Reputation: 983
After sometime of researching and learning new things, I was able to deploy it in production. Only thing is that my setup was based on RHEL7, MySQL, Python3.5. So here are the details, you may want to change it based on Ubuntu. The mod_wsgi part is very important.
yum check-update
yum groupinstall -y "Development tools"
----------------------------------------------------------------
Apache2.4
----------------------------------------------------------------
yum install -y httpd httpd-devel
systemctl start httpd.service
systemctl enable httpd.service
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
chgrp -R apache /var/www/html
find /var/www/html -type d -exec chmod g+rx {} +
find /var/www/html -type f -exec chmod g+r {} +
chown -R user /var/www/html/
find /var/www/html -type d -exec chmod u+rwx {} +
find /var/www/html -type f -exec chmod u+rw {} +
find /var/www/html -type d -exec chmod g+s {} +
----------------------------------------------------------------
MySQL
----------------------------------------------------------------
yum install -y mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation
----------------------------------------------------------------
----------------------------------------------------------------
Python3.5 along with lib and devel packages
----------------------------------------------------------------
yum install -y https://rhel7.iuscommunity.org/ius-release.rpm
yum install -y python35u python35u-libs python35u-devel python35u-pip
pip3.5 install virtualenv
----------------------------------------------------------------
mod-wsgi
----------------------------------------------------------------
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.14.tar.gz
tar -zxvf 4.5.14.tar.gz
cd mod_wsgi-4.5.14
./configure --with-python=/usr/bin/python3.5
make
make install
chmod 755 /usr/lib64/httpd/modules/mod_wsgi.so
----------------------------------------------------------------
portal.conf
----------------------------------------------------------------
vi /etc/httpd/conf.d/portal.conf
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName portal
ServerAlias portal.com
DocumentRoot /var/www/html/portal/src/
WSGIDaemonProcess portal python-path=/var/www/html/portal/src:/var/www/html/portal/venv/lib/python3.5/site-packages
WSGIApplicationGroup portal
WSGIScriptAlias / /var/www/html/portal/src/portal/wsgi.py process-group=portal
<Directory /var/www/html/portal/src>
Require all granted
</Directory>
<Directory /var/www/html/portal/src/portal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
systemctl restart httpd
Upvotes: 0
Reputation: 16733
Web server is not able to find existing django installation. Either you haven't installed it yet, or you have not configured your server to use virtual environment (in case you are using it).
ImportError: No module named 'django'
Upvotes: 1