Leichtes HTTP
Installation
apt install lighttpd apt-get install php7.0-xml
Konfiguration
Alle Parameter werden in der Datei /etc/lighttpd/lighttpd.conf konfiguriert
vim /etc/lighttpd/lighttpd.conf
server.modules = ( "mod_access", "mod_redirect", "mod_rewrite", "mod_auth", "mod_status", "mod_fastcgi", "mod_accesslog", "mod_proxy", ) server.document-root = "/automnt/USB/www/dokuwiki" server.upload-dirs = ( "/automnt/USB/cache/lighttpd/uploads" ) server.errorlog = "/automnt/USB/www/ssl/data/meta/error.log" accesslog.filename = "/automnt/USB/www/ssl/data/meta/access.log" server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" server.port = 80 index-file.names = ( "index.php", "index.html" ) url.access-deny = ( "~", ".inc" ) static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) compress.cache-dir = ( "/automnt/USB/cache/lighttpd/cache" ) compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" ) url.rewrite-once = ( "^\*(data|conf|bin|inc)/+.*" => "/nonexistentfolder" ) $HTTP["url"] =~ "^/(data|conf|bin|inc)/+.*" {url.access-deny = ("")} ## Sicherheitseinstellung für Dokuwiki $HTTP["url"] =~ "^/(data|conf|bin|inc)/+.*" { url.access-deny = ("") } ## Encoding ## dir-listing.encoding = "utf-8" server.dir-listing = "disable" ## IPv6 ## # default listening port for IPv6 falls back to the IPv4 port ## Use ipv6 if available #include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port include_shell "/usr/share/lighttpd/create-mime.assign.pl" include_shell "/usr/share/lighttpd/include-conf-enabled.pl" $HTTP["url"] =~ "\.(?i:pdf)$" {server.range-requests = "disable"} #X-Frame setenv.add-response-header = ("X-Frame-Options" => "DENY",) ## Verzeichnisschutz ## auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/etc/lighttpd/passwd" auth.require = ( "/test.php" => ( "method" => "basic", "realm" => "Wer will denn das wissen?", "require" => "valid-user" ), "/sicher" => ( "method" => "basic", "realm" => "Bitte jetzt Anmelden", "require" => "valid-user" ) ) ## SSL Verschlüsselte Seiten ## $SERVER["socket"] == ":443" { ssl.engine = "enable" ssl.pemfile = "/etc/lighttpd/ssl/server.pem" server.document-root = "/automnt/USB/www/ssl" } ##Fast cgi-php ## fastcgi.server += ( ".php" => (( "socket" => "/var/run/php/php7.0-fpm.sock", "brocken-scriptfilename" => "enable" )) ) ## VHOST ## #$HTTP["host"] =~ "awo-bellheim.spdns.de" { # proxy.server = ( # "" => ( # "AWO" => ( # "host" => "192.168.56", # "port" => "80" # ) # ) # ) #}
Plugins aktivieren
PHP7
Zuerst muss php7 installiert werden
apt install php7.0-fpm php7.0 php7.0-mbstring
Da lighttpd für php5 entwickelt wurde, müssen wir für php7 einiges anpassen
vim /etc/php/7.0/fpm/php.ini
Hier die Zeile cgi.fix_pathinfo=1 suchen und aktivieren
cd /etc/lighttpd/conf-available/ mv 15-fastcgi-php.conf 15-fastcgi-php.conf.bak vim 15-fastcgi-php.conf
# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz # http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi ## Start an FastCGI server for php (needs the php7.0-cgi package) fastcgi.server += ( ".php" => (( "socket" => "/var/run/php/php7.0-fpm.sock", "broken-scriptfilename" => "enable" )) )
Jetzt kann das Modul aktiviert werden
lighty-enable-mod fastcgi lighty-enable-mod fastcgi-php /etc/init.d/lighttpd force-reload
PHP testen
Eine Testdatei „/var/www/html/test.php erstellen (Pfad laut server.document-root)
<html> <head> <title> PHP Test Script </title> </head> <body> <?php phpinfo( ); ?> </body> </html>
Jetzt kann in einem Browser getestet werden: http://127.0.0.1/info.php
Dokuwiki Plugin
Für Dokuwiki bietet sich das Generieren eines Plugins an:
vim /etc/lighttpd/conf-available/50-dokuwiki.conf
alias.url += ("/dokuwiki" => "/usr/share/dokuwiki") $HTTP["url"] =~ "^/dokuwiki" { server.follow-symlink = "enable" } $HTTP["url"] =~ "/(\.|_)ht" { url.access-deny = ( "" ) } $HTTP["url"] =~ "^/dokuwiki/(bin|data|inc|conf)" { url.access-deny = ( "" ) }
Aktivieren mit
lighttpd-enable-mod dokuwiki /etc/init.d/lighttpd force-reload
SSL (https)
openssl installieren
apt install openssl
Zum Aktivieren in der Konfigdatei lighthttpd.conf ein neuer Socket hinzu gefügt
$SERVER["socket"] == ":443" { ssl.engine = "enable" ssl.pemfile = "/etc/lighttpd/ssl/server.pem" server.document-root = "/var/www/ssl" }
Alle unter /var/www/ssl abgelegten Daten werden mittels https angezeigt
Zertifikat erstellen
mkdir /etc/lighthttpd/ssl cd /etc/lighthttpd/ssl openssl req -new -x509 -keyout server.pem -out server.pem -days 3650 -nodes
HTTP-Authentifizierung
In der lighttpd.conf müssen die beiden Module mod_rewrite und mod_auth aktiv sein. Weiter wird in der Conf-Datei angegeben welche Ordner geschützt werden sollen
$HTTP["host"] =~ "" { auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/etc/lighttpd/passwd" auth.require = ( "/info.php" => ("method" => "basic", "realm" => "Anmelden", "require" => "user=andre"), "/bilder" => ("method" => "basic", "realm" => "Anmelden", "require" => "valid-user"), "/wiki" => ("method" => "basic", "realm" => "Anmelden", "require" => "user=andre|user=meteosat") ) }
Erklärung
- Die Datei info.php ist nur dem User andre zugänlich
- Der Ordner bilder ist allen in der /etc/lighttpd/passwd angelegten Benutzer erlaubt
- Der Ordner wiki darf nur von zwei Benutzern angeschaut werden.
Benutzer generieren
Hier hilft uns das Tool htpasswd, welches nachinstalliert werden muss
apt install apache2-utils
Wir legen den ersten Benutzer in die Datei /etc/lighttpd/passwd an
touch /etc/lighttpd/passwd htpasswd -c /etc/lighttpd/passwd andre
Soll andre ein neues Passwort bekommen, einfach das -c weg lassen
Dokumentation im Netz:
Update
Installation und Konfiguration zur Verwendung für dokuwiki
Installieren
War lighttpd schon installiert und es gibt noch config-Reste, hilft ein
apt purge lighttpd
Ist alles sauber, dann:
apt install php php-cgi php-cli php-gd php-fpm php-mbstring php-pear lighttpd
Konfigurieren
vim /etc/php/7.4/fpm/php.ini
cgi.fix_pathinfo=1 suchen und das“;„ entfernen
cd /etc/lighttpd/conf-available/ cp 15-fastcgi-php.conf 15-fastcgi-php.conf.bak vim 15-fastcgi-php.conf
Ersetze den Inhalt mit:
## Start a FastCGI server for php fastcgi.server += ( ".php" => (( "socket" => "/var/run/php/php7.4-fpm.sock", "broken-scriptfilename" => "enable" )) )
Aktivieren
lighttpd-enable-mod fastcgi lighttpd-enable-mod fastcgi-php
Wenn nötig, jetzt die conf von lighttpd anpassen
vim /etc/lighttpd/lighttpd.conf
Zum Test eine php-Test-Datei in /var/www/html/ erstellen und dei Berechtigungen glatt ziehen
chown -R www-data:www-data /var/www/html
Server kann gestartet werden
/etc/init.d/lighttpd stop /etc/init.d/lighttpd start /etc/init.d/lighttpd status
Siehe:
