Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

Laravel Framework cache does not get renewed

We use PHP Deployer to deploy our Laravel Vue app. Issue seems to be that Framework cache in ~/staging.site.com/shared/storage/framework/cache/ does not get emptied on deployment using this configuration or deploy.yml file

import:
  - recipe/laravel.php
  - contrib/php-fpm.php
  - contrib/npm.php

config:
  application: 'our-app'
  # remote_user: forge
  deploy_path: '~/{{hostname}}'
  repository: '[email protected]:site/our-app.git'
  php_fpm_version: '8.1'
  keep_releases: '10'
  shared_files: 
    - '.env'
    - '.transip_private_key'
    - 'storage/app/exact.api.json'
  shared_dirs:
    - 'bootstrap/cache'
    - 'public/sitemaps'
    - 'public/uploads'
    - 'public/published'
    - 'public/images'
    - 'public/downloads'
    - 'storage/framework/cache'
    - 'storage/framework/sessions'
    - 'storage/framework/views'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'
    - 'storage/app/projects'
  writable_dirs:
    - 'public/sitemaps'
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework'
    - 'storage/framework/cache'
    - 'storage/framework/cache/data'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'
    - 'storage/app/projects'

hosts:
  prod:
    hostname: 'site.com'
    # remote_user: forge
    # hostname: 'xx.xx.xxx.xx'
    # deploy_path: '~/site.com'
    remote_user: ploi
  staging:
    hostname: 'staging.site.com'
    remote_user: ploi

tasks:
  deploy:
    - deploy:prepare
    - deploy:vendors
    - artisan:storage:link
    - artisan:view:cache
    - artisan:config:cache
    - artisan:optimize
    - artisan:migrate
    # - npm:install
    # - npm:run:prod
    - artisan:queue:restart    
    - artisan:horizon:terminate
    - deploy:publish
  # npm:run:prod:
  #   - run: 'cd {{release_path}} && npm run prod'

after:
  # php fpm reload not needed post nginx update
  # deploy:symlink: php-fpm:reload 
  deploy:failed: deploy:unlock

when we check cache is from March 2023 when we first added the app to this new Hetzner server

~/staging.app.com/shared/storage/framework/cache/data/dd/c7$ ll
total 12
drwxrwxr-x+ 2 ploi ploi 4096 Mar 22  2023 ./
drwxrwxr-x+ 3 ploi ploi 4096 Mar 22  2023 ../
-rw-rw-r--+ 1 ploi ploi   22 Mar 22  2023 ddc7b4b589f5dd6ee935c9921cfd3798fea8c459

Why is that? Is it because we use these Artisan command and we should do something else to rebuild all? Or we forgot something?

- artisan:view:cache
- artisan:config:cache
- artisan:optimize

Is it something with rights? We do use user ploi and everything gets deployed all the time and chmod rights seems fine.. So what are we missing?

0 likes
3 replies
LaryAI's avatar
Level 58

It seems that your deployment process is missing a step to clear the cache. The commands you listed (artisan:view:cache, artisan:config:cache, and artisan:optimize) are for caching the views, configuration, and optimizing the framework for better performance, respectively. However, to ensure that the cache is cleared and rebuilt, you should include the artisan:cache:clear command in your deployment process.

Here's how you can modify your deploy.yml file to include the cache clearing step:

tasks:
  deploy:
    - deploy:prepare
    - deploy:vendors
    - artisan:storage:link
    - artisan:cache:clear # Add this line to clear the cache
    - artisan:view:cache
    - artisan:config:cache
    - artisan:optimize
    - artisan:migrate
    - artisan:queue:restart    
    - artisan:horizon:terminate
    - deploy:publish

By adding the artisan:cache:clear command, you ensure that the application's cache is cleared on each deployment. This should resolve the issue of the cache not being updated.

Additionally, if you are using Laravel's cache tags or driver-specific features, make sure that the cache driver you are using supports those features. For example, the file cache driver does not support cache tags.

If you continue to experience issues, you may want to verify the permissions of the cache directory to ensure that the ploi user has the necessary permissions to write to and delete files within ~/staging.site.com/shared/storage/framework/cache/. You can check and fix the permissions with the following commands:

# Navigate to the shared storage directory
cd ~/staging.site.com/shared/storage

# Recursively set the correct permissions for the framework cache directory
sudo chown -R ploi:ploi framework/cache
sudo chmod -R u+rwX,go+rX,go-w framework/cache

Replace ploi:ploi with the appropriate user and group for your server environment if different. The chmod command sets read and write permissions for the user, and read permissions for the group and others, while ensuring that directories are executable (which is necessary for directory access).

After making these changes, try deploying again and check if the cache is properly cleared and rebuilt.

1 like
rhand's avatar
Level 6

The cache clearing added to deployment using

- artisan:cache:clear # Add this line to clear the cache

but do not see update yet. No errors either on deployment though and 775 for directories and 664 for files should be fine under ploi:ploi

~/staging.site.com/shared/storage/framework/cache$ ll
total 16
drwxrwxr-x+ 3 ploi ploi 4096 Mar 22  2023 ./
drwxrwxr-x  5 ploi ploi 4096 Mar 22  2023 ../
drwxrwxr-x+ 3 ploi ploi 4096 Mar 22  2023 data/
-rw-rw-r--  1 ploi ploi   14 Mar 22  2023 .gitignore

and

~/staging.site.com/shared/storage/framework$ ll
total 104
drwxrwxr-x  5 ploi ploi  4096 Mar 22  2023 ./
drwxrwxr-x  6 ploi ploi  4096 Mar 22  2023 ../
drwxrwxr-x+ 3 ploi ploi  4096 Mar 22  2023 cache/
drwxrwxr-x  2 ploi ploi 65536 Nov 24 03:59 sessions/
drwxrwxr-x  2 ploi ploi 20480 Nov 24 04:23 views/
~/staging.sitecom/shared/storage/framework$ stat -c "%a %n" *
775 cache
775 sessions
775 views

and symlinks to these guys

~/staging.site.com/current/storage/framework$ ll
total 12
drwxrwxr-x+ 2 ploi ploi 4096 Nov 24 04:22 ./
drwxrwxr-x  7 ploi ploi 4096 Nov 24 04:22 ../
lrwxrwxrwx  1 ploi ploi   42 Nov 24 04:22 cache -> ../../../../shared/storage/framework/cache/
-rw-rw-r--  1 ploi ploi  119 Nov 24 04:20 .gitignore
lrwxrwxrwx  1 ploi ploi   45 Nov 24 04:22 sessions -> ../../../../shared/storage/framework/sessions/
lrwxrwxrwx  1 ploi ploi   42 Nov 24 04:22 views -> ../../../../shared/storage/framework/views/
rhand's avatar
rhand
OP
Best Answer
Level 6

The app uses CACHE_DRIVER=redis so I should not check /shared/framework/cache but Redis cache

redis-cli INFO | grep ^db
db0:keys=16,expires=4,avg_ttl=69945
db1:keys=7,expires=0,avg_ttl=0

and

ploi@app-staging-cx21-fs1:~/staging.app.com/current$ redis-cli -n 1 keys "*"
1) "app_staging_database_app_staging_cache_:6ecce696ff2e75d571bd1c9c150c6037ff52ec39:html.132"
2) "app_staging_database_app_staging_cache_:656045d323b93227863498:forever_ref"
3) "app_staging_database_app_staging_cache_:6ecce696ff2e75d571bd1c9c150c6037ff52ec39:projects.17.menus.130"
4) "app_staging_database_app_staging_cache_:6ecce696ff2e75d571bd1c9c150c6037ff52ec39:projects.17.menus.138"
5) "app_staging_database_app_staging_cache_:6ecce696ff2e75d571bd1c9c150c6037ff52ec39:projects.17.modules.132.desktop"
6) "app_staging_database_app_staging_cache_:tag:projects.17:key"
7) "app_staging_database_app_staging_cache_:6ecce696ff2e75d571bd1c9c150c6037ff52ec39:projects.17.menus.

and when I run php artisan cache:clear all does work.

php artisan cache:clear
 INFO  Application cache cleared successfully.
ploi@app-staging-cx21-fs1:~/staging.site.com/current$ redis-cli -n 1 keys "*"
(empty array)

So panic for nothing

Please or to participate in this conversation.