![Apache 2.4 + PHP-FPM + ProxyPassMatch mit Unix-Socket](https://rvso.com/image/726377/Apache%202.4%20%2B%20PHP-FPM%20%2B%20ProxyPassMatch%20mit%20Unix-Socket.png)
Ich versuche, Apache v2.4 + PHP-FPM + ProxyPassMatch mithilfe eines Unix-Sockets einzurichten.
Verwende Debian 9 Stretch, PHP v5.6.37, PHP v7.0.31, Apache v2.4.25.
Meine Virtualhost-Einstellung ist die folgende (000-default.conf):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName local.lc
DocumentRoot /var/www
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5.6-fpm.sock|fcgi://localhost/var/www/"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Ich habe die folgenden Befehle ausgeführt:
sudo apt-get install php7.0-cli php7.0-fpm php-pear libapache2-mod-fcgid
sudo apt install software-properties-common
# add repo to get PHP5
sudo apt-get -y install apt-transport-https lsb-release ca-certificates
sudo curl https://packages.sury.org/php/apt.gpg | apt-key add -
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo echo 'deb https://packages.sury.org/php/ stretch main' > /etc/apt/sources.list.d/deb.sury.org.list
sudo apt-get update
sudo apt-get install php5.6-cli php5.6-fpm
sudo apt-get install php7.0 php7.0-fpm
sudo a2enconf php5.6-fpm
sudo systemctl reload apache2
sudo a2dismod php5 php7 php5.6 php7.0 mpm_prefork
sudo a2enmod actions alias proxy_fcgi mpm_worker
sudo systemctl restart apache2 php5.6-fpm php7.0-fpm
Der Neustart der Server nach Änderungen erfolgt mit:
sudo systemctl restart apache2 php5.6-fpm php7.0-fpm
Ich bekomme eine leere Seite, wenn ich das lade
http://local.lc/
Website auf meinem Windows-basierten Entwicklungscomputer. Die Datei local.lc befindet sich in der Datei „hosts“.
Ich sehe Folgendes im Protokoll (/var/log/apache2/error.log):
[Tue Aug 28 23:24:26.685004 2018] [mpm_worker:notice] [pid 43104:tid 140487559849152] AH00295: caught SIGTERM, shutting down
[Tue Aug 28 23:24:27.001054 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity for Apache/2.9.1 (http://www.modsecurity.org/) configured.
[Tue Aug 28 23:24:27.001189 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: APR compiled version="1.5.2"; loaded version="1.5.2"
[Tue Aug 28 23:24:27.001205 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: PCRE compiled version="8.39 "; loaded version="8.39 2016-06-14"
[Tue Aug 28 23:24:27.001223 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: LUA compiled version="Lua 5.1"
[Tue Aug 28 23:24:27.001236 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: YAJL compiled version="2.1.0"
[Tue Aug 28 23:24:27.001248 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: LIBXML compiled version="2.9.4"
[Tue Aug 28 23:24:27.001498 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: StatusEngine call: "2.9.1,Apache/2.4.25 (Debian),1.5.2/1.5.2,8.39/8.39 2016-06-14,Lua 5.1,2.9.4,cb"
[Tue Aug 28 23:24:27.135554 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: StatusEngine call successfully sent. For more information visit: http://status.modsecurity.org/
[Tue Aug 28 23:24:28.005175 2018] [mpm_worker:notice] [pid 43532:tid 139833116394688] AH00292: Apache/2.4.25 (Debian) OpenSSL/1.0.2l mod_fcgid/2.3.9 configured -- resuming normal operations
[Tue Aug 28 23:24:28.005270 2018] [core:notice] [pid 43532:tid 139833116394688] AH00094: Command line: '/usr/sbin/apache2'
Ich sehe im Protokoll nichts Hilfreiches.
Irgendeine Idee, was falsch sein könnte?
Warum wird die Standardseite nicht geladen?
Antwort1
In Ihrer Konfiguration fehlt eine DirectoryIndex
Anweisung. Wenn Sie also eine URL wiehttp://local.lc/Apache weiß nicht, nach welcher Datei es auf der Festplatte suchen und diese bereitstellen soll, anstatt Ihnen lediglich den Inhalt des Verzeichnisses anzuzeigen (was wahrscheinlich nicht das ist, was Sie möchten).
Wenn Sie PHP-FPM verwenden, würde ich erwarten, dass Sie DirectoryIndex
etwas wie Folgendes einstellen index.php
, das dann von PHP-FPM verarbeitet werden sollte.
Wenn Sie PHP-FPM direkt mit einem cgi-fcgi
Dienstprogramm wie diesem testen, können Sie Apache umgehen, falls es immer noch nicht funktioniert.
Antwort2
Beim Zugriff http://local.lc/index.html
wurde weder eine Seite angezeigt, noch ist ein Fehler im Fehlerprotokoll aufgetreten.
Nachdem dies mit DirectoryIndex
der von @bodgit vorgeschlagenen Anweisung behoben und http://local.lc/index.php
jetzt geladen wurde, trat ein Fehler in error.log auf.
Beim Betrachten des error.log sehe ich jetzt die folgende Fehlermeldung:
No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/php5.6-fpm.sock (localhost) failed".
Beim Überprüfen wurde der /var/run/php5.6-fpm.sock
Pfad nicht gefunden, aber der /var/run/php/php5.6-fpm.sock
wurde gefunden.
Der Pfad wurde in meinen Virtualhost-Einstellungen wie folgt festgelegt (000-default.conf):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName local.lc
DocumentRoot /var/www
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/var/www/"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Korrigieren Sie also den Pfad in der Vhost-Konfigurationsdatei und laden Sie dann
http://local.lc/index.php
die Seite. Jetzt wird Folgendes angezeigt:
"Es klappt!".
Problem gelöst!