Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Arrrg! Permissions driving me nuts in PHP



Dave,

If this script is part of a web page, ensure that your web browser has
permission to modify the directories where you are creating and
deleting things.

My server is running on Ubuntu (I know, different people have
different oppinions of that), but Ubuntu and Debian both run appache
as user www-data, with group www-data.  Whenever I install a script, I
make sure to chown -R www-data:www-data  <script-data-path>

This gives the script access to do whatever it wants to the area where
it is writing files too.

I have heard (though not actually verified) that Fedora and CentOS run
Apache as user apache.

-- 
Ken



On Tue, Nov 23, 2010 at 1:44 PM, Dave M G <dave@example.com> wrote:
> TLUG,
>
> In a PHP script I have, I use mkdir() to create a directory and put some
> files in it.
>
> It's just a temporary directory to organize some files that I bundle
> into a tar.gz file and store away.
>
> After I've got the tar file made, I want to delete the temp directory. I
> use the code included at the bottom (which I took from the PHP manual
> site) to recursively delete the directory and its subdirectories and files.
>
> However, when I run the code, I get permission errors:
> Warning: unlink(/home/site/public_html/+backup/someFileOrOther)
> [function.unlink]: Permission denied in
> /home/site/public_html/backup.php on line 115
>
> How can a directory I just made a few lines earlier in a PHP script have
> permissions that don't permit the very same script that created it to
> delete it a few lines later?
>
> More importantly, how do I remove the $%&#ing thing?
>
> Thanks for any advice. The aforementioned delete function is included
> below for reference:
>
> function rrmdir($dir)
>    {
>        if (is_dir($dir))
>        {
>            $objects = scandir($dir);
>            foreach ($objects as $object)
>            {
>                if ($object != "." && $object != "..")
>                {
>                    if (filetype($dir . "/" . $object) == "dir")
>                        rrmdir($dir . "/" . $object); else
>                        unlink($dir . "/" . $object);
>                }
>            }
>            reset($objects);
>            rmdir($dir);
>        }
>    }
>
> --
> Dave M G
>
> --
> To unsubscribe from this mailing list,
> please see the instructions at http://lists.tlug.jp/list.html
>
> The TLUG mailing list is hosted by the award-winning Internet provider
> ASAHI Net.
> Visit ASAHI Net's English-language Web page: http://asahi-net.jp/en/
>


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links