skip to Main Content

I am trying to run some PHP applications on CentOS powered server with apache and MySQL. My apps have to create files on server, but it always says that permission is denied to create a file.

Files are located in /var/www/html. I even tried setting 777 permission to html folder and html/*. I changed apache user and group to myuser, that exists, and restarted apache. I changed the ownership of html folder and all files inside to myuser. I even tried changing document root to /home/myuser/public_html

I tried this code to test write permission. File location is /var/www/html/index.php and /home/myuser/public_html/index.php

$handle = fopen("a.txt", "w");
fwrite($handle, "test");
fclose($handle);

I am just more than amazed by this problem. The same configuration works on my another Ubuntu server.

Some geniuses must be here, help me.

2

Answers


  1. You need to allow you server user to do write operation on your directory, User the below command, If it is a multilevel directory use -R flag.

    sudo chown www-data my-dir
    
    Login or Signup to reply.
  2. Instead of manually giving permission you can try chmod($handle, 0777) within your code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search