0

I am trying to create files in my /var/www folder (debian), but the folder is read only. The only way I can create a file is to go into root and create it in the terminal. Then I have to edit the contents there too. How can I create files and folders inside the www directory, or make it not readonly but still be secure some how. I don't understand how this works... thanks

3
  • Better question, what are you wanting to use to upload files? via ftp? Could you type ls -l /var/ | grep www and give me the response aswell.
    – Jess
    Aug 18, 2011 at 4:36
  • This has nothing to do with ftp; /var/www is on his local machine.
    – cdhowie
    Aug 18, 2011 at 4:37
  • He never said he was working on a local machine, I assumed he was ssh'g into a remote machine and creating files. Then he would obviously want sftp/ftp access. My bad.
    – Jess
    Aug 18, 2011 at 4:39

5 Answers 5

4

You could change ownership of /var/www to your user or group, or create a subdirectory in /var/www and give yourself ownership. If your user name is "david" then:

david$ su -
root# chown david /var/www

Or:

david$ su -
root# mkdir /var/www/david
root# chown david /var/www/david

Then your user will be able to read and write inside of whichever directory you give yourself ownership of.

0
1
sudo chown `whoami` /var/www

That will set the owner of /var/www to the current user, which is what whoami returns.

You should really read up on permissions and ownership of files/directories in posix systems if you're going to be maintaining an apache instance.

This may not be the best link, but it was first on google for "understanding unix permissions" : http://www.perlfect.com/articles/chmod.shtml

1
  • Note that sudo is not installed on Debian by default.
    – cdhowie
    Aug 18, 2011 at 4:38
0

You can do this by changing the permissions of the folder.

$ chmod 664 myfile/folder

0

In order to do what you want and at the same time don't mess with the web server perms you must add yourself and the web server' user or group to the files and directories ownerships.

You can do it like follows:

1: # chmod -R 775 /var/www/;
2: # chown -R your-user.webserver-group /var/www/

The first line gives the user and group read, write and execution perms in the web server directory.

The second line warranties that you are the user stated in the line 1, and the web server group is in the group in the web server directory.

In that way you will be able to create, modify or delete files and folders in the /var/www/ directory and at the same time the web server can do its normal tasks.

0

You could save to /tmp, then use the ftp functions like PHP's ftp_fput() to push the temp file to its proper location. It seems crazy to have the server ftp "back to itself" but the files will then be owned by the ftp user and not the apache user. Be sure to delete the tmp file and secure the file that has the ftp password. us3.php.net/manual/en/function.ftp-fput.php

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .