Skip to content

Commit

Permalink
Support for PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveorevo committed Dec 1, 2023
1 parent bf7226e commit 8c991a7
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 4 deletions.
9 changes: 9 additions & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ apt-get -qq install php7.4-xdebug
apt-get -qq install php8.0-xdebug
apt-get -qq install php8.1-xdebug
apt-get -qq install php8.2-xdebug
apt-get -qq install php8.3-xdebug

# Copy PHP profiles to PHP Xdebug versions
mkdir /etc/php/7.4xdbg
Expand All @@ -32,12 +33,18 @@ rsync -al /etc/php/8.2/ /etc/php/8.2xdbg
rm -rf /etc/php/8.2xdbg/fpm/pool.d
./link_rename.sh /etc/php/8.2xdbg/fpm/conf.d /etc/php/8.2/ /etc/php/8.2xdbg/
ln -s /etc/php/8.2xdbg/mods-available/xdebug.ini /etc/php/8.2xdbg/fpm/conf.d/20-xdebug.ini
mkdir /etc/php/8.3xdbg
rsync -al /etc/php/8.3/ /etc/php/8.3xdbg
rm -rf /etc/php/8.3xdbg/fpm/pool.d
./link_rename.sh /etc/php/8.3xdbg/fpm/conf.d /etc/php/8.3/ /etc/php/8.3xdbg/
ln -s /etc/php/8.3xdbg/mods-available/xdebug.ini /etc/php/8.3xdbg/fpm/conf.d/20-xdebug.ini

# Remove xdebug from plain PHP versions
rm -f /etc/php/7.4/fpm/conf.d/20-xdebug.ini
rm -f /etc/php/8.0/fpm/conf.d/20-xdebug.ini
rm -f /etc/php/8.1/fpm/conf.d/20-xdebug.ini
rm -f /etc/php/8.2/fpm/conf.d/20-xdebug.ini
rm -f /etc/php/8.3/fpm/conf.d/20-xdebug.ini
rsync -r ./src/etc/php/ /etc/php/
rsync -r ./src/etc/init.d/ /etc/init.d/
rsync -r ./src/lib/systemd/system/ /lib/systemd/system/
Expand All @@ -47,12 +54,14 @@ chmod +x /etc/init.d/php7.4xdbg-fpm
chmod +x /etc/init.d/php8.0xdbg-fpm
chmod +x /etc/init.d/php8.1xdbg-fpm
chmod +x /etc/init.d/php8.2xdbg-fpm
chmod +x /etc/init.d/php8.3xdbg-fpm

# Add to auto start
systemctl enable php7.4xdbg-fpm
systemctl enable php8.0xdbg-fpm
systemctl enable php8.1xdbg-fpm
systemctl enable php8.2xdbg-fpm
systemctl enable php8.3xdbg-fpm


############################################
Expand Down
162 changes: 162 additions & 0 deletions src/etc/init.d/php8-3xdbg-fpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: php8.3xdbg-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 php8.3xdbg-fpm
# Description: Starts The PHP Xdebug FastCGI Process Manager Daemon
### END INIT INFO

# Author: Stephen J. Carnam <[email protected]>
export PHPRC=/etc/php/8.3xdbg/fpm
export PHP_INI_SCAN_DIR=/etc/php/8.3xdbg/fpm/conf.d
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="PHP 8.3 Xdebug FastCGI Process Manager"
NAME=php-fpm8.3
CONFFILE=/etc/php/8.3xdbg/fpm/php-fpm.conf
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--daemonize --fpm-config $CONFFILE"
CONF_PIDFILE=$(sed -n 's/^pid[ =]*//p' $CONFFILE)
PIDFILE=${CONF_PIDFILE:-/run/php/php8.3xdbg-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 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=QUIT/$TIMEOUT/TERM/5/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/TERM/5/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 USR2 --quiet --pidfile $PIDFILE --name $NAME
return 0
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
systemd-tmpfiles --remove --create /usr/lib/tmpfiles.d/php8.3xdbg-fpm.conf
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 $?
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
reopen-logs)
log_daemon_msg "Reopening $DESC logs" $NAME
if start-stop-daemon --stop --signal USR1 --oknodo --quiet \
--pidfile $PIDFILE --exec $DAEMON
then
log_end_msg 0
else
log_end_msg 1
fi
;;
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

:
145 changes: 145 additions & 0 deletions src/etc/php/8-3xdbg/fpm/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr). This prefix can be dynamically changed by using the
; '-p' argument from the command line.

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
; Warning: if you change the value here, you need to modify systemd
; service PIDFile= setting to match the value here.
pid = /run/php/php8.3xdbg-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; into a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php8.3xdbg-fpm.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php$8.3-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = error

; Log limit on number of characters in the single line (log entry). If the
; line is over the limit, it is wrapped on multiple lines. The limit is for
; all logged characters including message prefix and suffix if present. However
; the new line character does not count into it as it is present only when
; logging to a file descriptor. It means the new line character is not present
; when logging to syslog.
; Default Value: 1024
;log_limit = 4096

; Log buffering specifies if the log line is buffered which means that the
; line is written in a single write operation. If the value is false, then the
; data is written directly into the file descriptor. It is an experimental
; option that can potentially improve logging performance and memory usage
; for some heavy logging scenarios. This option is ignored if logging to syslog
; as it has to be always buffered.
; Default value: yes
;log_buffering = no

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
emergency_restart_threshold = 10

; Interval of time used by emergency_restart_interval to determine when
; a graceful restart will be initiated. This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 60s

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
process_control_timeout = 10s

; The maximum number of processes FPM will fork. This has been designed to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
; process.max = 128

; Specify the nice(2) priority to apply to the master process (only if set)
; The value can vary from -19 (highest priority) to 20 (lowest priority)
; Note: - It will only work if the FPM master process is launched as root
; - The pool process will inherit the master process priority
; unless specified otherwise
; Default Value: no set
; process.priority = -19

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes

; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
;rlimit_files = 1024

; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select (any POSIX os)
; - poll (any POSIX os)
; - epoll (linux >= 2.5.44)
; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll (Solaris >= 7)
; - port (Solaris >= 10)
; Default Value: not set (auto detection)
events.mechanism = epoll

; When FPM is built with systemd integration, specify the interval,
; in seconds, between health report notification to systemd.
; Set to 0 to disable.
; Available Units: s(econds), m(inutes), h(ours)
; Default Unit: seconds
; Default value: 10
;systemd_interval = 10

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options. The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p argument)
; - /usr otherwise
include=/etc/php/8.3xdbg/fpm/pool.d/*.conf
13 changes: 13 additions & 0 deletions src/etc/php/8-3xdbg/fpm/pool.d/dummy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; origin-src: deb/php-fpm/dummy.conf

[www]
listen = 127.0.0.1:9683
listen.allowed_clients = 127.0.0.1

user = www-data
group = www-data

pm = ondemand
pm.max_children = 4
pm.max_requests = 4000
pm.process_idle_timeout = 10s
4 changes: 4 additions & 0 deletions src/etc/php/8-3xdbg/mods-available/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zend_extension=xdebug.so
xdebug.start_with_request=yes
xdebug.mode=debug
xdebug.client_host=localhost
16 changes: 16 additions & 0 deletions src/lib/systemd/system/php8.3xdbg-fpm.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=The PHP 8.3 Xdebug FastCGI Process Manager
Documentation=man:php-fpm8.3(8)
After=network.target

[Service]
Type=notify
Environment=PHPRC=/etc/php/8.3xdbg/fpm
Environment=PHP_INI_SCAN_DIR=/etc/php/8.3xdbg/fpm/conf.d
ExecStart=/usr/sbin/php-fpm8.3 --nodaemonize --fpm-config /etc/php/8.3xdbg/fpm/php-fpm.conf
ExecStartPost=-/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.3xdbg/fpm/pool.d/www.conf 83
ExecStopPost=-/usr/lib/php/php-fpm-socket-helper remove /run/php/php-fpm.sock /etc/php/8.3xdbg/fpm/pool.d/www.conf 83
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 8c991a7

Please sign in to comment.