Laravel缓存在生产服务器上不会存储缓存文件

4
我在使用 Laravel 缓存系统时遇到了问题(我使用的是 Laravel 4.1)。
  1. 在我的本地服务器上,Laravel 存储缓存文件的“app/storage”文件夹具有755权限。
  2. 在我的生产服务器上,相同的文件夹具有相同的权限代码。
  3. 在我的本地服务器上,当我使用 Laravel 的缓存类缓存数据时,它可以正常工作。因此,如果我进入“app/storage”文件夹,我可以看到创建的文件。
  4. 在我的生产服务器上,它不行... "app/storage"中的缓存文件没有被创建,而 session 和 views 文件夹(位于 app/storage 中)中有文件存储。我可以确认这一点,因为即使我使用 Cache 类的 put 方法将我的 $datas 放入其中,它仍然始终进入我的 if 语句中的 has 方法。

编辑

/*
|--------------------------------------------------------------------------
| Default Cache Driver
|--------------------------------------------------------------------------
|
| This option controls the default cache "driver" that will be used when
| using the Caching library. Of course, you may use other drivers any
| time you wish. This is the default when another is not specified.
|
| Supported: "file", "database", "apc", "memcached", "redis", "array"
|
*/

'driver' => 'file',

/*
|--------------------------------------------------------------------------
| File Cache Location
|--------------------------------------------------------------------------
|
| When using the "file" cache driver, we need a location where the cache
| files may be stored. A sensible default has been specified, but you
| are free to change it to any other place on disk that you desire.
|
*/

'path' => storage_path(). DIRECTORY_SEPARATOR . 'cache',

/*
|--------------------------------------------------------------------------
| Database Cache Connection
|--------------------------------------------------------------------------
|
| When using the "database" cache driver you may specify the connection
| that should be used to store the cached items. When this option is
| null the default database connection will be utilized for cache.
|
*/

'connection' => null,

/*
|--------------------------------------------------------------------------
| Database Cache Table
|--------------------------------------------------------------------------
|
| When using the "database" cache driver we need to know the table that
| should be used to store the cached items. A default table name has
| been provided but you're free to change it however you deem fit.
|
*/

'table' => 'cache',

/*
|--------------------------------------------------------------------------
| Memcached Servers
|--------------------------------------------------------------------------
|
| Now you may specify an array of your Memcached servers that should be
| used when utilizing the Memcached cache driver. All of the servers
| should contain a value for "host", "port", and "weight" options.
|
*/

'memcached' => array(

    array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100),

),

/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing a RAM based store such as APC or Memcached, there might
| be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions.
|
*/

'prefix' => 'laravel',

Do you have any idea about what I'm doing wrong ?


你能展示一下/app/config/cache.php或者其他你正在使用的缓存配置文件吗? - Jerodev
我编辑了我的帖子以展示我的配置文件。 - KeizerBridge
你确定存储目录中包含的文件和文件夹具有正确的权限级别吗? - Matt Burrow
4
755 表示所有者权限为 7,群组权限为 5,其他用户权限为 5。您确定用来创建存储文件夹的用户与运行 Apache 的用户相同吗?否则,Apache 将无法访问该文件夹。 - dasper
就像@dasper在最后一条一年前的评论中所说,问题可能是由于目录的所有者与Web服务器使用的所有者不同所致。通常情况下,但并非总是如此,Apache的用户是“www-data”或“apache”。 - Gustavo Straube
显示剩余4条评论
1个回答

3

将文件夹的权限从755更改为777,以查看是否有效。如果缓存现在可以正常工作,则表示存在权限问题。将其设置回755,并确保您的Web服务器使用的用户是文件夹的所有者。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接