Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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: http://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?

share|improve this question

closed as too localized by Tim Post Aug 5 '10 at 14:05

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Stack Overflow is the correct place for this question, as you alluded to with your link. We're not all programmers here, just sysadmins :) –  Mark Henderson Aug 3 '10 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 '10 at 8:50
    
@Farseeker Sysadmin!? If this site is for Sysadmins then Serverfault is for whom? confused :-) –  San Aug 4 '10 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 '10 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" –  Mark Henderson Aug 4 '10 at 23:17
show 4 more comments

2 Answers 2

up vote 0 down vote accepted

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 :)

share|improve this answer
    
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 '10 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. –  David Spillett Aug 5 '10 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 '10 at 13:51
add comment

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"

share|improve this answer
add comment

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