Re: [PHP] Permission Denied - Help Requested - Solved
At 12:07 AM 3/30/2011, Adam Richardson wrote: On Tue, Mar 29, 2011 at 8:21 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 05:33 PM 3/29/2011, Adam Richardson wrote: Thanks. What do you see if you run this? Can't open or create file! Ethan OK, If you're running PHP as an Apache module, by default it won't have permissions to write to the directory (this is by design to avoid security issues.) You can do something like the following: 1. Create a directory for writing files outside of your public directory (let's call it uploads.) 2. Change the group associated with the directory to Apache: sudo chgrp -R www-data /home/username/path/to/uploads 3. Change the permissions on the directory so the group has write permissions: sudo chmod -R 2775 /home/username/path/to/uploads 4. Then try the script again. See if that works. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com Thanks - The directory is output_files, which is a subdirectory of /var/www I'm getting a message invalid owner on the command chown Apache output_files. Also with the -R option, and with apache as the owner, also with the chgrp. All these commands are run as root.. Help and advice please. Ethan Hi Ethan, I might be missing something. Did you set up the user Apache? On a standard install for Debian (using apt-get), apache is usually set up as the user/group www-data: http://wiki.debian.org/Apache http://wiki.debian.org/ApacheThe root user typically owns the /var/www directory. I usually set up virtual hosts within one of the other accounts and then change the group on a directory outside of the public directory specifically set aside for uploads and run the commands I sent. However, in the case of your example, I believe you can just run the 2 commands I sent on the /var/www/output_files directory and you should be able to write the files. sudo chgrp -R www-data /var/www/output_files sudo chmod -R 2775 /var/www/output_files Hope this helps, and sorry if I misunderstood something in your configuration or troubleshooting. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com Adam - Thanks. Works beautifully. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested
On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 11:14 PM 3/28/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg mailto: eth...@earthlink.neteth...@earthlink.net wrote: At 01:32 AM 3/28/2011, Hans Åhlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg mailto:eth...@earthlink.net eth...@earthlink.net: Dear List - Thanks for all your help in the past.  Here is another one... I am getting a Permission Denied message when I try to run a PHP script.  I just changed the mode on the directory and the files to 777.  This problem arose when I changed the permissions.  I thought I was solving a problem, because I could not open a file for writing.  I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg **  Hans Åhlin   Tel: +46761488019   icq: 275232967   http://www.kronan-net.com/http://www.kronan-net.com/   irc://http://irc.freenode.net:6667irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan Hi Ethan, Are you using suPHP or suExec? I believe the server chokes on 777 permissions in those cases. Have you checked the permissions in the command line (sorry for the basic question, but just making sure I know what you've already done?) Also, can we see some of the code you're using to handle the file processing? Thanks, Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.comhttp://nephtaliproject.com + Adam - Thanks. 1] Pardon my ignorance but I do not understand this - Are you using suPHP or suExec? suPHP and suExec are two modules that allow PHP to run with the permissions of the user, making it easy to write files to disk. However, suPHP (and I believe suExec, but I can't remember for sure) does not like 777 permissions. 2] I changed the permissions to 755 and the Permission Denied message went away. Check! 3] Have you checked the permissions in the command line? Yes Check! 4] Here are some code snippets: $fptr1 = fopen(chessboard, r+); //this works $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should for($i = 0; $i 8; $i++) { for ($j = 0; $j 8; $j++) fprinf($fptr2, %s , $results[$i][$j]); fprinf($fptr2, \n); } //this never writes, so I am left with an empty file Can you try a simplified form that checks for success along the way? How about something like the code below to see how far it gets (I haven't tested, but it should be close): ?php // let's make sure you see the E_WARNING errors if present for file functions error_reporting(-1); // set var for later $cost = 120.89; if (!($fp = fopen(test.txt, 'w'))) { echo Can't open or create file!; } else if (!($len = fprintf($fp, In the year 3000, a Coke will cost %01.2f, with tax., $cost))) { echo Can't write to file!; } else if (!(fclose($fp))) { echo Can't properly close file!; } ? What do you see if you run this? Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] Permission Denied - Help Requested
At 01:40 PM 3/29/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 11:14 PM 3/28/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg mailto: eth...@earthlink.neteth...@earthlink.net wrote: At 01:32 AM 3/28/2011, Hans à hlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg mailto:eth...@earthlink.net eth...@earthlink.net: Dear List - Thanks for all your help in the past.  Here is another one... I am getting a Permission Denied message when I try to run a PHP script.  I just changed the mode on the directory and the files to 777.  This problem arose when I changed the permissions.  I thought I was solving a problem, because I could not open a file for writing.  I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg **  Hans à hlin   Tel: +46761488019   icq: 275232967   http://www.kronan-net.com/http://www.kronan-net.com/   irc://http://irc.freenode.net:6667irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan Hi Ethan, Are you using suPHP or suExec? I believe the server chokes on 777 permissions in those cases. Have you checked the permissions in the command line (sorry for the basic question, but just making sure I know what you've already done?) Also, can we see some of the code you're using to handle the file processing? Thanks, Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.comhttp://nephtaliproject.com + Adam - Thanks. 1] Pardon my ignorance but I do not understand this - Are you using suPHP or suExec? suPHP and suExec are two modules that allow PHP to run with the permissions of the user, making it easy to write files to disk. However, suPHP (and I believe suExec, but I can't remember for sure) does not like 777 permissions. 2] I changed the permissions to 755 and the Permission Denied message went away. Check! 3] Have you checked the permissions in the command line? Yes Check! 4] Here are some code snippets: $fptr1 = fopen(chessboard, r+); //this works $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should for($i = 0; $i 8; $i++) { for ($j = 0; $j 8; $j++) fprinf($fptr2, %s , $results[$i][$j]); fprinf($fptr2, \n); } //this never writes, so I am left with an empty file Can you try a simplified form that checks for success along the way? How about something like the code below to see how far it gets (I haven't tested, but it should be close): ?php // let's make sure you see the E_WARNING errors if present for file functions error_reporting(-1); // set var for later $cost = 120.89; if (!($fp = fopen(test.txt, 'w'))) { echo Can't open or create file!; } else if (!($len = fprintf($fp, In the year 3000, a Coke will cost %01.2f, with tax., $cost))) { echo Can't write to file!; } else if (!(fclose($fp))) { echo Can't properly close file!; } ? What do you see if you run this? Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com +++ Thanks. What do you see if you run this? Can't open or create file! Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested
On 3/29/2011 3:06 PM, Ethan Rosenberg wrote: At 01:40 PM 3/29/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 11:14 PM 3/28/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg mailto: eth...@earthlink.neteth...@earthlink.net wrote: At 01:32 AM 3/28/2011, Hans �hlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg mailto:eth...@earthlink.net eth...@earthlink.net: Dear List - Thanks for all your help in the past.  Here is another one... I am getting a Permission Denied message when I try to run a PHP script.  I just changed the mode on the directory and the files to 777.  This problem arose when I changed the permissions.  I thought I was solving a problem, because I could not open a file for writing.  I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg **  Hans �hlin   Tel: +46761488019   icq: 275232967   http://www.kronan-net.com/http://www.kronan-net.com/   irc://http://irc.freenode.net:6667irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan Hi Ethan, Are you using suPHP or suExec? I believe the server chokes on 777 permissions in those cases. Have you checked the permissions in the command line (sorry for the basic question, but just making sure I know what you've already done?) Also, can we see some of the code you're using to handle the file processing? Thanks, Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.comhttp://nephtaliproject.com + Adam - Thanks. 1] Pardon my ignorance but I do not understand this - Are you using suPHP or suExec? suPHP and suExec are two modules that allow PHP to run with the permissions of the user, making it easy to write files to disk. However, suPHP (and I believe suExec, but I can't remember for sure) does not like 777 permissions. 2] I changed the permissions to 755 and the Permission Denied message went away. Check! 3] Have you checked the permissions in the command line? Yes Check! 4] Here are some code snippets: $fptr1 = fopen(chessboard, r+); //this works $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should for($i = 0; $i 8; $i++) { for ($j = 0; $j 8; $j++) fprinf($fptr2, %s , $results[$i][$j]); fprinf($fptr2, \n); } //this never writes, so I am left with an empty file Can you try a simplified form that checks for success along the way? How about something like the code below to see how far it gets (I haven't tested, but it should be close): ?php // let's make sure you see the E_WARNING errors if present for file functions error_reporting(-1); // set var for later $cost = 120.89; if (!($fp = fopen(test.txt, 'w'))) { echo Can't open or create file!; } else if (!($len = fprintf($fp, In the year 3000, a Coke will cost %01.2f, with tax., $cost))) { echo Can't write to file!; } else if (!(fclose($fp))) { echo Can't properly close file!; } ? What do you see if you run this? Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com +++ Thanks. What do you see if you run this? Can't open or create file! Ethan Run this. Make certain this script and test.txt are in the same dir. If not, use full path to your file. clearstatcache(); $array= stat(test.txt); print_r($array);//This will tell you what's going on. Incidentally, consider using file_get_contents() and file_put_contents() Much easier to use and faster. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested
At 03:49 PM 3/29/2011, Al wrote: On 3/29/2011 3:06 PM, Ethan Rosenberg wrote: At 01:40 PM 3/29/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 11:14 PM 3/28/2011, Adam Richardson wrote: On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg mailto: eth...@earthlink.neteth...@earthlink.net wrote: At 01:32 AM 3/28/2011, Hans Ã�hlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg mailto:eth...@earthlink.net eth...@earthlink.net: Dear List - Thanks for all your help in the past. à Here is another one... I am getting a Permission Denied message when I try to run a PHP script. à I just changed the mode on the directory and the files to 777. à This problem arose when I changed the permissions. à I thought I was solving a problem, because I could not open a file for writing. à I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg ** à Hans Ã�hlin à à Tel: +46761488019 à à icq: 275232967 à à http://www.kronan-net.com/http://www.kronan-net.com/ à à irc://http://irc.freenode.net:6667irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan Hi Ethan, Are you using suPHP or suExec? I believe the server chokes on 777 permissions in those cases. Have you checked the permissions in the command line (sorry for the basic question, but just making sure I know what you've already done?) Also, can we see some of the code you're using to handle the file processing? Thanks, Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.comhttp://nephtaliproject.com + Adam - Thanks. 1] Pardon my ignorance but I do not understand this - Are you using suPHP or suExec? suPHP and suExec are two modules that allow PHP to run with the permissions of the user, making it easy to write files to disk. However, suPHP (and I believe suExec, but I can't remember for sure) does not like 777 permissions. 2] I changed the permissions to 755 and the Permission Denied message went away. Check! 3] Have you checked the permissions in the command line? Yes Check! 4] Here are some code snippets: $fptr1 = fopen(chessboard, r+); //this works $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should for($i = 0; $i 8; $i++) { for ($j = 0; $j 8; $j++) fprinf($fptr2, %s , $results[$i][$j]); fprinf($fptr2, \n); } //this never writes, so I am left with an empty file Can you try a simplified form that checks for success along the way? How about something like the code below to see how far it gets (I haven't tested, but it should be close): ?php // let's make sure you see the E_WARNING errors if present for file functions error_reporting(-1); // set var for later $cost = 120.89; if (!($fp = fopen(test.txt, 'w'))) { echo Can't open or create file!; } else if (!($len = fprintf($fp, In the year 3000, a Coke will cost %01.2f, with tax., $cost))) { echo Can't write to file!; } else if (!(fclose($fp))) { echo Can't properly close file!; } ? What do you see if you run this? Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com +++ Thanks. What do you see if you run this? Can't open or create file! Ethan Run this. Make certain this script and test.txt are in the same dir. If not, use full path to your file. clearstatcache(); $array= stat(test.txt); print_r($array);//This will tell you what's going on. Incidentally, consider using file_get_contents() and file_put_contents() Much easier to use and faster. + Al - Thanks. Here is what I ran and the output. I do not know enough PHP to interpret the output. !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html body ?php error_reporting(1); clearstatcache(); $array= stat(test.txt); print_r($array);//This will tell you what's going on. // Output /* Array ( [0] = 2050 [1] = 876877 [2] = 33188 [3] = 1 [4] = 1001 [5] = 1001 [6] = 0 [7] = 30 [8] = 1301430589 [9] = 1301430589 [10] = 1301430589 [11] = 4096 [12] = 8 [dev] = 2050 [ino] = 876877 [mode] = 33188 [nlink] = 1 [uid] = 1001 [gid] = 1001 [rdev] = 0 [size] = 30 [atime] = 1301430589 [mtime] = 1301430589 [ctime] = 1301430589 [blksize] = 4096 [blocks] = 8 ) */ ? /body /html Help and advice, please. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe,
RE: [PHP] Permission Denied - Help Requested
Have you checked ownership? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested
Thanks. What do you see if you run this? Can't open or create file! Ethan OK, If you're running PHP as an Apache module, by default it won't have permissions to write to the directory (this is by design to avoid security issues.) You can do something like the following: 1. Create a directory for writing files outside of your public directory (let's call it uploads.) 2. Change the group associated with the directory to Apache: sudo chgrp -R www-data /home/username/path/to/uploads 3. Change the permissions on the directory so the group has write permissions: sudo chmod -R 2775 /home/username/path/to/uploads 4. Then try the script again. See if that works. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] Permission Denied - Help Requested
At 05:33 PM 3/29/2011, Adam Richardson wrote: Thanks. What do you see if you run this? Can't open or create file! Ethan OK, If you're running PHP as an Apache module, by default it won't have permissions to write to the directory (this is by design to avoid security issues.) You can do something like the following: 1. Create a directory for writing files outside of your public directory (let's call it uploads.) 2. Change the group associated with the directory to Apache: sudo chgrp -R www-data /home/username/path/to/uploads 3. Change the permissions on the directory so the group has write permissions: sudo chmod -R 2775 /home/username/path/to/uploads 4. Then try the script again. See if that works. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com Thanks - The directory is output_files, which is a subdirectory of /var/www I'm getting a message invalid owner on the command chown Apache output_files. Also with the -R option, and with apache as the owner, also with the chgrp. All these commands are run as root.. Help and advice please. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested
On Tue, Mar 29, 2011 at 8:21 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 05:33 PM 3/29/2011, Adam Richardson wrote: Thanks. What do you see if you run this? Can't open or create file! Ethan OK, If you're running PHP as an Apache module, by default it won't have permissions to write to the directory (this is by design to avoid security issues.) You can do something like the following: 1. Create a directory for writing files outside of your public directory (let's call it uploads.) 2. Change the group associated with the directory to Apache: sudo chgrp -R www-data /home/username/path/to/uploads 3. Change the permissions on the directory so the group has write permissions: sudo chmod -R 2775 /home/username/path/to/uploads 4. Then try the script again. See if that works. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com Thanks - The directory is output_files, which is a subdirectory of /var/www I'm getting a message invalid owner on the command chown Apache output_files. Also with the -R option, and with apache as the owner, also with the chgrp. All these commands are run as root.. Help and advice please. Ethan Hi Ethan, I might be missing something. Did you set up the user Apache? On a standard install for Debian (using apt-get), apache is usually set up as the user/group www-data: http://wiki.debian.org/Apache http://wiki.debian.org/ApacheThe root user typically owns the /var/www directory. I usually set up virtual hosts within one of the other accounts and then change the group on a directory outside of the public directory specifically set aside for uploads and run the commands I sent. However, in the case of your example, I believe you can just run the 2 commands I sent on the /var/www/output_files directory and you should be able to write the files. sudo chgrp -R www-data /var/www/output_files sudo chmod -R 2775 /var/www/output_files Hope this helps, and sorry if I misunderstood something in your configuration or troubleshooting. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] Permission Denied - Help Requested
At 01:32 AM 3/28/2011, Hans à hlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg eth...@earthlink.net: Dear List - Thanks for all your help in the past.  Here is another one... I am getting a Permission Denied message when I try to run a PHP script.  I just changed the mode on the directory and the files to 777.  This problem arose when I changed the permissions.  I thought I was solving a problem, because I could not open a file for writing.  I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg **  Hans à hlin   Tel: +46761488019   icq: 275232967   http://www.kronan-net.com/   irc://irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Permission Denied - Help Requested
On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg eth...@earthlink.netwrote: At 01:32 AM 3/28/2011, Hans Åhlin wrote: Do you have SELinux installed? 2011/3/28 Ethan Rosenberg eth...@earthlink.net: Dear List - Thanks for all your help in the past.  Here is another one... I am getting a Permission Denied message when I try to run a PHP script.  I just changed the mode on the directory and the files to 777.  This problem arose when I changed the permissions.  I thought I was solving a problem, because I could not open a file for writing.  I was not receiving error messages, but no file was created. Help and advice, please. Ethan Rosenberg **  Hans Åhlin   Tel: +46761488019   icq: 275232967   http://www.kronan-net.com/   irc://irc.freenode.net:6667 - TheCoin ** Hans - Sorry, I did not include my signature, which includes all the requested information. Here it is Ethan == MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)] The problem persists. I cannot write to a file from PHP. Any more suggestions? Thanks. Ethan Hi Ethan, Are you using suPHP or suExec? I believe the server chokes on 777 permissions in those cases. Have you checked the permissions in the command line (sorry for the basic question, but just making sure I know what you've already done?) Also, can we see some of the code you're using to handle the file processing? Thanks, Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com