如何在Elastic Beanstalk上运行Laravel数据库队列



我是AWS EB的新手,但能够在64位Amazon Linux 2/3.3.9 Laravel API上设置PHP 8.0。

我想在数据库队列中使用php artisan queue:listen运行一些作业。我关注了这个Stack Exchange问题然而,当我推送代码时,脚本不会运行,因为作业没有执行

使用这个问题,我可以手动将SSH连接到EC2实例中,并在/opt/elasticbeanstalk/deployment/env中手动设置env变量。然后当我运行php artisan queue:listen时,它就工作了!

如何设置脚本,使其在EC2/EB实例启动和队列上的作业运行时运行?

PS:我的环境配置正在运行,数据库配置也在运行

这是我当前的脚本设置:

./.ebextensions/01-setup.config

container_commands:
    01-no_dev:
        command: "composer.phar install --optimize-autoloader --no-dev"
    02-config_clear:
        command: "php artisan config:clear"
    03-view_clear:
        command: "php artisan view:clear"
    04-route_cache:
        command: "php artisan route:cache"
    05-view_cache:
        command: "php artisan view:cache"
    06-migrate:
        command: "php artisan migrate --force"
        leader_only: true
    07-queue_service_restart:
        command: "systemctl restart laravel_worker"
files:
    /opt/elasticbeanstalk/tasks/taillogs.d/laravel-logs.conf:
        content: /var/app/current/storage/logs/laravel.log
        group: root
        mode: "000755"
        owner: root
    /etc/systemd/system/laravel_worker.service:
        mode: "000755"
        owner: root
        group: root
        content: |
            # Laravel queue worker using systemd
            # ----------------------------------
            #
            # /lib/systemd/system/queue.service
            #
            # run this command to enable service:
            # systemctl enable queue.service
            [Unit]
            Description=Laravel queue worker
            [Service]
            User=nginx
            Group=nginx
            Restart=always
            ExecStart=/usr/bin/nohup /usr/bin/php /var/www/html/artisan queue:work //is this line correct???
            [Install]
            WantedBy=multi-user.target

.platformnginxconf.delasticbeanstalklaravel.conf

location / {
    try_files $uri $uri/ /index.php?$query_string;
    gzip_static on;
}

./.ebextensions/cron-linux.config

files:
    "/etc/cron.d/schedule_run":
        mode: "000644"
        owner: root
        group: root
        content: |
            * * * * * root . /opt/elasticbeanstalk/deployment/env && /usr/bin/php /var/app/current/artisan schedule:run 1>> /dev/null 2>&1
commands:
    remove_old_cron:
        command: "rm -f /etc/cron.d/*.bak"

如果您的脚本/应用程序依赖于不在.env中但作为操作系统环境变量加载的变量,则默认情况下您的cron将无法访问这些变量。

除非您导出带有:env>gt/etc/environment启动cron之前。

最新更新