【问题标题】:Laravel Continuous Integration with Gitlab-runner in offline environment (CentOS 7)Laravel 在离线环境中与 Gitlab-runner 持续集成(CentOS 7)
【发布时间】:2017-05-01 06:30:42
【问题描述】:

我正在完全离线的环境中开发一个网站。另外,我使用 gitlab runner 进行 CI,主机是 CentOS 7。

问题是 gitlab runner 在 centos 上使用 gitlab-runner 用户来部署 laravel 应用程序,而 apache 使用 apache 用户来运行 laravel。 我在 apache 上收到 Permission denied 错误,直到我更改了文件的所有权。之后我在 apache 日志上得到这个错误:

Uncaught UnexpectedValueException: The stream or file "storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

似乎像monolog 这样的一些供应商库想要将错误或调试日志写入storage/logs/laravel.log,但它的权限被拒绝。 :(

.gitlab-ci.yml

stages:
  - build
  - test
  - deploy

buildBash:
  stage: build
  script:
    - bash build.sh

testBash:
  stage: test
  script:
    - bash test.sh

deployBash:
  stage: deploy
  script:
    - sudo bash deploy.sh

build.sh

#!/bin/bash

set -xe

# creating env file from production file
cp .env.production .env

# initializing laravel
php artisan key:generate
php artisan config:cache

# database migration
php artisan migrate --force

deploy.sh

#!/bin/bash

PWD=$(pwd)'/public'
STG=$(pwd)'/storage'

ln -s $PWD /var/www/html/public
chown apache.apache -R /var/www/html/public
chmod -R 755 /var/www/html/public
chmod -R 775 $STG

我使用 gitlab runner 正确吗?如何解决权限被拒绝错误?

【问题讨论】:

    标签: apache continuous-integration centos7 gitlab-ci gitlab-ci-runner


    【解决方案1】:

    SELinux

    我发现了问题,它是 selinux,像往常一样是 selinux,我一开始就忽略了它


    有什么问题

    您可以使用ls -lZ 命令查看文件上的selinux 上下文,默认情况下www 上的所有文件都是httpd_sys_content_t,问题是selinux 只允许apache 读取这些文件。您应该更改 storagebootstrap/cache 上下文,使其可写。

    有 4 种 apache 上下文类型:

    • httpd_sys_content_t:只读目录和文件
    • httpd_sys_rw_content_t:Apache使用的可读写目录和文件
    • httpd_log_t:Apache 用于日志文件和目录
    • httpd_cache_t:被 Apache 用于缓存文件和目录

    做什么:

    首先安装policycoreutils-python 以获得更好的命令

    yum install -y policycoreutils-python

    安装policycoreutils-python 后,semanage 命令可用,因此您可以像这样更改文件上下文:

    semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/laravel/storage(/.*)?" semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/laravel/bootstrap/cache(/.*)?"

    不要忘记通过此命令提交更改:

    restorecon -Rv /var/www/html/laravel/storage restorecon -Rv /var/www/html/laravel/bootstrap/cache

    问题解决了:)

    参考:http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/

    【讨论】:

      猜你喜欢
      • 2014-02-09
      • 2020-01-29
      • 2019-11-28
      • 2016-01-16
      • 2010-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多