0

This question already has an answer here:

Just moved my websites to my first vps (centos 7). So i'm very new to linux. Now I have a problem: php cant write anything. Can't make dirs, files, edit them. Php runs as "apache" Things I tried:

  • Chmod all dirs and files to 777
  • Chown all dirs and files to "apache"
  • Chown all dirs and files to "nobody"

Its simply wants to edit with file_put_contents(req.log, $content).

How can I fix it?

Edit: Ls -l:

root@vps314463 data]# ls -l
total 120
drwxrwxrwx. 2 apache apache  4096 Sep  8 11:12 EMAIL
-rwxrwxrwx. 1 apache apache 30357 Sep  8 10:49 login.log
-rwxrwxrwx. 1 apache apache   510 Sep  8 10:49 loginfail.log
-rwxrwxrwx. 1 apache apache 73268 Sep  8 10:49 req.log
-rwxrwxrwx. 1 apache apache   837 Sep  8 10:49 users copy 3.db
-rwxrwxrwx. 1 apache apache   994 Sep  8 10:49 users.db

Edit: Tried the answer of Kostas I chmoded and chowned public_html/data. Then opened test.php in public_html in webbrowser with the following code:

<?php
mkdir("data/testdir")
?>

Nothing happened and this error occurred:

[Thu Sep 08 22:39:20.138500 2016] [:error] [pid 24286] [client xx.xx.xxx.xxx:47632] PHP Warning: mkdir(): Permission denied in /var/www/example.com/public_html/usertest.php on line 3

marked as duplicate by Michael Hampton linux Sep 8 '16 at 21:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Your question lack sufficient information to answer it. You should edit it to include relevant information such as the output of ls -l for the directories that you want PHP to be able to write to and the user/UID that PHP runs as. See How to Ask. – Anthony Geoghegan Sep 8 '16 at 19:49
  • @AnthonyGeoghegan thx, did it. – natwaalf twaalf Sep 8 '16 at 19:56
  • Do a ls -ld too. And pwd (both while in data directory) – Matija Nalis Sep 8 '16 at 21:14
0

To create a directory / file inside a directory apache user should have write permissions to the parent directory.

chown apache.apache /path/to/data

and then

chmod 755 /path/to/data
  • Did'nt work, gave same error. See edit with more info. – natwaalf twaalf Sep 8 '16 at 20:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.