Heroku PHP应用程序无法写入雪松堆栈上的文件系统

Heroku PHP应用程序无法写入雪松堆栈上的文件系统

问题描述:

I have a couple Heroku CakePHP apps running on the cedar stack. My app is erroring out on every request when the cache engine tries to write out to a file.

[Sat Feb 09 05:56:51 2013] [error] [client x.x.x.x] PHP Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /app/www/lib/Cake/Cache/Cache.php:165
Stack trace:
#0 /app/www/lib/Cake/Cache/Cache.php(135): Cache::_buildEngine('_cake_core_')
#1 /app/www/app/Config/core.php(277): Cache::config('_cake_core_', Array)
#2 /app/www/lib/Cake/Core/Configure.php(76): include('/app/www/app/Co...')
#3 /app/www/lib/Cake/bootstrap.php(163): Configure::bootstrap(true)
#4 /app/www/app/webroot/index.php(82): include('/app/www/lib/Ca...')
#5 {main}
thrown in /app/www/lib/Cake/Cache/Cache.php on line 165

2013-02-09T05:56:51+00:00 app[web.1]: [Sat Feb 09 05:56:51 2013] [error] [client x.x.x.x] PHP Warning: /app/www/app/tmp/cache/persistent/ is not writable in /app/www/lib/Cake/Cache/Engine/FileEngine.php on line 336

2013-02-09T05:56:51+00:00 app[web.1]: [Sat Feb 09 05:56:51 2013] [error] [client x.x.x.x] PHP Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /app/www/lib/Cake/Cache/Cache.php on line 309

I thought dynos on the cedar stack have writable ephemeral filesystems. Why am I getting not writable errors, and what can I do to fix them?

我在雪松堆上运行了几个Heroku CakePHP应用程序。 当缓存引擎尝试写出文件时,我的应用程序在每个请求上都出错。 p>

[Sat Feb 09 05:56:51 2013] [错误] [client xxxx] PHP致命错误:未捕获异常'CacheException',消息'Cache engine _cake_core_未正确配置'。 在/app/www/lib/Cake/Cache/Cache.php:165
堆栈跟踪:
#0 /app/www/lib/Cake/Cache/Cache.php(135): Cache :: _ buildEngine('_ cake_core_')
#1 /app/www/app/Config/core.php(277):Cache :: config('_ cake_core_',Array)
#2 /app/www/lib/Cake/Core/Configure.php(76):include('/ app / www / app / Co ...')
#3 / app / www / lib / Cake / bootstrap.php(163):配置:: bootstrap(true)
#4 /app/www/app/webroot/index.php(82):include('/ app / www / lib / Ca .. 。')
#5 {main}
在第165行的/app/www/lib/Cake/Cache/Cache.php中抛出 p>

2013- 02-09T05:56:51 + 00:00 app [web.1]:[Sat Feb 09 05:56:51 2013] [错误] [客户端xxxx] PHP警告:/ app / www / app / tmp / cache / 持久性/在第336行的/app/www/lib/Cake/Cache/Engine/FileEngine.php中无法写入 p>

2013-02-09T05:56:51 + 00:00 app [web.1]:[Sat Feb 09 05:56:51 2013] [错误] [客户端xxxx] PHP警告:_ cake_core_ cache无法将'cake_dev_en-us'写入/ app / www / lib / Cake中的文件缓存 /Cache/Cache.php上 第309行 p> blockquote>

我认为雪松堆上的dynos有可写的短暂文件系统。 为什么我得不到可写错误,我该怎么做才能修复它们? p> div>

Your best bet would be to configure an actual cache system like Memcahier or even Redis. While you can normally write to the dynos, you have limited space and it will be lost on restart, and cause issues if you're using more than one dyno.

This specific instance could be explained by limitations in the apache conf, or dir settings in the buildpack. I'm sure not all directories are writable. If you run 'heroku run bash' and get a shell into your app, does the directory exist, and what are its permissions?

This specific problem has nothing to do with Heroku.

CakePHP's default gitignore ignores the tmp directory. The tmp directory structure was never committed into my new app and therefore didn't exist when deployed to Heroku.

So, when starting a new CakePHP app, take care to actually commit the tmp directories into your repository.