Skip to content

Instantly share code, notes, and snippets.

@budiantoip
Last active June 12, 2025 22:18
Show Gist options
  • Save budiantoip/72b071366592e1d67d70d34c208ef246 to your computer and use it in GitHub Desktop.
Save budiantoip/72b071366592e1d67d70d34c208ef246 to your computer and use it in GitHub Desktop.
How to compile php 8.3.20 on CentOS 7

Compile PHP 8.3.20 along with all required extensions

#!/bin/bash

sudo su

yum groupinstall -y "Development Tools"
yum install -y epel-release
yum install -y gcc gcc-c++ make autoconf bison re2c libxml2-devel bzip2-devel curl-devel \
    libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel mariadb-devel \
    aspell-devel recode-devel openssl-devel sqlite-devel oniguruma-devel libzip-devel libicu-devel postgresql-devel \
    readline-devel libsodium-devel libxslt-devel libzip libzip-devel libmcrypt-devel
    
# BEGIN - Install CMake 3.27+ manually
cd /usr/local/src
curl -LO https://github.com/Kitware/CMake/releases/download/v3.27.9/cmake-3.27.9-linux-x86_64.tar.gz
tar -xzf cmake-3.27.9-linux-x86_64.tar.gz
mv cmake-3.27.9-linux-x86_64 /opt/cmake-3.27
export PATH=/opt/cmake-3.27/bin:$PATH
# Confirm it works
cmake --version
# END - Install CMake 3.27+ manually

# BEGIN - Download and build libzip 1.10.1 (or newer)
cd /usr/local/src
curl -LO https://github.com/nih-at/libzip/releases/download/v1.10.1/libzip-1.10.1.tar.gz
tar xzf libzip-1.10.1.tar.gz
cd libzip-1.10.1
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
make install
# END - Download and build libzip 1.10.1 (or newer)

export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH
export CFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib"
ldconfig

cd /usr/local/src
curl -O https://www.php.net/distributions/php-8.3.20.tar.gz
tar xzf php-8.3.20.tar.gz
cd php-8.3.20

./configure --prefix=/opt/php-8.3.20 \
--with-config-file-path=/opt/php-8.3.20/etc \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-bcmath \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-fpm \
--enable-ftp \
--enable-gd \
--with-gettext \
--with-iconv \
--enable-intl \
--with-libxml \
--enable-mbstring \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pear \
--with-pdo-mysql=mysqlnd \
--with-pdo-pgsql \
--with-pdo-sqlite \
--with-pgsql \
--enable-phar \
--enable-pcntl \
--enable-pdo \
--enable-posix \
--with-openssl \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-sodium \
--with-sqlite3 \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-tokenizer \
--enable-xml \
--enable-xmlreader \
--enable-xmlwriter \
--with-xsl \
--enable-opcache \
--with-zip \
--with-zlib

make -j$(nproc)
make install

# Install the mcrypt extension
/opt/php-8.3.20/bin/pecl install mcrypt
echo "extension=mcrypt.so" >> /opt/php-8.3.20/etc/php.ini

#/opt/php-8.3.20/bin/pear channel-update pear.php.net
#/opt/php-8.3.20/bin/pear install channel://pear.php.net/PHP_Archive-0.14.0

mkdir -p /opt/php-8.3.20/etc
cd /usr/local/src/php-8.3.20
cp php.ini-production /opt/php-8.3.20/etc/php.ini
cp sapi/fpm/php-fpm.conf /opt/php-8.3.20/etc/php-fpm.conf
cp sapi/fpm/www.conf /opt/php-8.3.20/etc/php-fpm.d/www.conf

sed -i 's/www-data/apache/g' /opt/php-8.3.20/etc/php-fpm.d/www.conf

groupadd apache
useradd -g apache -s /sbin/nologin apache

echo "export PATH=/opt/php-8.3.20/bin:\$PATH" > /etc/profile.d/custom-php8320.sh
chmod +x /etc/profile.d/custom-php8320.sh

# Reload shell
exec $SHELL -l

Create PHP-FPM service file

# Create PHP FPM service
cat > /etc/systemd/system/php83-fpm.service <<EOF
[Unit]
Description=The PHP 8.3.20 FastCGI Process Manager
After=network.target

[Service]
Type=simple
ExecStart=/opt/php-8.3.20/sbin/php-fpm --nodaemonize --fpm-config /opt/php-8.3.20/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 \$MAINPID
PrivateTmp=true
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload

systemctl enable php83-fpm
systemctl start php83-fpm

systemctl status php83-fpm
@bleve97
Copy link

bleve97 commented Jun 11, 2025

To make this work you may also need to set --enable-mbstring to --enable-mbstring=shared and then add in the mbstring.so module, and add it to php.ini. You need this if you're getting weird compile time errors.
worked for me on a couple of CentOS 7 servers.

@budiantoip
Copy link
Author

@bleve97 thank you for your suggestion!

@bleve97
Copy link

bleve97 commented Jun 12, 2025

my configure script, to build 8.3.22 on CentOS 7 to run Moodle :

more php_build-8.3.sh

# 8.3
# see : https://gist.github.com/budiantoip/72b071366592e1d67d70d34c208ef246
# a bunch of stuff is b0rked on Centos7 in the build kit
# we need to manually install an updated cmake so we can build a new
# libzip, and change how we handle mbstring.
# we put libzip into /usr/local/apache/2.4 using config
# see /usr/local/src/moodle/centos7-hacks

# /usr/local/apache/2.4/
export PKG_CONFIG_PATH=/usr/local/apache/2.4/lib64/pkgconfig:/usr/local/apache/2.4/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/apache/2.4/lib64:/usr/local/apache/2.4/lib:$LD_LIBRARY_PATH
export CFLAGS="-I/usr/local/apache/2.4/include"
export LDFLAGS="-L/usr/local/apache/2.4/lib64 -L/usr/local/apache/2.4/lib"
ldconfig

 ./configure --with-mysqli --with-apxs2=/usr/local/apache/2.4/bin/apxs --prefix=/usr/local/apache/2.4 --enable-gd --libdir=/usr/lib64 --with-libdir=lib64 --with-zip --with-config-file-path=/usr/local/apache/2.4/etc --with-jpeg --with-curl --with-zlib --with-openssl --enable-oap --enable-mbstring=shared --enable-opcache --enable-intl --with-sodium  --enable-exif --with-tidy

make

echo "remember to manually install opcache and mbstring in /usr/local/apache/2.4/modules"

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment