1

I've started a project which I intend to set up on an Apache2 server running Ubuntu. I've created the skeleton of the Django project locally and pushed it to a repo on bitbucket. A friend who provided the server told me that Digital Ocean tutorials may be a good start, so I've been using this to set up wsgi. I deviated slightly from the wording and steps of the tutorial so I'll run through how I did it.

  1. I created a directory at the path ~/public_html/clupus.com and changed into it.

  2. I already had a previous skeleton so I cloned it into the current directory. The path now looked like ~/public_html/clupus.com/clupus where clupus is a directory containing the project files (manage.py etc.)

  3. I created a new virtual host file at /etc/apache2/sites-available/clupus.com which contained the following definition:

    <VirtualHost *:80>
        ServerName clupus.com
        ServerAlias www.clupus.com
        WSGIScriptAlias / /home/ubuntu/public_html/clupus.com/clupus.wsgi
    </VirtualHost>
    
  4. I then created the actual wsgi file at ~/public_html/clupus.com/clupus.wsgi which contained the following configuration:

    import os
    import sys
    sys.path.append('~/public_html/clupus.com')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'clupus.clupus.settings'
    import django.core.handlers.wsgi 
    application = django.core.handlers.wsgi.WSGIHandler()
    
  5. Finally I did sudo a2ensite clupus.com followed by sudo service apache2 reload. When I went to access the URL at which the server was located I was met with the default welcome page. Assuming I had to de-activate the default page I did sudo a2dissite 000-default followed by a reload which now, understandably, gives me a 500 error.

My question is what is the URL I use to access my Django project? I feel like I've set everything up correctly and I'm just not pointing to the right URL.

Also, in the line os.environ['DJANGO_SETTINGS_MODULE'] = 'clupus.clupus.settings' should it be clupus.clupus.settings or just clupus.settings given the hierarchy is ~/public_html/clupus.com/clupus/clupus/settings.py

1
  • 1
    Not related to your problem, but you shouldn't be putting your Django code in public_html. Commented Jan 14, 2014 at 12:55

2 Answers 2

1

According to directory list that you posted and your comments:

ubuntu@ip-10-137-27-87:~/public_html/clupus.com$ ls ~/public_html/clupus.com/ -la
total 16
drwxrwxr-x 3 ubuntu ubuntu 4096 Jan 14 11:13 .
drwxrwxr-x 3 ubuntu ubuntu 4096 Jan 14 10:38 ..
drwxr-xr-x 7 ubuntu ubuntu 4096 Jan 14 10:43 clupus
-rw-rw-r-- 1 ubuntu ubuntu  219 Jan 14 14:09 clupus.wsgi
ubuntu@ip-10-137-27-87:~/public_html/clupus.com$ 

you should change full path here (you can use os.path.expanduser to convert ~ (tilde) to home path):

#sys.path.append('~/public_html/clupus.com'
sys.path.append('/home/ubuntu/public_html/clupus.com/clupus')

To fix this ImportError: Could not import settings 'clupus.settings' check var DJANGO_SETTINGS_MODULE. Path 'clupus.settings' should work after changing sys.path (supposed that settings.py located in /home/ubuntu/public_html/clupus.com/clupus/clupus directory):

#os.environ['DJANGO_SETTINGS_MODULE'] = 'clupus.clupus.settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'clupus.settings'
Sign up to request clarification or add additional context in comments.

7 Comments

I've done that and reloaded Apache. Whenever I visit the IP it still gives me the internal server error. Should I be visiting a sub-directory of the IP?
ImportError: Could not import settings 'clupus.settings'
I think it's looking for a python model called com inside clupus instead of referencing it as a whole. I have never faced such a problem, but do try this: '"clupus.com".settings' (notice the " and ' difference)
I think adding ~/public_html/clupus.com/clupus to you python path will solve your problem.
@Nanor try change path: sys.path.append('/home/ubuntu/public_html/clupus.com/clupus')
|
0

Are you sure apache user have permission to ~/public_html/clupus.com ?

Could you do

ls ~/public_html -la
ls ~/public_html/clupus.com -la

2 Comments

sudo usermod -a -G www-data ubuntu
The problem has been fixed above. Thanks though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.