开发者

Unlink and permission denied in php

开发者 https://www.devze.com 2023-02-25 04:12 出处:网络
I\'m trying to delete a file. I know what the issue is, I just don\'t know how to set the permissions correctly.

I'm trying to delete a file. I know what the issue is, I just don't know how to set the permissions correctly.

My current setup is Ubuntu 10.10 Netbeans and upload via FTP to my development server.

These are the steps I did in order to get Apache2 and VSTPD

  1. set up vsftpd for umask 0027 (/etc/vsftpd.conf) [local_umask=0027开发者_运维百科]
  2. create www-users group (groupadd www-users)
  3. add linux_server_user to group (usermod -a -G group linux_server_user)
  4. Set apache to run as www-users group (httpd.conf)
  5. chgrp www-users /var/www
  6. chmod 2775 /var/www

I'm guessing I need to give apache permission to write over the files that I upload from the FTP. How do I accomplish this?


Let's see your access mode:

2775
 ^^^
 ||'- read/exec by everyone in different groups
 |'-- read/write/exec by group only
 '--- read/write/exec by user only

That last flag should be at least 6 (read/write by other groups).

That said, there are corner cases when this is absolutely not possible (chmod, unlink etc all fail).

This is the exact reason why major new systems (eg wordpress and joomla) offer to do file modifications (programmatically) via FTP.

This is done by supplying a DSN to unlink:

unlink('ftp://user:pass@host/absolute/path/to/file');

In some cases, allow_url_fopen can be disabled, in which case you will have to stream_wrapper_register() your own FTP class.

I've found that PHP's FTP functions are quite problematic and that it seems to work best when I use CURL's.


You might have to check your ftp user and see if he has permission to delete files, some users are only given read only permissions. If you're trying to unlink() via PHP, then you might have to CHMOD the file to 777 before it can be done.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号