0

I have configured apache2 to run my django application on ubuntu server but I'm facing issue while uploading images at my desired directory, it goes into /var/www/ directory.

I have edited '000-default.conf' file in apache2 with the directory I want the webserver to take as root directory for my application as bellow.

DocumentRoot /home/ubuntu/project/

<Directory /home/ubuntu/project/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

and /etc/apache2/apache2.conf

<Directory /home/ubuntu/project/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

After this change I have restarted the web server. Still when my django application uploads any images it goes in /var/www/ directory. I don't understand why its happening even if I have changed the apache root directory from /var/www/ to /home/ubuntu/project/

Please suggest ...

2 Answers 2

0

You need to change the DocumentRoot setting in your httpd.conf file. Chances are it will be under something like /etc/apache2/conf/httpd.conf

There just change this:

<Directory "/var/www">

to this:

<Directory "/home/ubuntu/project">

Now restart your apache service:

/etc/init.d/apache2 restart
Sign up to request clarification or add additional context in comments.

4 Comments

Hi, thanks @Timo but I dont have this "/etc/apache2/conf/httpd.conf" directory , but as I have mentioned above "/etc/apache2/apache2.conf" in this file I have made the same changes as you described, but still its not affecting the change even after restarting apache2
That is akward. Do you tried to open the httpd.conf with a text editor or, its not an directory. Did that help?
I mean I don't have that httpd.conf file as per your mentioned directory path. I dont have that /conf/ directory even under apache2.
Try find -name "httpd.conf" and look if you find the file path.
0

The upload directory will be set by your Django app, not by your Apache config.

Check your MEDIA_ROOT setting.

5 Comments

Cool. I know that but just one query, till now I was not using full path for my media directory. When I gave full directory path then images getting uploaded at desired place but when I didn't define full path for media then its going into /var/www directory. First I need to know if I dont defined media root why its going into /var/www. It should ideally give an error saying 'media' doesn't exists in your project directory.
Why apache always going into /var/www directory for uploading files, even though we haven't included that path in apache config file.
You query is too complicated for the comments. Please update your original question, include the relevant Django code, and say where your Django project is located.
Basically when you run your django app on server without using apache or any webserver it runs perfectly fine, uploaded files goes into specific desired directory defined in MEDIA_ROOT but when you use apache to server your django app I don't understand why apache looks for /var/www directory to put uploaded files.
I think thats the key we need full directory path to be define in settings for MEDIA_ROOT if you don't define that it goes into /var/www. Just little curious about from where its actually taking this /var/www path to store files.

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.