Page 1 of 1

Permission denied for php code in /var/tmp folder

PostPosted: 16. September 2014 07:35
by snehu
I am using apache web server on linux. I am using PHP for web designing. On web server, i want to show the configuration data by reading the ini file. I am creating this ini file from one php code itself. If this php code i run through linux terminal, the file is created with file and group owner as root.(i am having sudo rights on machine) Then if i try to read the ini file from my apache web server, it gives warning as failed to open stream: permission denied. I have tried changing the owner, and permissions to 777 of the file. Still it is not editable.
Also from folder /var/www/html, php code is able to read any owner file but not able to write.
and from folder /var/tmp, php code is not able to read any other owner file.
On the other hand, if i run the php code of ini file creation through web server, ini file is created with file and group owner as apche. and web server is able to read/ write the file.

But i want to create that file from root or some other user and later read/written by apache.

How to give this access permission?

Re: Permission denied for php code in /var/tmp folder

PostPosted: 17. September 2014 10:52
by Nobbie
snehu wrote:Then if i try to read the ini file from my apache web server, it gives warning as failed to open stream: permission denied. I have tried changing the owner, and permissions to 777 of the file. Still it is not editable



"Read" and "editable" is NOT the same?! For "editable" you need to open in read/write mode. How is your open flag in the code?

The problem usually is the missing permission of the folders(!) that holds the file. You have to grant full access to /var and to /var/tmp for example, if you like to read/write a file like /var/tmp/config.ini

Another hint: maybe you are running your PHP installation with a "safe_mode" restriction (see php.ini). Typically for safe_mode, the Apache user may NOT open files from different users.