4

I have an XML file on my server. In the same directory I have a PHP file which modifies the content of the XML and saves it. In this, the save part doesn't work. In my knowledge the code is alright and the problem is with the file access persmissions.

More details available here: https://stackoverflow.com/questions/3351652/how-to-save-an-xml-file-on-the-web-server-using-php ( There is nothing wrong with the code. I provided it to give more insights. The problem seems to be with the access permissions )

The permissions of the XML file is: rw-r--r-- (644)

My question is, am I doing it right? How do I modify a file in the same directory?

8
  • Stack Overflow is the correct place for this question, as you alluded to with your link. We're not all programmers here, just sysadmins :) Aug 3, 2010 at 8:44
  • Closing this, as you've already asked the same question on SO which is the appropriate venue for programming questions.
    – Tim Post
    Aug 3, 2010 at 8:50
  • @Farseeker Sysadmin!? If this site is for Sysadmins then Serverfault is for whom? confused :-)
    – San
    Aug 4, 2010 at 10:18
  • @Tim I tried it already on SO Tim. There is nothing wrong with the code. I am just overlooking something on the server/file permissions. That's why I thought webmasters may able to help!
    – San
    Aug 4, 2010 at 10:19
  • 1
    @San, sorry my mistake. i must ahve been tired when I wrote that. I meant to say "We're not all sysadmins, just webmasters" Aug 4, 2010 at 23:17

2 Answers 2

0

The answer will change depending on who owns the rights to that file. For example when I create a file on our server with our FTP client (filezilla) the owner is the username of our FTP account but if we create the file using PHP the owner is www-data.

That being said by looking at your rights I see that only the owner has the right to write on your file, the group and other only have read access. Here's a calculator I'll often use to figure which rights to give to the chmod command (http://www.onlineconversion.com/html_chmod_calculator.htm). It's pretty intuitive but I'm guessing you'll have to give write access to the group.

Hope that helps :)

3
  • The owner of the file is, as you said, the username (sanspace). But, who will be the user while I try to access it through PHP? Will it be the same user or a different one? There are no other users in this server other than sanspace.
    – San
    Aug 5, 2010 at 8:59
  • @San: it depends how your web server is setup. If php is being run in one of the (fast)CGI modes through suexec or similar then your script may be run as you (sanspace). Otherwise it will be run as the user the web server runs under, "apache", "http", "www-data" and "nobody" are common usernames to find in this case. If your server setup is Linux based and doesn't have PHP's exec and related functions disabled, you can use them to run the whoami or id commands to see what user the script is running as. Aug 5, 2010 at 10:56
  • If you don't have access to what David mentioned above you could also figure it out by creating a file using php (fopen('yourPath/test.txt', 'w')) in your script and looking at the owner of that file. Just make sure you know how to remove it afterward since your FTP account probably won't have the rights to it haha :)
    – Gazillion
    Aug 5, 2010 at 13:51
0

Maybe I'm overlooking something, but it seems like you only have given write access to the owner, which has already been established to be likely something other than your PHP/Webserver's user, thus, no permission to write.

You could either make sure that your user is in the "www-data" group (or whichever group your webserver is using) and add write permission to the group "chmod g+w filename.xml"

Or, you could place that file in the "www-data" group with "chown www-data:www-data filename.xml"

Not the answer you're looking for? Browse other questions tagged or ask your own question.