permission denied in apache configuration : [Errno 13] Permission denied


Im tring to host flask on apache2.4(ubuntu 16) using wsgi and but im facing 500 error in browser:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.25 (Ubuntu) Server at Port 80

when i run tail -f /var/log/apache2/error.log:

[Tue Jan 02 05:27:28.444613 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client] Traceback (most recent call last):
[Tue Jan 02 05:27:28.444688 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]   File "/var/www/TW96/tw96.wsgi", line 4, in 
[Tue Jan 02 05:27:28.444703 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]     from index import app as application
[Tue Jan 02 05:27:28.444717 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]   File "/var/www/TW96/tw96/", line 32, in 
[Tue Jan 02 05:27:28.444740 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client],debug=True)
[Tue Jan 02 05:27:28.444755 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]   File "/usr/local/lib/python3.5/dist-packages/flask/", line 841, in run
[Tue Jan 02 05:27:28.444766 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]     run_simple(host, port, self, **options)
[Tue Jan 02 05:27:28.444789 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]   File "/usr/local/lib/python3.5/dist-packages/werkzeug/", line 780, in run_simple
[Tue Jan 02 05:27:28.444799 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client]     s.bind((hostname, port))
[Tue Jan 02 05:27:28.444825 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client] PermissionError: [Errno 13] Permission denied

this is my apache configuration file:

<VirtualHost *:80>
                ServerAdmin [email protected]
                WSGIScriptAlias / /var/www/TW96/tw96.wsgi
                <Directory /var/www/TW96/tw96/>
                        Require all granted
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined

and this is my wsgi file :

import sys,os
from index import app as application

and the www folder :

Asked By: Kasra



Line 32 of /var/www/TW96/tw96/ starts an HTTP server on port 80:,debug=True)

This fails because the first 1024 ports are for privileged users only. Even if your application would run as a privileged user, Apache is already listening on that port, so you can’t open it.

In any case, importing your application should not start an HTTP server in the first place. Remove line 32.

Answered By: phihag

Just run below command it was worked for me

$ sudo chown -R www-data:www-data /var/www/TW96/tw96/

Checking file ownership

If you have created any new files & folders in your website’s folder then its owner may be the Linux user you are currently logged in as. For example, if you are currently logged in as user ubuntu and create a new file in /var/www/html then its owner will be ubuntu. By default Apache uses www-data user to access your website’s files & folders by default.

So in this case, you will need to change the user of newly created files & folders. Run the following command to set the owner of your website files & folders recursively.

$ sudo chown -R www-data:www-data /var/www/html

for more detailed references please check this below link

Answered By: Rabiyulfahim