Skip to content

Instantly share code, notes, and snippets.

@lostsnow
Last active February 11, 2022 04:10
Show Gist options
  • Save lostsnow/b43a1f53752b503a7343ac46c661cd42 to your computer and use it in GitHub Desktop.
Save lostsnow/b43a1f53752b503a7343ac46c661cd42 to your computer and use it in GitHub Desktop.

php

set current version

PHP_VERSION=7.1

ulimit

set ulimit

sudo bash -c 'echo "fs.file-max = 65536" >> /etc/sysctl.conf'
sudo bash -c 'echo "fs.suid_dumpable = 1" >> /etc/sysctl.conf'
sudo sysctl -p

sudo bash -c 'cat << EOF >> /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
* soft core 65535
* hard core 65535
EOF'

coredump

Some possible default coredump paths

  • /var/lib/apport/coredump/
  • /var/crash/
  • /var/lib/systemd/coredump/
  • /var/spool/abort/

Custom coredump path

sudo bash -c 'echo "kernel.core_pattern = /tmp/coredump-%e.%p.%t" >> /etc/sysctl.conf'
sudo sysctl -p

run gdb with coredump file

gdb /usr/local/php${PHP_VERSION}-debug/sbin/php-fpm /tmp/coredump-php-fpm.2393

centos7

yum install centos-release-scl
yum install devtoolset-7
scl enable devtoolset-7 bash

systemd

sudo sed -i 's/.*DefaultLimitCORE.*/DefaultLimitCORE=infinity/' /etc/systemd/system.conf

php-fpm

sudo bash -c 'cat << EOF > /lib/systemd/system/php'${PHP_VERSION}'-debug-fpm.service
[Unit]
Description=The PHP '${PHP_VERSION}' debug FastCGI Process Manager
Documentation=man:php-fpm'${PHP_VERSION}'(8)
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/php'${PHP_VERSION}'-debug/sbin/php-fpm --nodaemonize
ExecReload=/bin/kill -USR2 \$MAINPID

[Install]
WantedBy=multi-user.target
EOF'

nginx

mkdir -p /etc/nginx/includes
sudo bash -c "cat << EOF > /etc/nginx/includes/php${PHP_VERSION}-debug.conf
    fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-debug-fpm.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
EOF"

set current php version

sudo ln -sf /etc/nginx/includes/php${PHP_VERSION}-debug.conf /etc/nginx/includes/php.conf

vhost

    # current version
    location ~ .php$ {
        try_files $uri =404;
        include includes/php.conf;
    }

    # or speciafic version
    location ~ .php$ {
        try_files $uri =404;
        include includes/php7.1-debug.conf;
    }

php

7.1

# @TODO:
apt install libxml2-dev libbz2-dev libpng-dev libjpeg-dev

compiler

./configure --prefix=/usr/local/php${PHP_VERSION}-debug \
    --enable-debug \
    --enable-cli --disable-cgi --disable-phpdbg \
    --with-config-file-path=/usr/local/php${PHP_VERSION}-debug/etc \
    --with-config-file-scan-dir=/usr/local/php${PHP_VERSION}-debug/etc/conf.d \
    --disable-rpath --with-pic --enable-pcntl \
    --with-openssl=yes --with-pcre-regex --enable-exif \
    --enable-hash --with-mhash=/usr --enable-mbstring --enable-mbregex \
    --with-libxml-dir=/usr --enable-libxml --enable-session \
    --with-zlib --with-zlib-dir=/usr --with-iconv --enable-bcmath --with-bz2 --enable-zip --with-gd \
    --enable-fpm --with-fpm-user=www --with-fpm-group=www \
    --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
    --with-curl --with-gettext --enable-filter --enable-ftp --enable-sockets --with-xmlrpc
make
sudo make install

config

sudo cp php.ini-development /usr/local/php${PHP_VERSION}-debug/etc/php.ini
sudo mkdir -p /usr/local/php${PHP_VERSION}-debug/etc/conf.d

sudo cp /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.conf.default /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.conf
sudo cp /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf.default /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf

sudo sed -i 's#^[; ]*pid =.*#pid = run/php-fpm.pid#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.conf
sudo sed -i 's#^[; ]*error_log =.*#error_log = log/php-fpm.log#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.conf

sudo sed -i 's#^[; ]*user =.*#user = www#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
sudo sed -i 's#^[; ]*group =.*#group = www#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
sudo sed -i "s#^[; ]*listen =.*#listen = /run/php/php${PHP_VERSION}-debug-fpm.sock#" /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
sudo sed -i 's#^[; ]*listen.owner =.*#listen.owner = www#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
sudo sed -i 's#^[; ]*listen.group =.*#listen.group = www#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
sudo sed -i 's#^[; ]*process.dumpable =.*#process.dumpable = yes#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
sudo sed -i 's#^[; ]*rlimit_core =.*#rlimit_core = unlimited#' /usr/local/php${PHP_VERSION}-debug/etc/php-fpm.d/www.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment