【问题标题】:Post-receive hook to /var/www/html and permissions到 /var/www/html 和权限的后接收挂钩
【发布时间】:2018-09-13 07:46:57
【问题描述】:

我在我的 Centos 7 VPS 上创建了一个 wordpress 登台遥控器。 Wordpress 安装在此目录/var/www/html 中,组/所有者是默认的apache:apache。 然后我在~/git/repopost-receive 上创建了一个裸git repo,并在hooks 中使用这个bash 脚本:

#!/bin/sh
TARGET=/var/www/html/wp-content
GIT_DIR=/home/username/git/repo

#(1) Change directory's ownership to allow writing
sudo chown -R username:apache /var/www/html

#run 'post-receive' hook
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f

#(2) return to original 
sudo chown -R apache:apache /var/www/html

让我解释一下。 (1) = 因为否则我无法在该目标目录中写入任何内容,所以我必须将所有权更改为我当前的用户名。 (2) = 因为否则,通过维护 username:apache 我无法通过 wordpress 管理前端安装任何东西:FTP 权限凭据输入。

在我的本地环境中,我在 wordpress 安装的wp-content 创建了工作 git 存储库并链接到远程。 现在,问题是当我使用 GIT bash 或 Sourcetree 推送更改时,文件被传输到裸远程仓库,但接收后脚本由于其 sudo 命令而失败。

你对我有什么建议?

【问题讨论】:

  • 没人能帮我解决这个问题吗?

标签: wordpress git git-remote git-post-receive git-bare


【解决方案1】:

我正在寻找类似的解决方案。到目前为止,这是我正在使用的两个部分:

1) 接收后挂钩:

    #!/bin/bash
    TARGET="/var/www"
    GIT_DIR="/home/<username>/repo.git"
    BRANCH="master"

    while read oldrev newrev ref
    do
        # only checking out the master (or whatever branch you would like to deploy)
        if [[ $ref = refs/heads/$BRANCH ]];
        then
            echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
            git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
        else
            echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
        fi
    done

2) 通过组权限获得写入权限

    $ sudo usermod -a -G www-data <username>
    $ sudo chmod -R g+w /var/www/domainname/public_html

在您的情况下,www-data 将替换为拥有您需要写入权限的目录的 GROUP。在 root 拥有服务目录之前,我愿意这样做。

需要明确的是,这些想法来自两个不同的来源。我将它们一起使用并将它们作为我发现对我有用的单一解决方案传递。已包含指向原始来源的链接以供参考。

参考资料:

FWIW,我还对 repo 和裸 repo 之间的差异以及对 --git-dir 的引用表示不满(致命:...不是 git 存储库...) .

祝你好运

【讨论】:

    猜你喜欢
    • 2018-09-17
    • 2012-09-06
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    相关资源
    最近更新 更多