fix permission denied in apache

How to Fix Errno 13 Permission Denied Error in Apache

Very often when you configure something in Apache, you will get “Errno 13 Permission Denied” error. In this article, we will look at the different reasons for this problem and also how to fix it.

How to Fix Errno 13 Permission Denied Error in Apache

Let us say you try to access your home page and get this error. There are a few things you need to check.

1. Check Apache configuration

Open Apache configuration file in a text editor.

$ sudo vi /etc/apache2/httpd.conf

Look for the following Directory tag.

<Directory />
     Order deny,allow
     Deny from all

The above configuration will block access to all files and URLs. Instead it should be something like

<Directory />
     Order allow,deny
     Allow from all

If you face this problem for a specific folder or subdirectory, check if that folder’s Directory tag or its parent folder’s Directory tag is blocked as shown above.

If you have created a virtual host configuration for your website, such as /etc/apache2/sites-available/example.conf then open that file abd repeat the above step.

$ sudo vi /etc/apache2/sites-available/example.conf

2. Check Read/Write Permissions

Make sure the Apache user that you use (e.g. www-data) has read/write permissions for your website’s files & folders. If you have created any new files & folders, they may not have the permissions required by Apache. So run the following command to allow read/write permissions to all files & folders in your website root folder.

$ sudo chmod -R 755 /var/www/html

The -R option above will recursively update the user permissions of all files & folders in your webite’s root location.

3. Check 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

If you want to find out the user used by Apache process on your system run the following command.

$ ps aux|grep apache

You will see a similar output as shown below. The first column of the output displays the user being used by Apache.

www-data  1378  0.0  0.1 141184  7634 ? Ss Apr29   0:02 /usr/bin/apache2 -k start 
www-data  1397  0.0  0.1 151184  7268 ? S Apr29   0:00 /usr/bin/apache2 -k start

4. Check for enhanced security

If you are using Security Enhanced Linux (SELinux) then you may need to use chcon to set the security context of your directory. You can do this copying the security context of an existing folder that does work properly.

chcon -R --reference=/var/www /var/www/html

To sum up, you need to check Apache configuration file & virtual host files, then file permissions and file ownership to fix the permission denied error in Apache.

Also read:

How to Define & Use Variables in Apache
NGINX : Protect Static Files With Authentication
How to Setup Apache Virtual Host in Windows
How to Escape Percent Character in Apache
How to Log POST data in NGINX

Leave a Reply

Your email address will not be published. Required fields are marked *