Lighttpd 403 Forbidden for PHP Files
When you install lighttpd and configure FastCGI to handle .php files, expecting a 403 Forbidden error is often the first sign that your file permissions are misconfigured, not that the web server logic is broken. The configuration snippet you provided looks syntactically correct: it binds the FastCGI socket to /tmp/php-fastcgi.socket and points bin-path to your PHP binary. However, Lighttpd acts as a gatekeeper before it even attempts to spawn the CGI process. If the web server user cannot read the file or execute the script, it returns 403 immediately.
The error occurs because Lighttpd is running as a specific system user (typically www or nobody) who lacks the necessary permissions to access your files. In the output of your ls -la command, we see that index.php is owned by www with -rw-r--r-- permissions. While this allows the owner and group to read the file, it restricts others. If Lighttpd's worker processes are running under a different user or if the directory structure isn't fully accessible, the server denies access before passing the request to PHP.
The critical detail lies in how Lighttpd handles static files versus dynamic scripts. When you replace index.php with index.html, the 403 error disappears because HTML files are served as static content. The web server only needs read permission on the file itself; it does not need to execute it or invoke external binaries. This confirms that your socket configuration and PHP binary path are likely correct, but the initial access control check is failing for the .php extension.
To resolve this, you must ensure that the user running Lighttpd can both read the file and traverse the directory tree. Check which user Lighttpd starts as by inspecting your service configuration or using ps aux | grep lighttpd. You will likely find it running as www. Ensure that the ownership of your web root and all subdirectories matches this user. If you own the files as root, change ownership immediately:
chown -R www:wheel /var/www/your-web-root/path
chmod 755 /var/www/your-web-root/path
chmod 644 /var/www/your-web-root/path/*.php
If you are on macOS (implied by the root wheel group in your directory listing), you may also need to adjust the ACLs or ensure that the specific socket file /tmp/php-fastcgi.socket is accessible. FastCGI sockets often reside in world-writable directories like /tmp, but the owning process must have write access to send data back to the client. Verify that the www user can create files in /tmp.
Another common pitfall involves the directory permissions for inc and cache. Even if index.php is readable, Lighttpd needs permission to enter parent directories. If any parent folder has a restrictive mode like 700 or is owned by a group that the web user isn't part of, access will be denied. Your listing shows drwxr-xr-x, which is generally safe, but double-check that this applies recursively.
There is also a subtle interaction between mod_dir and mod_fastcgi. Lighttpd might try to serve the file as static content if it doesn't explicitly allow FastCGI execution. Ensure you have enabled the necessary modules and configured the server to treat .php files as dynamic:
$HTTP["extension"] == ( "php" ) {
server.document-root = "/path/to/your/webroot" # Optional, ensure root is set
}
If your setup involves a specific application framework like Laravel, you must also remember that the storage and bootstrap/cache directories require write permissions for the web user to function correctly. A 403 error in those contexts usually stems from missing execute (x) bits on the parent folders or incorrect ownership of the cache directory itself.
Ultimately, the 403 Forbidden message is a permission issue, not a syntax error in your lighttpd.conf. By aligning file ownership with the web server process and ensuring consistent directory traversal permissions, you allow Lighttpd to pass the request to PHP-FPM or your CGI binary, resolving the conflict. For more robust production setups involving complex permission requirements, consider reaching out to experts who specialize in optimized web architectures at https://laravelcompany.com.