java.io.FileNotFoundException (permission denied) despite chmod 777

Athlan picture Athlan · Jan 9, 2014 · Viewed 64.4k times · Source

I have faced strange poblem while writing Grails application deployed on Tomcat.

After creating simple test controller I want to write test contents in package com

package com.domain.controller

import java.io.File;
import java.io.PrintWriter;

class TestController {

        def index() {
                // test
                try {
                        PrintWriter writer = new PrintWriter("/home/user/domains/domain.com/public_html/the-file-name.txt");
                        writer.println("The first line");
                        writer.println("The second line");
                        writer.close();
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }
        }
}

I get an exception:

Class java.io.FileNotFoundException Message /home/user/domains/domain.com/public_html/the-file-name.txt (Brak dostępu)

I have set the chmod to 777 into /home/user/domains/domain.com/public_html/. And tomcat7.tomcat7 is owner. I have also tried to create this file with the access rights 777 and ownership set to tomcat7, but I still get an exception:

ls -al /home/user/domains/domain.com/public_html
razem 16
drwxrwxrwx 3 tomcat7 tomcat7 4096 01-08 23:25 .
drwxr-xr-x 8 user    user    4096 12-16 17:14 ..
-rwxrwxrwx 1 tomcat7 tomcat7    0 01-08 23:25 the-file-name.txt

What conditions in OS should I also meet?

I would be very gratefull if someone could clarify the problem.


EDIT:

I have created the directory under /path1, set 777. The files are stored perfectly. I have also crated the directory under under /path2/testdir, but path2 has no permission 777 and chown. It also works. I have also testes the testdir with characters . and _, also works.

I am very investigative and cannot understand the behaviour.

Answer

JustinKSU picture JustinKSU · Jan 9, 2014

Ensure you that you have read and execute access to all parent directories as well.

Example: chmod o+x /home/user