Laravel deployment cache until server restart

风流意气都作罢 提交于 2020-01-03 06:04:11

问题


When I deployed my Laravel 4.2.9 application to a Ubuntu 14.04 server using Capistrano, it seems like all my php files are being cached by PHP, Laravel or Nginx. I have to manually restart the server to bust the cache and see any of my changes.

Capistrano creates a new release directory on the server and runs a git checkout inside to get te last tagged version. When the deploy has been completed, the 'current' symlink will be updated to point to the the new release directory. The only shared files are my uploads directory and my environment settings file.

Things I've tried:

  • php artisan cache:clear
  • composer dump-autoload

Only a manual server restart after deployment will bust the cache, which comes with a downtime (also for other sites hosted on that server) and extra risks.

Anyone have a suggestion whether this could be Nginx, PHP or Laravel itself?


回答1:


I was having a similar problem when deploying my Laravel 5 application and seem to have solved it by adding the following to the end of Capistrano's deploy.rb:

namespace :deploy do
    desc "Build"
    after :updated, :build do
        on roles(:web) do
            within release_path  do
                execute :composer, "install --no-dev --quiet"
                execute :php, "artisan clear-compiled"
                execute :php, "artisan cache:clear"
                execute :php, "artisan view:clear"
                execute :php, "artisan twig:clean" # For use with TwigBridge
                execute :php, "artisan route:cache"
                execute :php, "artisan config:cache"
            end
        end
    end
end

(If you aren't using TwigBridge, be sure to remove the twig:clean line.)

Edited to include the clear-compiled and view:clear lines, as these seem to solve additional problems with deploying Laravel applications using Capistrano.



来源:https://stackoverflow.com/questions/29594173/laravel-deployment-cache-until-server-restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!