Lighttpd 403 Forbidden for PHP files

Scott picture Scott · Jul 18, 2012 · Viewed 59.5k times · Source

I've just installed lighttpd on my dedicated server, mod_fastcgi is enabled, so I've appended the following lines to the lighttpd.conf file:

fastcgi.server = ( ".php" =>
( "localhost" =>
                     (
                        "socket" => "/tmp/php-fastcgi.socket",
                        "bin-path" => "/usr/local/bin/php-cgi"
                      )
                   )
)

But it still doesn't help, since I'm getting the 403 - Forbidden message when I try to enter a PHP file in my web browser... When I delete the index.php file from my web root directory and place the index.html there, then everything is fine, and there are no errors, no matter if index.php file has 100 lines or just one - <?php echo 'test'; ?> it always is showing up an 403 - Forbidden, I'm out of ideas now.

Why does it happend?

ls -la of my web root directory:

#
total 6

    drwxr-xr-x  15 root  wheel   1536 Jul 18 10:23 .
    drwxr-xr-x   4 root  wheel    512 Jul 18 08:45 ..
    drwxr-xr-x   2 www   www      512 Jul  1 02:36 cache
    drwxr-xr-x   2 www   www      512 Jul  1 02:36 config
    drwxr-xr-x   6 www   www      512 Jul  1 02:36 inc
-rw-r--r--   1 www   www        9 Jul 18 11:02 index.php

Answer

Maidenone picture Maidenone · Aug 20, 2012

Your php is not configured correctly. check your lighttpd error.log it will state something like:

(mod_fastcgi.c.1397) [ERROR]: spawning fcgi failed. 

i use:

fastcgi.server = ( ".php" => ((                                      
                     "bin-path" => "/bin/php-cgi",             
                     "socket" => "/tmp/php.socket",              
                     "max-procs" => 1,                                     
                     "bin-environment" => (                         
                       "PHP_FCGI_CHILDREN" => "16",                    
                       "PHP_FCGI_MAX_REQUESTS" => "10000"           
                     ),         
                     "broken-scriptfilename" => "enable"
                 )))   

make sure that fastcgi is enabled in modules.conf

server.modules = (
  "mod_access",
  "mod_fastcgi",
#  "mod_alias",
#  "mod_auth",
#  "mod_evasive",
#  "mod_redirect",
#  "mod_rewrite",
#  "mod_setenv",
#  "mod_usertrack",
)