Laravel deployment cache until server restart

2019-06-14 06:06发布

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条回答
Emotional °昔
2楼-- · 2019-06-14 06:37

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.

查看更多
登录 后发表回答