Project

General

Profile

[Solved] Parsing html as php

Added by cpcnw over 5 years ago

Hi All,

n00b first post here so please don't flame me :)

What is the minimum I need to parse php snippets within html files? I have lighty installed on DietPi/Raspi3 and am hitting a wall atm with 'Access Denied'

Have tried the advice here :-

https://stackoverflow.com/questions/9754326/handling-html-as-php-lighttpd

and various other places round the net to no avail.

Here are my versions etc and conf file - any advice would be truly appreciated!

DietPi v6.11 RPi 2 Model B (armv7l)
Linux raspi 4.14.54-v7+ #1126 SMP Wed Jul 11 20:01:03 BST 2018 armv7l GNU/Linux

lighttpd/1.4.45 (ssl) - a light and fast webserver
Build-Date: Jan 14 2017 21:07:19

--- lighttpd.conf ---

server.modules = (
"mod_access",
"mod_alias",
"mod_redirect",
)

server.document-root = "/mnt/cf/http"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
server.max-worker = 4

index-file.names = ( "index.html", "index.htm", "index.php" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

fastcgi.map-extensions = ( ".htm" => ".php" )

#compress.cache-dir = "/var/cache/lighttpd/compress/"
#compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )

dir-listing.activate = "enable"
server.error-handler-404 = "/404.htm"


Replies (8)

RE: Parsing html as php - Added by gstrauss over 5 years ago

You haven't loaded mod_fastcgi and you haven't defined fastcgi.server. Docs_ModFastCGI Please see the documentation and search the internet with this new information.

RE: Parsing html as php - Added by cpcnw over 5 years ago

Thanks for the reply. I have added to my conf file :-

"mod_fastcgi",

to the modules section and from an example I found on the net :-

fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php",
"socket" => "/tmp/php.socket",
"max-procs" => 2,
"idle-timeout" => 20,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
))
)

I got an error in the log file about security.limit_extensions so have added

security.limit_extensions = .php .html .htm

The result is that I am now getting 'Site can't be reached' and oddly the log file is empty after a reboot!

Sorry for being a pain!

RE: Parsing html as php - Added by cpcnw over 5 years ago

I have now removed security.limit_extensions = .php .html .htm as well as my fastcgi.server section and the behaviour now is that the browser downloads the page as a file?

Not sure if this helps or not?

RE: Parsing html as php - Added by cpcnw over 5 years ago

Getting somewhere? Or at least some error messages ;

From the browser: 500 - Internal Server Error
From the log file:
2018-07-16 13:21:45: (mod_fastcgi.c.3574) child exited: 0 unix:/var/run/lighttpd/php-fastcgi.socket-3
2018-07-16 13:21:45: (mod_fastcgi.c.3565) pid 941 1 not found: No child processes

--- lighttpd.conf ---

server.modules = ( "mod_access", "mod_alias", "mod_redirect", "mod_fastcgi" )
server.document-root = "/mnt/cf/http"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
server.max-worker = 4
index-file.names = ( "index.html", "index.htm", "index.php" )
fastcgi.map-extensions = ( ".htm" => ".php", ".html" => ".php")
dir-listing.activate = "enable"
server.error-handler-404 = "/404.htm"

fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/bin/php"
)
)
)

RE: Parsing html as php - Added by cpcnw over 5 years ago

Have just been having a look through the various directories associated with lighttpd on DietPi and came across this in /etc/lighttpd/conf-available/README

ligghttpd Configuration under Debian GNU/Linux
Files and Directories in /etc/lighttpd:

lighttpd.conf:
main configuration file

conf-available/
This directory contains a series of .conf files. These files contain
configuration directives necessary to load and run webserver modules.
If you want to create your own files they names should be
build as nn-name.conf where "nn" is two digit number (number
is used to find order for loading files)

conf-enabled/
To actually enable a module for lighttpd, it is necessary to create a
symlink in this directory to the .conf file in conf-available/.

Enabling and disabling modules could be done by provided
/usr/sbin/lighty-enable-mod and /usr/sbin/lighty-disable-mod scripts.

There are two symlinks in /etc/lighttpd/conf-enabled namely

10-fastcgi.conf wk#hich has contents

/usr/share/doc/lighttpd/fastcgi.txt.gz
http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

server.modules += ( "mod_fastcgi" )

and 15-fastcgi-php.conf which has contents

 depends: fastcgi 
/usr/share/doc/lighttpd/fastcgi.txt.gz
http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

Start an FastCGI server using php-fpm
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php/php7.0-fpm.sock",
"broken-scriptfilename" => "enable"
))
)

these where referenced in the original lighttpd.conf before I started getting mad with it and hacking it up

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

the later of which includes

!/usr/bin/perl -wl

use strict;
use File::Glob ':glob';

my $confdir = shift || "/etc/lighttpd/";
my $enabled = "conf-enabled/*.conf";

chdir($confdir);
my @files = bsd_glob($enabled);

for my $file (@files) {
print "include \"$file\"";
}

I have now put these two lines back in and removed my own references as I think this may be interfering!

RE: Parsing html as php - Added by cpcnw over 5 years ago

So here is my last edit for comment ;

server.modules = ( "mod_access", "mod_alias", "mod_redirect")
server.document-root = "/mnt/cf/http"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
server.max-worker = 4
index-file.names = ( "index.html", "index.htm", "index.php" )
fastcgi.map-extensions = ( ".htm" => ".php", ".html" => ".php")
dir-listing.activate = "enable"
server.error-handler-404 = "/404.htm"
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

if I include

security.limit_extensions = .php .html .htm

I get "This site can’t be reached" from Chrome [but nothing in the logs]
Conversely if I remove it I get "Access Denied" [and msg in logs about security.limit_extentions]

I am completely at a loss as to where to go next...

RE: Parsing html as php - Added by cpcnw over 5 years ago

security.limit_extensions = .php .html .htm

must be added to

/etc/php/7.0/fpm/pool.d/www.conf

NOT

/etc/lighttpd/lighttpd.conf

Useful command that helped me track this down was

lighttpd -p -f /etc/lighttpd/lighttpd.conf

this is also an interesting command to know about;

root@raspi:~# systemctl status php7.0-fpm
? php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2018-07-18 09:23:46 BST; 7min ago
Docs: man:php-fpm7.0(8)
Main PID: 910 (php-fpm7.0)
Status: "Processes active: 0, idle: 4, Requests: 1, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php7.0-fpm.service
+-910 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
+-918 php-fpm: pool www
+-919 php-fpm: pool www
+-920 php-fpm: pool www
+-921 php-fpm: pool www

Jul 18 09:23:45 raspi systemd1: Starting The PHP 7.0 FastCGI Process Manager...
Jul 18 09:23:46 raspi systemd1: Started The PHP 7.0 FastCGI Process Manager.

RE: [Solved] Parsing html as php - Added by gstrauss over 5 years ago

Thanks for the update. Glad you figured it out.

    (1-8/8)