Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Folder(s) Can My Tomcat Application Write To on Ubuntu Server

I'm not sure if the fact that i'm using Ubuntu Server matters in this case. When I am trying to create folder using the File.mkdirs() method, it doesn't throw an exception, just never works.

A larger explanation of my problem with specific code references can be found here: Cannot Create Directory On Server. Permission Issue?

The reason i'm writing a new question is because i'm wondering if i'm having issues creating directories on the server because of permissions.

String path = /home/username/foldertocreate;
File file = new File(path);
file.mkdirs();

So i'm trying to create a folder in the /home/username directory. This works just fine when i'm running in dev mode on my dev box and on a tomcat instance inside of Eclipse, but fails when the code is run on the server. Could this be because on the dev box the user is logged in and therefore permission is open to write the /home/username folder? On the server a user isn't actually logged in while the program is running...

Is there a specific folder I am able to write to?

I checked the permissions of the folder which are currently set to 700. Could that be the problem? Is it safe to set this folder to 666 or 777? Is this folder writable even if the user is not logged in?

Update: Tried changing the folder permissions to 755 with no luck.

like image 283
ryandlf Avatar asked May 26 '13 07:05

ryandlf


People also ask

Where does Tomcat save files?

By default, these files are located at TOMCAT-HOME/conf/server. xml and TOMCAT-HOME/conf/web. xml, respectively.

Where does Tomcat install on Linux?

The default directory for Tomcat files will be in /usr/local/tomcat9, you can view the configuration files inside the conf folder, the main page that you have seen above, when you open your website on the 8080 port is in /usr/local/tomcat9/webapps/ROOT/.


1 Answers

If you're using ubuntu's packaged version of tomcat, this is running under a different user account - most likely named 'tomcat'. Double check with ps aux | grep catalina - this will display the username that tomcat is running as in the first column. Exactly this user account needs to be able to create the directories/files.

For this reason, you probably don't want to open arbitrary home directories to be world-writeable, but rather configure specific directories somewhere to be accessible by the tomcat user. Setting a 755 permission gives the owner read/write/execute permissions, while everybody else gets read/execute permission. If 'tomcat' is not the owner, it will not be able to create anything in these directories. But don't fall for the trap to chmod 777 - unless it's for a quick test.

like image 118
Olaf Kock Avatar answered Oct 12 '22 23:10

Olaf Kock