Software⏱️ 2 min read📅 2026-05-31

How to Fix: Composer: file_put_contents(./composer.json): failed to open stream: Permission denied

Composer permission denied error on Ubuntu 16.04 server.

Quick Answer: Run the command with sudo privileges: $ sudo composer global require hirak/prestissimo:^0.3

The 'file_put_contents(./composer.json): failed to open stream: Permission denied' error occurs when the Composer installation directory does not have the necessary permissions to write files.

💡 Why You Are Getting This Error

  • [Cause]

🔧 Proven Troubleshooting Steps

Method 1: Changing Permissions

  1. Step 1: Open the terminal and run the command `sudo chown -R $USER:$USER /home/kramer65/.composer` to change the ownership of the directory to your current user.

Method 2: Running Composer with Elevated Privileges

  1. Step 1: Run the command `sudo -u $USER composer global require

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions