PHP: file write permissions -


i have been banging head quite while because of this...

i'm trying install mybb forum on virtual server (centos 7, apache http server, php 5.4.3) , ran troubles file permissions. mybb needs 2 files writable, 1 of them config.php , second 1 settings.php, both of them in directory inc.

i set permissions on both files 666. wrote simple testing php page mimics way mybb tests ability write:

<?php echo('config: '); $configwritable = @fopen('forum/inc/config.php', 'w'); if ($configwritable) {         echo('yes'); } else {         echo('no'); } echo('<br/>'); echo('settings: '); $configwritable = @fopen('forum/inc/settings.php', 'w'); if ($configwritable) {     echo('yes'); } else {     echo('no'); } ?> 

the page output is

config: no settings: yes 

but if list files, show this

root@localhost# ls -l forum/inc/config.php forum/inc/settings.php  -rw-rw-rw-. 1 krkavec krkavec 0  2. říj 22.49 forum/inc/config.php -rw-rw-rw-. 1 krkavec krkavec 0  2. říj 22.51 forum/inc/settings.php 

how possible? both files belong same user, same group, have same size (zero), in same directory, have same permissions, have same modification time (differing 2 minutes) , virtually else except name identical.

to make things more weird, tried play around deleting , creating files again, watch:

1: deleting both files

root@localhost# rm -f forum/inc/config.php forum/inc/settings.php 

and page output:

config: no settings: no 

which ok since inc directory isn't supposed writable.

2: create settings.php

root@localhost# f=forum/inc/settings.php ; touch $f ; chown krkavec:krkavec $f ; chmod 666 $f root@localhost# ls -l forum/inc/settings.php forum/inc/config.php ls: cannot access forum/inc/config.php: no such file or directory -rw-rw-rw-. 1 krkavec krkavec 0  2. říj 23.15 forum/inc/settings.php 

and page output:

config: no settings: yes 

which totally ok , expected - file there , has writable permissions.

3: create config.php

root@localhost# f=forum/inc/config.php ; touch $f ; chown krkavec:krkavec $f ; chmod 666 $f root@localhost# ls -l forum/inc/settings.php forum/inc/config.php -rw-rw-rw-. 1 krkavec krkavec 0  2. říj 23.23 forum/inc/config.php -rw-rw-rw-. 1 krkavec krkavec 0  2. říj 23.15 forum/inc/settings.php 

and page output:

config: no settings: yes 

bam! totally expect config writable.

any appreciated.

edit: modified testing page according marc b's , drew010's suggestions

<?php error_reporting(e_all); ini_set('display_errors', 1);  echo('config var_dump: '); var_dump(stat('forum/inc/config.php')); echo('<br/>config: '); $configwritable = fopen('forum/inc/config.php', 'w'); if ($configwritable) {     echo('yes'); } else {     echo('no'); } echo('<br/>'); echo('settings var_dump: '); var_dump(stat('forum/inc/settings.php')); echo('<br/>settings: '); $configwritable2 = fopen('forum/inc/settings.php', 'w'); if ($configwritable2) {     echo('yes'); } else {     echo('no'); } ?> 

and page's output (with both files present) is:

config var_dump: array(26) { [0]=> int(64768) [1]=> int(19155212) [2]=> int(33206) [3]=> int(1) [4]=> int(1000) [5]=> int(1000) [6]=> int(0) [7]=> int(0) [8]=> int(1443821772) [9]=> int(1443821772) [10]=> int(1443821772) [11]=> int(4096) [12]=> int(0) ["dev"]=> int(64768) ["ino"]=> int(19155212) ["mode"]=> int(33206) ["nlink"]=> int(1) ["uid"]=> int(1000) ["gid"]=> int(1000) ["rdev"]=> int(0) ["size"]=> int(0) ["atime"]=> int(1443821772) ["mtime"]=> int(1443821772) ["ctime"]=> int(1443821772) ["blksize"]=> int(4096) ["blocks"]=> int(0) }  config:  warning: fopen(forum/inc/config.php): failed open stream: permission denied in /var/www/html/test.php on line 8 no settings var_dump: array(26) { [0]=> int(64768) [1]=> int(19155069) [2]=> int(33206) [3]=> int(1) [4]=> int(1000) [5]=> int(1000) [6]=> int(0) [7]=> int(0) [8]=> int(1443821763) [9]=> int(1443823158) [10]=> int(1443823158) [11]=> int(4096) [12]=> int(0) ["dev"]=> int(64768) ["ino"]=> int(19155069) ["mode"]=> int(33206) ["nlink"]=> int(1) ["uid"]=> int(1000) ["gid"]=> int(1000) ["rdev"]=> int(0) ["size"]=> int(0) ["atime"]=> int(1443821763) ["mtime"]=> int(1443823158) ["ctime"]=> int(1443823158) ["blksize"]=> int(4096) ["blocks"]=> int(0) }  settings: yes 

for magical, unknown reason, when renamed settings.php config.php , created new settings.php , set rights appropriately, both files writable.

however, have no idea whatsoever why file had renamed. result same after step 3 described in question except works.

any suggestion why hat done , reason behind welcome.

edit: caused selinux security context prevented apache write file. running chcon -t httpd_sys_rw_content_t config.php solved problem.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -