0

I've implemented a simple caching system that loads a static HTML if the database says no updates are available, and re-generates/writes the file when the database says there is an update.

Initial tests suggest that this works, however, the actual writing of the file does not operate:

Warning: fopen(/var/www/html/cache/en/item_4.php):
failed to open stream: Permission denied

The php script that attempts to write said file is located at /var/www/html/src/p/view_item.php

Every solution thus far assumes that I know how to fully operate the server and uses complicated terminology and reasoning; this is my first go with my own server, several things still aren't clear.

I've seen it said on multiple occasions that you should give the the user "nobody" write access to said folder (On a fresh PHP installation), while others say the file itself need some form of ownership over the directory or Apache itself needs write access.

Overall: Nothing's worked, ranging setting the directory to 777 and running the operation as another user (Whom I can only assume has write access there, too).

How exactly can I allow PHP to write to /var/www/html/cache/en/ and sub-folders?

I'm running LAMP, I have shell access and all that.

Super Cat
  • 1,547
  • 1
  • 18
  • 23
  • can you write anywhere? can you read? have you been through the first page of google results when you search for this issue? what happened when you tried those things? (they're too detailed to suggest in a comment) [PHP Documentation on fopen](http://php.net/manual/en/function.fopen.php) talks about restrictions when used with safe_mode and open_basedir...? – gloomy.penguin Sep 05 '14 at 21:22
  • Check out this link. I had a similar issue and this fixed it. http://stackoverflow.com/questions/9133024/www-data-permissions – Nicolas Sep 05 '14 at 21:25
  • @gloomy.penguin - Yep, I can't write anywhere. It can read anything, just not write (You may want to rephrase that :P). I sort of summarized the fruit of my efforts in the question. – Super Cat Sep 05 '14 at 21:27
  • @Nicolas That seems to have worked to a degree (As I've discovered, PHP runs under www-data), but it still, unfortunately, denies the script permission to create the file. – Super Cat Sep 05 '14 at 21:38

1 Answers1

0

How exactly can I allow PHP to write to /var/www/html/cache/en/ and sub-folders?
PHP runs under www-data

chown -R www-data.www-data /var/www/html/cache/en/
Jan
  • 403
  • 8
  • 19