0

I am working on a Django project and using Apache as web server. Everything is working fine with

python manage.py runserver

But while running the application through apache I am not able to write my python app logs into the stated path which is outside the project directory.

Project directory /home/ubuntu/saas-DocumentProcessing

Log files are in

/home/ubuntu/log/SaasAap/SaasAap.log and /home/ubuntu/log/error/error.log

My 000-default.conf content

<VirtualHost *:8000>
        ServerAdmin abc@xyz.com
        ServerName my_ip
        ServerAlias my_ip
        DocumentRoot /home/ubuntu/saas-DocumentProcessing/
        WSGIScriptAlias / /home/ubuntu/saas-DocumentProcessing/src/wsgi.py
        Alias /static/ /home/ubuntu/saas-DocumentProcessing/static/
        ErrorLog /home/ubuntu/log/error.log
        CustomLog /home/ubuntu/log/custom.log combined
        <Location "/static/">
                Options -Indexes
                        AllowOverride All
                        Require all granted
        </Location>
        <Location "/">
                AllowOverride All
                Require all granted
        </Location>
        <Directory /home/ubuntu/saas-DocumentProcessing/static>
                Order allow,deny
                 Allow from all
        </Directory>
         <Directory /home/ubuntu/log>
                Order allow,deny
                 Allow from all
        </Directory>
        WSGIDaemonProcess saas-DocumentProcessing python-path=/home/ubuntu/
saas-DocumentProcessing python-home=/home/ubuntu/saas-DocumentProcessing/ve
nv
        WSGIProcessGroup saas-DocumentProcessing

</VirtualHost>

1 Answers1

0

Step 1: Figure out what user Apache is running as:

ps aux | egrep '(apache|httpd)'

Then check the file ownership and permissions for the directories that you are writing your logs to. Either change the owner of this directory (and children) to match Apache, or change the file permissions to allow write to this directory.

The best solution is to change the owner:

sudo chown -R <user_from_above> /home/ubuntu/log

An NOT secure method is to change the permissions:

sudo chmod 777 /home/ubuntu/log
sudo chmod 777 /home/ubuntu/log/SaasAap
John Hanley
  • 4,287
  • 1
  • 9
  • 20
  • I cross checked the file ownership and permissions, ownership is set to the same user with which apache is running. But the issue is still present. – Girish Sharma Aug 29 '18 at 06:08