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 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题