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.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题