tomcat cannot write files into WEB-INF folder

I used cpanel+tomcat .the Project structure is :

ROOT

 ----index.jsp

 ---- sample.txt

 ----- /WEB-INF/classes/pack2/sample2.txt

tomcat Can write into sample.txt with permission 664 . but cannot write into /WEB-INF/classes/pack2/sample2.txt

/WEB-INF/classes/pack2/ with permission 775 , sample2.txt with permission 775 . all folder and files in web-inf folder contains permission 775 and the owner of files is Ftp user .

permissions are:

root@panther [/home/domain /public_html]# ls -la

total 15884

drwxr-x— 4 domain nobody 4096 Jan 9 19:10 ./

drwx–x–x 11 domain domain 4096 Jan 28 12:06 ../

-rw-r–r– 1 domain domain 0 Oct 2 14:44 .htaccess

drwxr-xr-x 5 domain domain 4096 Oct 8 19:26 ROOT/

-rw-r–r– 1 domain domain 16216478 Jan 9 19:10 ROOT.zip

For all files Owner,Group is domain. domain is ftp user. tomcat is member of nobody group.

Answer

You haven’t provided enough information for a definitive answer; but what you have provided is enough for me to take a stab. I’m going to assume that the problem lies outside of tomcat, in the filesystem permissions – but it’s also possible that tomcat, or your application, has some other config that limits what locations on the filesystem it will let itself write to.

You mentioned that all the folders are 775 – that’s rwx for the onwer, rwx for the owning group, and read and execute for everyone else.

You’ve mentioned that the problem is that tomcat (and by implication, the user running tomcat) can’t create files inside /WEB-INF/classes/pack2/

If the user running tomcat was the owner of the directory, they’d be able to create files in that directory – so it must be a running as a different user

If the user running tomcat is in the group that owns the directory, the permissions are sufficient that they should still have the ability to create files – so we can deduce that the user running tomcat is also not in the group that owns the directory

So, the only remaining possibility is that the user running tomcat is neither the user that owns the directory or a member of the group owning the directory – or there’s something weird going on.

One way to make this problem go away would be to make the folder 777 – but I’m not going to call that a “solution” as it leaves the system wide open for abuse, as anyone can write there. Another way would be to add the user running tomcat into the group that owns the directory; but I don’t know what that group is, so I don’t know if that’s going to be an appropriate solution or not.

Another way is to make a new group just to control access to this folder; use chgrp to change the group owner of the folder to the new group, and add anyone who needs write access to the folder into that group.

Attribution
Source : Link , Question Author : amir2 taghvaei , Answer Author : James Polley

Leave a Comment