Skip to content
Advertisement

fopen() works properly in a debug session, but doesn’t work when I call the file through the browser

I’m new to PHP and just faced the problem with creating and opening a file with fopen(). Here is my code:

JavaScript

When I try to run the file by opening it in the browser I see the next message: ‘Cannot create a file’. But when I start debug session everithing works as it supposed to. I suspect that there is some issue with permissions and XDebug uses root access unlike the usual interpreter?

Advertisement

Answer

To solve this problem first of all I was needed to check PHP user with the next command:

JavaScript

It outputs:

JavaScript

This is the default PHP user. Next I checked the owner of the folder with this command:

JavaScript

It outputs:

JavaScript

Next I’ve sat permissions to the PHP user by running:

JavaScript

Checking once again if the owner changed

JavaScript

And now it outputs

JavaScript

Done. Now I’m able to create and write to the file.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement