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/