You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel权限错误求助:file_put_contents打开流失败(附具体路径)

Fixing Laravel Permission Denied Error for file_put_contents

Hey there, let's get this permission error sorted out—your Laravel app is trying to write to the /var/www/html/{project_name}/public/temp/ttfontdata directory, but it doesn't have the right access to do so. Here's how to fix it:

Step 1: Ensure the target directory exists

First, double-check that the temp/ttfontdata folder actually exists. If it's missing, create it with this command (replace {project_name} with your actual project name):

mkdir -p /var/www/html/{project_name}/public/temp/ttfontdata

The -p flag ensures all parent directories (like temp if it's also missing) are created automatically.

Step 2: Set the correct directory ownership

Your web server (usually www-data for Apache/Nginx on Debian/Ubuntu, or apache on CentOS/RHEL) needs to own this directory to write to it. Run this command:

chown -R www-data:www-data /var/www/html/{project_name}/public/temp

If you're on a CentOS/RHEL system, swap www-data with apache in the command above.

Step 3: Assign secure functional permissions

Next, set permissions that are secure but let the web server do its job. Directories need execute permissions to be traversed, so we'll use 755 for directories and 644 for files:

chmod -R 755 /var/www/html/{project_name}/public/temp

If you're working in a team where multiple users need access, you can use 775 instead (just make sure your user is part of the web server's group, like www-data). Never use 777—it’s a critical security risk.

Step 4: Check SELinux (for RHEL/CentOS-based systems)

If your server has SELinux enabled (common on CentOS/RHEL), it might block the web server from writing even if file permissions are correct. Fix the SELinux context with:

chcon -R -t httpd_sys_rw_content_t /var/www/html/{project_name}/public/temp

This tells SELinux that the web server is allowed to read and write to this directory.

Quick reminders

  • Don’t forget to replace {project_name} with your actual Laravel project folder name.
  • If you’re using Docker, make sure permissions inside the container match—you might need to set ownership in your Dockerfile or adjust volume permissions when starting the container.
  • After making changes, test your app again to confirm the error is resolved.

内容的提问来源于stack exchange,提问作者RaedN

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 20:32:53