0

我正在一个完全离线的环境中开发一个网站。还有,我用gitlab转轮CI和主机是CentOS的7Laravel在离线环境下与Gitlab-runner持续集成(CentOS 7)

问题是gitlab亚军使用gitlab-runner用户在CentOS部署laravel应用和Apache使用apache用户运行laravel。 我得到了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运行正确吗?我如何解决权限被拒绝的错误?

回答

0

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用于日志文件和目录
  • http d_cache_t:缓存文件和目录的Apache使用

怎么办:

首先是为了更好的命令

yum install -y policycoreutils-python

安装policycoreutils-python安装policycoreutils-pythonsemanage命令后是可用的,所以你可以像这样改变文件上下文:

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/