• This forum has a zero tolerance policy regarding spam. If you register here to publish advertising, your user account will be deleted without further questions.

Froxlor mit Nginx + PHP-FPM

Crystal26

New Member
Hallo zusammen,

ich wollte demnächst meinen Server neu bestücken und weg vom Apache. Ich habe mich nun für nginx entschieden mit PHP-FPM.

Ich hab nun schon zum 3. Mal probiert das auf diese Ebene zu installieren, jedoch scheitere ich spät, sobald ein Cron gelaufen ist an einen Bad Gateway.

Ich habe alles wie folgt installiert. PHP-FPM + Nginx über Konsole geladen, danach Froxlor runtergeladen und die fehlenden Pakete autom. nachgeladen.

Danach musste ich erstmal den default "vhost" umschreiben, sodass ich überhaupt in die Installationsroutine von Froxlor reinkomme, soweit so gut...

Nun in Froxlor PHP-FPM aktiviert und die nötigen weiteren Änderungen durchgeführt, bis auf den Teil (bei Webserver NGINX) mit FASTCGI, da ich FPM verwenden möchte und es keine Routine gibt für PHP-FPM.

Sobald der Cron gelaufen ist, kann man Froxlor nicht mehr aufrufen, weil ein Bad Request erscheint. Wenn ich mir die vHosts genau anschaue, sehe ich auch dass FastCGI als Modul geladen wird, obwohl ja gar nicht gewollt.

Vll. hat ja jemand hiermit Erfahrung, im eigenen Forum von Froxlor konnte ich leider nichts finden was zum Thema passt.
 
Ja, weil sonst müsste ich es für alle Kunden immer einzeln anlegen was auf die Dauer enorm Zeit kosten würde
 
bjo meint, ob du in Froxlor unter PHP FPM aktiviert hast, dass auch ein vhost für Froxlor selbst erstellt werden soll.
 
Ahh, ja habe ich dies war ja im Endeffekt nur das Einschalten des FPM-Modus unter Einstellungen auf "JA".

So schaut eine vHost von froxlor aus:

Code:
# 10_froxlor_ipandport_80.xxx.xx.xx.80.conf
# Created 21.03.2012 02:00
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.

server { 
	listen    80.xxx.xx.xx:80 default;
	# Froxlor default vhost
	server_name    vps9382.xxxx.de;
	access_log      /var/log/nginx/access.log;
	root     /var/www/froxlor/;
	location / {
		index    index.php index.html index.htm;
	}
	location ~ \.php$ {
		fastcgi_index index.php;
		include /etc/nginx/fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		fastcgi_pass unix:/var/run/nginx/froxlor.panel-vps9382.xxx.de-php-fpm.socket;
	}
}

Bei der Konfiguration will er unbedingt dass man im init.d die Batch-Datei für fastCGI ändert, jedoch wird dort gar keine erstellt - es ist ja die Datei "php5-fpm" zuständig.

Das soll geändert werden an der Datei: "php-fcgi":

Code:
#!/bin/bash
BIND="127.0.0.1:8888"
USER="www-data"
PHP_FCGI_CHILDREN="15"
PHP_FCGI_MAX_REQUESTS="1000"

PHP_CGI="/usr/bin/php-cgi"
PHP_CGI_NAME="$(basename ${PHP_CGI})"
PHP_CGI_ARGS="- USER=${USER} PATH=/usr/bin PHP_FCGI_CHILDREN=${PHP_FCGI_CHILDREN} PHP_FCGI_MAX_REQUESTS=${PHP_FCGI_MAX_REQUESTS} ${PHP_CGI} -b ${BIND}"
RETVAL="0"

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- "$PHP_CGI_ARGS"
      RETVAL="$?"
      echo "${PHP_CGI_NAME}."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u "${USER} ${PHP_CGI}"
      RETVAL="$?"
      echo "${PHP_CGI_NAME}."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit "$RETVAL"

Ich habe bis auf diese Änderung alle Änderungen ausgeführt. Weil ja schliesslich FPM zuständig ist, so schaut meine "php5-fpm" aus, ist eigtl. ziemlich Standard:

Code:
#!/bin/sh
### BEGIN INIT INFO
# Provides:          php-fpm php5-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php5-fpm
# Description:       Starts PHP5 FastCGI Process Manager Daemon
### END INIT INFO

# Author: Ondrej Sury <ondrej@debian.org>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="PHP5 FastCGI Process Manager"
NAME=php5-fpm
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--fpm-config /etc/php5/fpm/php-fpm.conf"
PIDFILE=/var/run/php5-fpm.pid
TIMEOUT=30
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function to check the correctness of the config file
#
do_check()
{
    [ "$1" != "no" ] && $DAEMON $DAEMON_ARGS -t 2>&1 | grep -v "\[ERROR\]"
    FPM_ERROR=$($DAEMON $DAEMON_ARGS -t 2>&1 | grep "\[ERROR\]")

    if [ -n "${FPM_ERROR}" ]; then
	echo "Please fix your configuration file..."
	$DAEMON $DAEMON_ARGS -t 2>&1 | grep "\[ERROR\]"
	return 1
    fi
    return 0
}

#
# Function that starts the daemon/service
#
do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
		|| return 1
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
		$DAEMON_ARGS 2>/dev/null \
		|| return 2
	# Add code here, if necessary, that waits for the process to be ready
	# to handle requests from services started subsequently which depend
	# on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	start-stop-daemon --stop --quiet --retry=TERM/$TIMEOUT/KILL/5 --pidfile $PIDFILE --name $NAME
	RETVAL="$?"
	[ "$RETVAL" = 2 ] && return 2
	# Wait for children to finish too if this is a daemon that forks
	# and if the daemon is only ever run from this initscript.
	# If the above conditions are not satisfied then add some other code
	# that waits for the process to drop all resources that could be
	# needed by services started subsequently.  A last resort is to
	# sleep for some time.
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
	[ "$?" = 2 ] && return 2
	# Many daemons don't delete their pidfiles when they exit.
	rm -f $PIDFILE
	return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
	#
	# If the daemon can reload its configuration without
	# restarting (for example, when it is sent a SIGHUP),
	# then implement that here.
	#
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
	return 0
}

case "$1" in
    start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	do_check $VERBOSE
	case "$?" in
	    0)
		do_start
		case "$?" in
		    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
		esac
		;;
	    1) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
    stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
    status)
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
        ;;
    check)
        do_check yes
	;;
    reload|force-reload)
	log_daemon_msg "Reloading $DESC" "$NAME"
	do_reload
	log_end_msg $?
	;;
    restart)
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
	  	# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
    *)
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
	exit 1
    ;;
esac

:


Der Error.LOG von Nginx sagt folgendes aus:

Code:
2012/03/21 02:06:17 [crit] 9541#0: *157 connect() to unix:/var/run/nginx/froxlor.panel-vps9382.xxx.de-php-fpm.socket failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xx.xx, server: vps9382.xxx.de, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/nginx/froxlor.panel-vps9382.xxx.de-php-fpm.socket:", host: "vps9382.xxx.de"
 
Last edited by a moderator:
Erstellt Froxlor denn die php-fpm-configs, und werden die in /etc/php5/fpm/php-fpm.conf eingebunden?

Wenn Froxlor die Configs in /etc/php5/fpm/pool.d/ erstellt, müsste in der php-fpm.conf dann
Code:
include=/etc/php5/fpm/pool.d/*.conf
stehen, sonst erstellt php-fpm nicht die entsprechenden Sockets und nginx kann nicht connecten.
 
Danke für den Hinweis.

Code:
include=/etc/php-fpm.d/*.conf

Die Configs haben in etc einen eigenen Ordner von Froxlor erhalten. Dann hat PHP-FPM ein bissel gemerkt in den Logs weil die Startserver falsch konfiguriert waren, dies ist aber nun behoben.

Leider ohne Veränderung, habe immer noch "Bad Request" aktuell.

Auszug aus den Log:

Code:
[22-Mar-2012 18:18:15] ERROR: FPM initialization failed
[22-Mar-2012 18:21:36] ERROR: [pool vps9382.xxx.de] cannot get uid for user 'froxlorlocal'
 
Last edited by a moderator:
Code:
addgroup --gid 9999 froxlorlocal
adduser --no-create-home --uid 9999 --ingroup froxlorlocal --shell /bin/false froxlorlocal
 
Vielen Dank, die Config von Froxlor war hiernach nicht lesbar. Was ich nun jedoch ändern konnte.

Habe testweise auch schon eine Subdomain angelegt und es scheint zu funktionieren nun alles.

Sollte ich ggf. noch an der Batch für php-fpm im init-d Ordner etwas ändern, (siehe Vorposts) oder ist dies nicht mehr notwendig?

Die Errorlogs scheinen nun sauber. Die Prozesse scheinen mir nicht ganz so sauber, oder was meinen die Fachleute (siehe Bild). PHP-FPM wird ja mit 3 versch. Benutzern aufgerufen.
 

Attachments

  • screen.PNG
    screen.PNG
    64.4 KB · Views: 506
Last edited by a moderator:
Sowohl der root als auch die froxlorlocal PHP Prozesse sind völlig normal. Für jeden angelegten Kunden (und auch Froxlor, wie bei dir in den Froxlor Einstellungen aktiviert) werden eigene PHP Prozesse unter dessen Benutzernamen gestartet.

Zu den www-data PHP fpm Prozessen: Lässt du Froxlor die Konfigurationsdateien in /etc/php-fpm.d/ oder in /etc/php5/fpm/pool.d/ erstellen? In letzteren (Standard)Verzeichnis existiert nach der Installation bereits eine angelegte Konfiguration, welche in deinem Fall wohl mitgestartet wird.
 
Hey, die Dateien liegen in /etc/php-fpm.d/ - Ich entsinne mich aber leicht, dass man im Froxlor ACP unter Konfiguration der Prozess www-data genannt wird bzw. auch umbenannt werden kann.

Ich hab das gleiche Spiel mal auf ISPConfig getestet und muss mit erstaunen sagen, dass die Installation mit diesem ISP viel reibungsloser läuft. Aber ich bin großer ispCP Fan und ich finde Froxlor auch deutlich leichter strukturiert, wäre es nicht so schwer umzusetzen mit Nginx und PHP-FPM.
 
Last edited by a moderator:
Also ich habe selbst Froxlor mit PHP fpm laufen, allerdings mit lighttpd. Kann mich nicht beklagen und werde wohl demnächst auch auf nginx umsteigen - das Problem, welches mir beim letzten Test begegnet ist (Froxlor schreibt falsche nginx Konfigurationsdateien) ist ja inzwischen behoben.

Die zusätzlichen www-data Prozesse sind mir wie gesagt nur dadurch begegnet, dass ich das Verzeichnis php fpm genutzt habe, in der sich noch eine standardmäßige Konfiguration von der php fpm Installation befand. Ich würde dies ggf. nochmal kontrollieren; vielleicht hat aber auch bjo noch eine Idee.
 
Back
Top