Tuesday, March 22, 2011

Fedora Localhost PHP Server (Upload File Permission Problem)

Hello Fedora Linux User,

I'm currently using Fedora 14 and still haven't got any problem with "Selinux" until one day i want to install apache, php, mysql server on my linux box. The problem is that i can't get the PHP upload file function "move_uploded_file" function to work. The error described on my apache error warning is "failed to open stream: Permission denied in $YOUR_PHP_FILE_PATH".

At first i thought that this error is a common error which caused by lack of privillages however even after changing file permissions and owner the error still exist.  Not long after that i found it in linux forum that "Selinux" may caused the error. Actually "Selinux" will give warning / notification if there is an access violation but in few cases it won't.

There are two ways to handle this:
1. Disable the selinux completely
2. Gives selinux permissive authorization

In most fedora distributions Selinux configuration can be found in /etc/selinux/config. Just pick one of your favourite editor and do some editing to these lines: "SELINUX=$value". $value is the value you want for selinux to undergoes.

Example of Selinux configuration
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.

In my case i completely disabled the protection. But if your linux box has local network neighbourhood i recommend the permissive mode. Permissive mode only gives warnings unlike the enforcing mode

Therefore, if anybody experience similar thing like this i hope this guide can help you. Thank you for reading...