dongxing7083 2015-02-13 15:44
浏览 116

如何给git创建的某些目录提供PHP写访问权限?

There are several similar questions on here, such as this one, but the answer to that question (and several others I read) is:

let PHP create the directory itself in the first place.

I use git on my site, so it's not possible to allow PHP to "create the directory itself."

To pull in changes, I run a git pull origin master command when logged into my server via SSH, which makes the owner of the files my cpanel user I'm logged in as.

I need PHP to be able to create files in certain directories. Is the only way to allow this to chmod the folders to 777, or is there a better way?

I don't have a good understanding of Linux permissions, but from what I've read changing directory and file permissions to 777 is generally not a good idea. Furthermore, if I chmod the folders to 777, I suspect the permissions will be overwritten when I run git pull origin master, although I haven't tested this.

  • 写回答

2条回答

  • duanfan8360 2015-02-13 15:56
    关注
    1. Git won’t override permissions on already existing directories.
    2. You should check under what user apache (or whatever http server you use) is running.

    It would be likely www-data for apache:

    ps aux | grep http | cut -f 1 -d ' '
    
    1. As soon as you know the user, https server is running as, do change the owner.

    This shell command is fine:

    chown -R www-data FOLDER_PHP_NEEDS_TO_WRITE_TO
    

    The above will set the owner of the folder to www-data, apparently giving a write permission for https server to write there.

    Whether you are afraid of loosing control over this directory, do it via group permission:

    chgrp -R www-data FOLDER_PHP_NEEDS_TO_WRITE_TO
    chmod -R g+w FOLDER_PHP_NEEDS_TO_WRITE_TO
    

    Now you are still the owner, while http server is able to write there because it belongs to this group. You might do it other way, adding yourself to www-data group and giving write permissions for that group to the desired folder.

    Another option is to run git as www-data:

    sudo runuser -l  www-data -c 'git pull'
    

    But I would suggest the solution with group.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!