20

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
Scott
  • 5,991
  • 15
  • 35
  • 42
  • Can you show `ls -la` of your web root? It's likely your permissions are wrong. – Martin Jul 18 '12 at 09:09
  • #edited my quesition with that – Scott Jul 18 '12 at 09:14
  • and what user is php-cgi running as? Also is there any errors in your logs? – Martin Jul 18 '12 at 09:18
  • Does [this](http://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialLighttpdAndPHP#Configuration) can helps? It solved many error from user getting a 403 with php & lighty. – j0k Jul 18 '12 at 09:21
  • I ran into this same issue. Tried everything in this post then found the solution on another forum, so here it is: `service lighttpd stop; ps -e | grep "lighttpd"` If you get a result, you likely have a perfectly working config but lighttpd is still running a config from before the php install. Just run kill on the process, then service lighttpd start again! Note that this stops lighttpd so remember to start it again if that wasn't the issue – Brian Hannay Jun 24 '17 at 18:31

6 Answers6

14

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",
)
Maidenone
  • 723
  • 10
  • 22
11

Same issue, the fix for Mint was install php5-cgi package.
sudo apt-get install php5-cgi
enable fastcgi modules
sudo lighttpd-enable-mod fastcgi fastcgi-php
and finally reload
sudo service lighttpd force-reload

Tomáš Mika
  • 111
  • 1
  • 2
6

I had the same issue. The fix was as simple as moving the config files so there were enabled. All I did was...

$ ln -s /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-enabled/
$ ln -s /etc/lighttpd/conf-available/15-fastcgi-php.conf /etc/lighttpd/conf-enabled/

and reload...

$ service lighttpd force-reload
max kaplan
  • 541
  • 4
  • 13
4

On ubuntu you can do this:

sudo lighty-enable-mod fastcgi 
sudo lighty-enable-mod fastcgi-php

Source: https://wiki.ubuntu.com/Lighttpd%2BPHP

Sevle
  • 3,109
  • 2
  • 19
  • 31
Geom16
  • 41
  • 1
1

Unlikely, but should be noted as another possible reason for "403 Forbidden" responses.

Check for any access module (mod_access) statements in the config file (lighttpd.conf)

Example:

      url.access-deny = ( "", ".php");

Docs: Module mod_access

Scryptronic
  • 111
  • 1
  • 4
1

you need to config ur lighttpd :

just :

sudo lighty-enable-mod fastcgi; sudo lighty-enable-mod fastcgi-php; sudo service lighttpd force-reload
aerrajiy
  • 21
  • 2
  • Duplicate Answer. Similar to the answer provided previously by @Geom16 with only one more instruction. Please consider adding the additional instruction as a comment to the original answer. – Missaka Iddamalgoda Nov 15 '22 at 11:16
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33166892) – ahuemmer Nov 19 '22 at 07:54