首页 > 解决方案 > 没有作曲家、npm、git 的 Laravel 自定义部署 - 出现错误“无效的路由操作”,但通过一些尝试解决了

问题描述

我在使用AdminLTEJetstream为Laravel项目进行自定义首次部署时遇到了几个问题,我无法解决这些问题,即使经过一些尝试应用程序可以正常工作,我也不明白问题出现的原因和位置以及如何以获得稳定的部署。

让我解释一下:生产服务器没有安装composer 和 npm 和 git(我无法安装它们),因此我创建了一个干净的 tar 存档以上传到服务器上,这些是我的分步命令序列我的本地开发者设备

composer install --no-interaction --prefer-dist --optimize-autoloader
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan clear-compiled
npm install
npm run production
tar --transform='flags=r;s|.env.production|.env|' -czvf bin/archive/MYARCHIVE-VERSION.tar.gz --exclude='.git' --exclude='.idea' --exclude='.editorconfig' --exclude='.env' --exclude='.env.example' --exclude='.gitattributes' --exclude='.gitignore' --exclude="storage/logs/*.log

然后,我将 tar 存档上传到生产服务器上,并在服务器上启动以下命令序列(使用 sudo 或以 root 身份):

# deleting the content of the project directory
rm -R /var/www/MYPROJECT/{*,.*}

# unpacking the tar I've just uploaded
tar -xf /somewhere/MYARCHIVE-VERSION.tar.gz /var/www/MYPROJECT/

# down of app and executing the migration
php artisan down
php artisan migrate

# recreating the log file to avoid some permission errors
touch /var/www/MYPROJECT/storage/logs/laravel.log

# changing permissions of various files
chmod -R 777 /var/www/MYPROJECT/storage /var/www/MYPROJECT/bootstrap/cache
chown -R www-data:www:data /var/www/MYPROJECT/{*,.*}

# generating the app key, if is the first deploy (actually, this is my case: in the .env file the APP_KEY is empty)
php artisan key:generate

# cleaning config, cache, etc, etc
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan clear-compiled
php artisan auth:clear-resets
php artisan optimize

# restart app and webserver
php artisan up
systemctl restart apache2

好的,当我重新启动 apache 时,总是出现错误:我调用的 EVER 路由的 INVALID ROUTE ACTION,例如 /dashboard:

Invalid route action: [C:32:"Opis\Closure\SerializableClosure":210:{a:5:{s:3:"use";a:0:{}s:8:"function";s:44:"function () { return \view('dashboard'); }";s:5:"scope";s:37:"Illuminate\Routing\RouteFileRegistrar";s:4:"this";N;s:4:"self";s:32:"0000000049110cda00000000033dff1d";}}].

我猜问题出在缓存或密钥中:经过一些尝试,应用程序可以正常工作。例如,如果我重新生成应用程序密钥,然后重新优化php artisan optmize两次,应用程序实际上可以工作!

错误在哪里?

感谢任何提示,谢谢。

标签: laraveldeployment

解决方案


您的某些路线可能已关闭。

当您调用php artisan optimize,$this->call('route:cache');将被执行,并且您的路线将从缓存文件中加载。这可以解释为什么它可以解决您的问题。

确保php artisan route:cache在每次部署后调用,或将路由定义中的闭包移动到控制器。


推荐阅读