I couldn't write in file

Issues related to applications and software problems
Post Reply
xo)mora
Posts: 58
Joined: 2017/01/13 20:52:59

I couldn't write in file

Post by xo)mora » 2019/02/12 16:41:49

Hi I have a conflict, I couldn't write from web the visit counter, the code is:

<?php
$handle = fopen("counter.txt", "r");
$fileip = file_get_contents("counter.txt");
if(!$handle){
echo "Archivo bloqueado";
}
else {
$counter=(int )fread($handle,20);
fclose($handle);
$counter++;
echo "<b><font face='arial' size='4' color='#C10434'>VISITAS: &nbsp;&nbsp;". $counter . " <br>" ;
$handle= fopen("counter.txt", "w" ) ;
fwrite($handle,$counter) ;
fclose ($handle) ;
}
?>

I found that probably the problem is Selinux Permissions: https://lists.centos.org/pipermail/cent ... 15653.html

Probably I will execute: chcon -R -t httpd_sys_rw_content_t /var/www/html BUT the web server has another applications like joomla and perl.


Please will you help to find the solution?

Thanks a lot.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: I couldn't write in file

Post by TrevorH » 2019/02/12 16:43:58

Move your file somewhere that selinux does allow the web server to write.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

xo)mora
Posts: 58
Joined: 2017/01/13 20:52:59

Re: I couldn't write in file

Post by xo)mora » 2019/02/12 17:35:34

Move your file somewhere that selinux does allow the web server to write.

Thanks a lot, I moved and the counter grew.

Post Reply