想知道如何改进此bash脚本以设置laravel目录和文件权限?

问题描述 投票:0回答:1

为laravel的文件权限创建此文件,已在终端中厌倦了此操作。httpd的用户组是Fedora中的apache。用bash编写,将其放入我的项目文件夹中,似乎可以正常工作。想知道我如何才能使它变得更实用或更小?或对此有任何想法。

#! /bin/bash
if [ -f artisan ]; then
    sudo chown -R $USER:apache $PWD
    sudo find $PWD -type f -exec chmod 644 {} \;
    sudo find $PWD -type d -exec chmod 755 {} \;
    sudo chgrp -R apache storage bootstrap/cache
    sudo chmod -R ug+rwx storage bootstrap/cache
    echo "file permissions all set"
else
    echo 'Artisan command does not exist are you in the laravel installation base directory';
fi
bash file-permissions laravel-6
1个回答
0
投票

为什么不使用Laravel的Envoy运行此类特定任务?首先,全局安装Envoy。

composer global require laravel/envoy

然后在根目录中创建一个名为Envoy.blade.php的文件。

Envoy.blade.php

@setup
    $chmods = [
        'storage',
        'bootstrap/cache',
    ];
@endsetup

@servers(['local' => '127.0.0.1'])

@story('deploy')
    permissions
    finishDeploy
@endstory

@task('permissions')
    @foreach($chmods as $file)
        chmod -R 755 {{ $file }}
        chmod -R g+s {{ $file }}
        chown -R apache:apache {{ $file }};
        echo "Permissions have been set for {{ $file }}."
    @endforeach
    echo "File permissions complete."
@endtask

@task('finishDeploy')
    echo 'Deployment finished successfully!'
@endtask

在终端中,您可以使用以下命令来运行它。

envoy run deploy
© www.soinside.com 2019 - 2024. All rights reserved.