Jump to content

Recommended Posts

Posted

Been reading here for about an hour. I think I know the answer but maybe someone knows something I don't. Here's what I'm trying to do. I wrote a php program that extracts info from mysql and then attempts to write it to a file. The problem is the directories are 775 and the php script is nobody so it can't write the file. So I figured if I ran chmod(..., 0777) from the script and then changed it back all would be good. And it would have except the chmod command didn't run either.

 

Anyone have any ideas? Or will I just have to chmod the dirs manually, write the files then chmod everything back?

Posted
I wrote a php program that extracts info from mysql and then attempts to write it to a file. The problem is the directories are 775 and the php script is nobody so it can't write the file.

That would be a problem if you own the directory, which it appears that you do.

 

So I figured if I ran chmod(..., 0777) from the script and then changed it back all would be good. And it would have except the chmod command didn't run either.

Users can only do a chmod on directories and files that they own. Since your PHP script runs as 'nobody', it cannot change the permissions on a directory that is not owned by 'nobody'.

 

Anyone have any ideas? Or will I just have to chmod the dirs manually, write the files then chmod everything back?

You could set up your PHP script to run as a CGI script. As a CGI script, the script will run as "you" and avoid the permission problems you're currently having.

 

In the directory where your script is, create an .htaccess file if there isn't one, or edit the existing one and add the following:

><Files myscriptname.php>
 AddHandler cgi-script .php
</Files>

Replace 'myscriptname.php' with the actual file name of your PHP script.

 

Then, edit your script and insert the following as the very first line in your script:

>#!/usr/bin/php

Finally, set the permissions on your PHP script to 0755 so it is executable.

 

That should set you up. Leave the directory your script writes to with 0775 permissions and run the script - hopefully, the script will be able to create the file as you intend.

Posted
That would be a problem if you own the directory, which it appears that you do.

Users can only do a chmod on directories and files that they own. Since your PHP script runs as 'nobody', it cannot change the permissions on a directory that is not owned by 'nobody'.

You could set up your PHP script to run as a CGI script. As a CGI script, the script will run as "you" and avoid the permission problems you're currently having.

 

In the directory where your script is, create an .htaccess file if there isn't one, or edit the existing one and add the following:

><Files myscriptname.php>
 AddHandler cgi-script .php
</Files>

Replace 'myscriptname.php' with the actual file name of your PHP script.

 

Then, edit your script and insert the following as the very first line in your script:

>#!/usr/bin/php

Finally, set the permissions on your PHP script to 0755 so it is executable.

 

That should set you up. Leave the directory your script writes to with 0775 permissions and run the script - hopefully, the script will be able to create the file as you intend.

 

 

cool, that sounds like it should work. :) I'll give it a try and let you know if it does.

 

thanks a bunch. :thumbup1:

Posted
cool, that sounds like it should work. :) I'll give it a try and let you know if it does.

 

thanks a bunch. :thumbup1:

 

yep that worked. :thumbup1: Thank you very very much. :thumbup1:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...