Debian Build PHP 8.2 From Source for aapanel

Install Dependencies

apt update && apt-get install build-essential \
pkg-config \
autoconf \
libtool \
bison \
re2c \
libavif-dev \
libxml2-dev \
libonig-dev \
libssl-dev \
libargon2-0-dev \
libsodium-dev \
libcurl4-openssl-dev \
libreadline-dev \
libyaml-dev \
libgmp-dev \
libzip-dev \
libpng-dev \
libjpeg-dev \
libwebp-dev \
libxpm-dev \
libicu-dev \
libfreetype6-dev \
libxslt-dev \
libldb-dev \
libtidy-dev \
libvips-dev \
libmagickcore-dev \
libmagickwand-dev

Download PHP 8 And Extension Source Code

Install_Directory=/www/mod
mkdir -p ${Install_Directory} && cd ${Install_Directory}
wget -c https://www.php.net/distributions/php-8.2.7.tar.gz -O - | tar -xz
wget -c https://pecl.php.net/get/igbinary-3.2.14.tgz -O - | tar -xz
wget -c https://pecl.php.net/get/msgpack-2.2.0.tgz -O - | tar -xz
wget -c https://pecl.php.net/get/apcu-5.1.22.tgz -O - | tar -xz
wget -c https://pecl.php.net/get/redis-5.3.7.tgz -O - | tar -xz
wget -c https://pecl.php.net/get/imagick-3.7.0.tgz -O - | tar -xz

Generate PHP Build Configuration

cd ${Install_Directory}/php-8.2.*
./configure --prefix=/www/server/php/82 \
--with-config-file-path=/www/server/php/82/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-avif \
--with-curl \
--with-freetype \
--with-gettext \
--with-gmp \
--with-jpeg \
--with-mhash \
--with-openssl \
--with-password-argon2 \
--with-pear \
--with-readline \
--with-readline \
--with-sodium \
--with-tidy \
--with-webp \
--with-xsl \
--with-zip \
--with-zlib \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-fileinfo \
--enable-fpm \
--enable-ftp \
--enable-gd \
--enable-intl \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml 

Build & Install PHP 8

make -j $(nproc) && make install

Build & Install PHP Extension

install extension igbinary msgpack apcu imagick and redis with igbinary support

cat >cmd.sh <<\EOF
#!/bin/sh
Version=82
Install_Folder="/www/mod"
Install_Bin_Folder="/www/server/php/${Version}/bin"
phpConfig="--with-php-config=${Install_Bin_Folder}/php-config"
extArray=("igbinary" "msgpack" "apcu" "imagick" "redis")

BuildFun(){
  cd ${Install_Folder}/${1}* && make clean
  ${Install_Bin_Folder}/phpize
  if [ ${1} != redis ] ;then ./configure ${phpConfig}
    else ./configure ${phpConfig} --enable-redis-igbinary
  fi
  make -j $(nproc) && make install
}

for ext in ${extArray[@]};do BuildFun $ext ;done
EOF

bash cmd.sh

Enable System RAM Hugepages

echo vm.nr_hugepages=128 >> /etc/sysctl.conf && sysctl -p

Configure PHP 8

  • Conflict Configuretion File Need To Delete For aapanel
    rm /www/server/php/82/etc/php-cli.ini
  • Optimization
    • Use Opcache Cache
    • Use igbinary As PHP Serialize Handler
      • session.serialize_handler = igbinary
    • Use redis As PHP Session Handler
      • session.save_handler = redis
        session.save_path = "unix:///tmp/redis.sock?persistent=1&weight=1&database=0"
  • Conflict Seting Needs To Disable
    • ;session.serialize_handler = php
    • ;session.save_handler = file
nano /www/server/php/82/etc/php.ini
[Zend Opcache]
zend_extension = opcache.so
opcache.enable = 1
opcache.enable_cli = 1
opcache.fast_shutdown = 1
opcache.huge_code_pages=1
opcache.save_comments = 1
opcache.memory_consumption = 1024
opcache.interned_strings_buffer = 128
opcache.max_accelerated_files = 120000
opcache.max_wasted_percentage = 50
;opcache.revalidate_freq = 60  ;For only nextcloud server
;opcache.jit = 1205 
;opcache.jit_buffer_size = 512m ; BeAware JIT may cause Segmentation fault

[apcu]
extension = apcu.so
apc.enable_cli = 1
apc.shm_size = 512M

[igbinary]
extension = igbinary.so
session.serialize_handler = igbinary
apc.serializer = igbinary

[msgpack]
extension = msgpack.so
;session.serialize_handler = msgpack ; igbinary or msgpack as serialize_handler

[redis]
extension = redis.so
session.save_handler = redis
session.save_path = "unix:///tmp/redis.sock?persistent=1&weight=1&database=0"
redis.session.locking_enabled=1
redis.session.lock_retries=-1
redis.session.lock_wait_time=10000

[ImageMagick]
extension = imagick.so

Leave a Comment