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

aidysproule's avatar

Laravel Deployment - Permission errors

I'm trying to deploy a Laravel app but I'm getting a 'file_put_contents' permissions error, full error below. I've ran the following permissions commands but it still hasn't worked.

sudo chown -R $USER:nginx /var/www/example.com/ sudo chmod -R 775 /var/www/example.com/storage sudo chmod -R 775 /var/www/example.com/bootstrap/cache

Each of the folders below /storage has the $USER:nginx set. I've put a temporary web shell in place to check what user nginx is running as and it is the 'nginx' user.

I've Googled for the past 2 days and can not get it to work. It's a fresh setup on AWS and can be blown away and re-built easily if needed. I've re-built the server this morning from scratch.

Any help will be greatly appreciated.

Thanks in advance.

Full error: file_put_contents(/var/www/example.com/storage/framework/views/012ae97320bad8ccbcf38c57fd8d2b1e.php): Failed to open stream: Permission denied

0 likes
3 replies
LaryAI's avatar
Level 58

To resolve the 'file_put_contents' permissions error when deploying a Laravel application, you need to ensure that the web server user (in this case, nginx) has the correct permissions to write to the necessary directories. Here are the steps you can follow to fix this issue:

  1. Verify Ownership and Permissions:

    Ensure that the storage and bootstrap/cache directories are owned by the nginx user and group. You can do this by running:

    sudo chown -R nginx:nginx /var/www/example.com/storage
    sudo chown -R nginx:nginx /var/www/example.com/bootstrap/cache
    
  2. Set Correct Permissions:

    Set the correct permissions for these directories to ensure they are writable by the web server:

    sudo chmod -R 775 /var/www/example.com/storage
    sudo chmod -R 775 /var/www/example.com/bootstrap/cache
    

    The 775 permission allows the owner and group to read, write, and execute, while others can only read and execute.

  3. Check SELinux (if applicable):

    If your server is running SELinux, it might be blocking the write operations. You can temporarily disable SELinux to see if it resolves the issue:

    sudo setenforce 0
    

    If this resolves the issue, you may need to configure SELinux policies to allow the necessary write operations.

  4. Verify Nginx User:

    Double-check that Nginx is indeed running as the nginx user. You can check the Nginx configuration file (usually located at /etc/nginx/nginx.conf) to confirm the user directive:

    user nginx;
    
  5. Restart Nginx:

    After making these changes, restart Nginx to ensure all configurations are applied:

    sudo systemctl restart nginx
    
  6. Check for Other Issues:

    If the problem persists, check the Laravel logs located in storage/logs/laravel.log for any additional error messages that might provide more context.

By following these steps, you should be able to resolve the permission error and successfully deploy your Laravel application. If the issue continues, consider checking other server configurations or logs for more clues.

aidysproule's avatar

This has worked:

  1. Check SELinux (if applicable):

If your server is running SELinux, it might be blocking the write operations. You can temporarily disable SELinux to see if it resolves the issue:

sudo setenforce 0

aidysproule's avatar
aidysproule
OP
Best Answer
Level 4

*** Solution ***

To make the setup secure, I've re-enabled SELinux and only set permissive permissions for NGINX, commands below:

sudo setenforce 1

sudo semanage permissive -a httpd_t

Please or to participate in this conversation.