0

I have tested my blog website using:

 python manage.py runserver

Everything is correct. Now I want to deploy my blog site on apache. But I cannot configure apache with django correctly. Basicly, my blog structure is the following:

├── blog
│   ├── __init__.py
│   ├── models.py
│   ├── static
│   │   └── blog
│   │       ├── css
│   │       ├── images
│   │       └── js
│   ├── templates
│   │   └── blog
│   │       ├── base.html
│   │       ├── index.html
│   ├── templatetags
│   │   ├── custom_filter.py
│   │   ├── __init__.py
│   ├── tests.py
│   ├── urls.py
│   ├── views.py
├── blogC
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
├── manage.py
└── usermanage
    ├── admin.py
    ├── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py

I have installed the apache, mod_wsgi and database. My question is the django middleware will look for static files automatically. Should I add the path to the static files in the httpd.conf? How should I write the configure file? I follow the instruction on django official website. But it turned out the apache service cannot restart, so I must configure it wrong.

Update the last several lines of the error.log:

[Tue Feb 10 10:02:08.796042 2015] [core:error] [pid 6610] (13)Permission denied: [client 113.240.234.213:14433] AH00035: access to /phppath/php5 denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 10:02:11.700382 2015] [core:error] [pid 5220] (13)Permission denied: [client 113.240.234.213:15162] AH00035: access to /local-bin/php denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 10:02:12.407788 2015] [core:error] [pid 5257] (13)Permission denied: [client 113.240.234.213:15339] AH00035: access to /local-bin/php5 denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 10:02:13.118587 2015] [core:error] [pid 5221] (13)Permission denied: [client 113.240.234.213:15501] AH00035: access to / denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 11:14:12.291824 2015] [core:error] [pid 5218] (13)Permission denied: [client 205.145.18.5:47369] AH00035: access to / denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 11:14:14.319037 2015] [core:error] [pid 6308] (13)Permission denied: [client 205.145.18.5:57326] AH00035: access to / denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
9
  • I used "apache:www" as user/group in the httpd.conf file. And I changed the owner of contents in the static folder to be apache. But I got the permission denied when using http access from browser. Commented Feb 10, 2015 at 0:23
  • I searched the log file. It said: "search permissions are missing on a component of the path". Since I use apache:www in configure file. But the django folder is in my ec2-user account. So I replaced apache:www as ec2-user:ec2-user. But I still get the same error. Commented Feb 10, 2015 at 5:17
  • Which OS are you using. Apache user and group usually www-data:www-data. Moreover, you normally don't want to change a user, which apache runs as. Any particular reason why you setting a user and group manually? Commented Feb 11, 2015 at 0:16
  • I used the redhat OS. The default user and group are apache:apache in this case. And I got the error something like that "You don't have permission to /home/ec2-user for some search path". That's the reason I changed the the user:group, since all the django codes are located in /home/ec2-user folder. Commented Feb 11, 2015 at 0:20
  • Gotcha. You still don't need to change the user, just make sure you project code is readable by all: chmod -R a+rX /home/ec2-user/path/to/project Commented Feb 11, 2015 at 1:25

1 Answer 1

1

Here is a possible apache config:

WSGIDaemonProcess blog processes=2 threads=15
WSGIScriptAlias / /path/to/project/blog/blogC/wsgi.py

<Directory /path/to/project/>
            WSGIProcessGroup blog
            WSGIApplicationGroup %{GLOBAL}
            Options All
            AllowOverride All
            Require all granted
</Directory>

Alias /media/ /path/to/project/media/
<Directory /path/to/project/media/>
            Options FollowSymLinks MultiViews
            Order deny,allow
            Allow from all
</Directory>

Alias /static/ /path/to/project/static/
<Directory /path/to/project/static/>
            Options FollowSymLinks MultiViews
            Order allow,deny
            Allow from all
</Directory>

Also create a static and media folders in your projects root folder and set them in settings.py:

import os

BASE_PATH = os.path.join(os.path.dirname(__file__), '..')
MEDIA_ROOT = os.path.join(BASE_PATH, 'media/')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_PATH, 'static/')
STATIC_URL = '/static/'

Then collect all static files into provided directory (this will link static files from all apps into one location):

./manage.py collectstatic --link

Also make sure apache has permissions to write into media folder, so files can be uploaded:

sudo chown -R www-data:www-data /path/to/project/media

Now you gotta make sure your wsgi.py is configured correctly:

import os, sys

## apache/mod_wsgi cannot find the path without it!
path = os.path.split(os.path.dirname(__file__))[0]
if path not in sys.path:
    sys.path.append(path)

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

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

That should be it.

Sign up to request clarification or add additional context in comments.

2 Comments

I found the reason that why httpd service didn't restart. I removed the <VirtualHost> tag for above configuration(I don't know why at this moment). But I have a new problem when I try to browse the website. I got the messege: "you don't have permission to access / on this server"
Can you post the actual error trace back from apache log file /var/log/apache/...error.log

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.