Skip to content

Instantly share code, notes, and snippets.

@latuminggi
Last active May 29, 2024 16:26
Show Gist options
  • Save latuminggi/998d5738ebb8d9a1c56e34602c17804a to your computer and use it in GitHub Desktop.
Save latuminggi/998d5738ebb8d9a1c56e34602c17804a to your computer and use it in GitHub Desktop.
COMPILE PHP 8.0 RHEL/(CentOS?) 6
### COMPILE PHP 8.0 RHEL/(CentOS?) 6 ###
# You can find PHP 8.0 repository here:
# https://pkgs.dyn.su/el6-extras/x86_64
# installing dependencies
# https://coderwall.com/p/ggmpfa/php-configuration-error-and-solutions-in-rpm
yum install -y autoconf autotools gmp-devel libcurl-devel postgresql postgresql-devel sqlite sqlite-devel \
libxslt-devel net-snmp-devel readline-devel aspell aspell-devel unixODBC-devel libicu-devel libc-client-devel \
freetype-devel libXpm-devel libpng-devel libvpx-devel enchant-devel libmcrypt-devel libmemcached-devel \
libzip-devel libtidy libtidy-devel openldap openldap-devel cyrus-sasl-devel krb5-devel krb5-libs \
oniguruma oniguruma-devel libssh2-devel
export PHP_AUTOCONF=/opt/rh/autotools/root/usr/bin/autoconf && \
export PHP_AUTOHEADER=/opt/rh/autotools/root/usr/bin/autoheader
# install perl yaml & text template
cpan YAML
cpan -i Text :: Template
cpan -f -i Text :: Template
# install latest openssl
mkdir -p /opt/openssl
git clone https://github.com/openssl/openssl.git && \
cd openssl && \
git checkout OpenSSL_1_1_1-stable && \
./config -fPIC shared --prefix=/opt/openssl && \
make -j$(nproc)
make test
make install
# install latest curl
mkdir -p /opt/curl
git clone https://github.com/curl/curl.git && \
cd curl && \
./buildconf
env PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig ./configure --with-ssl --prefix=/opt/curl
make -j$(nproc)
make test
make install
# install newer curl
wget http://apt-mirror.sepia.ceph.com/centos6-qemu-kvm/curl-7.29.0-6.el6.x86_64.rpm \
http://apt-mirror.sepia.ceph.com/centos6-qemu-kvm/libcurl-7.29.0-6.el6.x86_64.rpm \
http://apt-mirror.sepia.ceph.com/centos6-qemu-kvm/libcurl-devel-7.29.0-6.el6.x86_64.rpm
rpm -Uvh curl-7.29.0-6.el6.x86_64.rpm libcurl-7.29.0-6.el6.x86_64.rpm libcurl-devel-7.29.0-6.el6.x86_64.rpm
# install newer libxml2
wget http://xmlsoft.org/download/libxml2-2.9.0.tar.gz &&
tar xvf libxml2-2.9.0.tar.gz && \
cd libxml2-2.9.0 && \
./configure && \
make -j$(nproc) && make install
# install latest oniguruma
mkdir -p /opt/oniguruma && \
git clone https://github.com/kkos/oniguruma && \
cd oniguruma && \
autoreconf -vfi && \
./configure --prefix=/opt/oniguruma && \
make -j$(nproc)
make check
make install
# install newer icu
mkdir -p /opt/icu && \
wget https://github.com/unicode-org/icu/archive/refs/tags/release-50-1-2.tar.gz -O icu-50-1-2.tar.gz && \
tar xvf icu-50-1-2.tar.gz && \
cd icu-release-50-1-2/icu4c/source && \
sed -i '/#define __UCONFIG_H__/a #define UCONFIG_ENABLE_PLUGINS 1' common/unicode/uconfig.h && \
./configure --prefix=/opt/icu --bindir=/usr/bin --libdir=/usr/lib64 --datadir=/usr/share --enable-plugins && \
make -j$(nproc) && make install
# install libjpeg-turbo
cd /etc/yum.repos.d && \
wget https://libjpeg-turbo.org/pmwiki/uploads/Downloads/libjpeg-turbo.repo && \
yum install -y libjpeg-turbo-official
# install newer libwebp
mkdir -p /opt/libwebp && \
wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.0.tar.gz && \
tar xvf libwebp-1.2.0.tar.gz && \
cd libwebp-1.2.0 && \
./configure --prefix=/opt/libwebp --disable-png && \
make -j$(nproc)
make check
make install
# install oracle instantclient
mkdir -p /opt/oracle && \
cd /opt/oracle && \
wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip \
https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-sdk-linux.x64-19.9.0.0.0dbru.zip && \
unzip instantclient-basic-linux.x64-19.9.0.0.0dbru.zip && \
unzip instantclient-sdk-linux.x64-19.9.0.0.0dbru.zip && \
echo "/opt/oracle/instantclient_19_9" > /etc/ld.so.conf.d/instantclient.conf
# compiling php
mkdir -p /opt/php-8.0 && \
mkdir -p /usr/systemd/rpm/php && \
cd /usr/systemd/rpm/php && \
wget https://www.php.net/distributions/php-8.0.6.tar.bz2 && \
tar jxf php-8.0.6.tar.bz2 && \
cd php-8.0.6
# alter gmp ext
sed -i 's#typedef mp_bitcnt_t (\*gmp_unary_opl_t)(mpz_srcptr);#/*typedef mp_bitcnt_t (\*gmp_unary_opl_t)(mpz_srcptr);*/#g' ext/gmp/gmp.c && \
sed -i 's#static inline void _gmp_unary_opl(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_opl_t gmp_op)#/*static inline void _gmp_unary_opl(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_opl_t gmp_op)*/\nstatic inline void _gmp_unary_opl(INTERNAL_FUNCTION_PARAMETERS)#g' ext/gmp/gmp.c && \
sed -i 's#gmp_unary_opl(mpz_popcount);#/*gmp_unary_opl(mpz_popcount);*/#g' ext/gmp/gmp.c
# configure php
export ORACLE_HOME=/opt/oracle/instantclient_19_9 && \
export LIBXML_LIBS=/usr/local/lib LIBXML_CFLAGS=/usr/local/lib && \
export SASL_LIBS=/usr/local/lib SASL_CFLAGS=/usr/local/lib && \
export KERBEROS_LIBS=/usr/include KERBEROS_CFLAGS=/usr/include && \
export PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig:/opt/curl/lib/pkgconfig:\
/opt/icu/lib/pkgconfig:/opt/oniguruma/lib/pkgconfig:\
/opt/libjpeg-turbo/lib64/pkgconfig:/opt/libwebp/lib/pkgconfig:\
/usr/lib64/pkgconfig && \
./configure --prefix=/opt/php-8.0 --with-pdo-pgsql=/usr/pgsql-10 --enable-mbstring --with-bz2 \
--enable-soap --enable-calendar --with-curl=/opt/curl --with-zlib --with-zlib-dir --with-pgsql=/usr/pgsql-10 \
--enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif \
--enable-bcmath --with-mhash --with-pdo-mysql --with-mysqli --with-mysql-sock \
--with-openssl=shared --with-openssl-dir=/opt/openssl --with-fpm-user=nginx --with-fpm-group=nginx \
--with-libdir=/lib64 --enable-ftp --with-gettext --with-xsl --enable-opcache --enable-fpm --enable-dba \
--with-gmp=/usr --with-imap-ssl --with-kerberos --with-mhash --enable-shmop --with-pdo-odbc=unixODBC,/usr \
--with-readline=/lib64 --with-pdo-oci=instantclient,$ORACLE_HOME --enable-sysvmsg --enable-sigchild \
--enable-gd --with-jpeg --with-xpm --with-webp --with-freetype \
--enable-phpdbg --enable-intl --with-pear --with-zip --with-tidy=/usr \
--with-ldap=/usr/lib64/evolution-openldap --with-ldap-sasl --with-pspell
make -j$(nproc) && \
make test && \
make install
## start copying configs to the right places.
## p.s once already execute & running should NOT be redo !
cp /usr/systemd/rpm/php/php-8.0.6/php.ini-production /opt/php-8.0/lib/php.ini && \
cp /opt/php-8.0/etc/php-fpm.conf.default /opt/php-8.0/etc/php-fpm.conf && \
cp /opt/php-8.0/etc/php-fpm.d/www.conf.default /opt/php-8.0/etc/php-fpm.d/www.conf
nano /opt/php-8.0/etc/php-fpm.conf
## add/change following
pid = run/php-8.0-fpm.pid
nano /opt/php-8.0/etc/php-fpm.d/www.conf
## add/change following
listen = 9080
sed -i 's/;date.timezone =/date.timezone = "Asia\/Jakarta"/g' /opt/php-8.0/lib/php.ini && \
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /opt/php-8.0/lib/php.ini
cd /etc/init.d/ && \
wget https://gist.githubusercontent.com/latuminggi/998d5738ebb8d9a1c56e34602c17804a/\
raw/2be41f0400f68060ff4ea45af398aea78ffc27f8/php-8.0-fpm && \
chmod 755 /etc/init.d/php-8.0-fpm && \
chkconfig --add /etc/init.d/php-8.0-fpm
ln -s /opt/php-8.0/bin/php /usr/bin/php8.0
ln -s /opt/php-8.0/sbin/php-fpm /usr/bin/php8.0-fpm
## end of configs
### php extensions ###
# ls -al /opt/php-8.0/lib/php/extensions/no-debug-non-zts-20200930
# using pecl/pear
/opt/php-8.0/bin/pecl -C /opt/php-8.0/etc/pear.conf update-channels
/opt/php-8.0/bin/pecl -C /opt/php-8.0/etc/pear.conf install memcached
/opt/php-8.0/bin/pear install http://pecl.php.net/get/memcached-3.1.5.tgz
mkdir -p /usr/systemd/rpm/php/ext/8.0
# installing apcu ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/apcu-5.1.20.tgz && \
tar xvf apcu-5.1.20.tgz && \
cd apcu-5.1.20 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# installing igbinary ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/igbinary-3.2.2.tgz && \
tar xvf igbinary-3.2.2.tgz && \
cd igbinary-3.2.2 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# install latest imagemagick
mkdir -p /opt/ImageMagick && \
git clone https://github.com/ImageMagick/ImageMagick.git && \
cd ImageMagick && \
./configure --prefix=/opt/ImageMagick --with-fftw --with-gslib --with-gvc --with-jxl --with-rsvg --with-wmf
make -j$(nproc)
make check
make install
# installing imagick ====
cd /usr/systemd/rpm/php/ext/8.0 && \
git clone https://github.com/Imagick/imagick && \
cd imagick && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config --with-imagick=/opt/ImageMagick && \
make -j$(nproc) && \
make test && \
make install
# installing mcrypt ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/mcrypt-1.0.4.tgz && \
tar xvf mcrypt-1.0.4.tgz && \
cd mcrypt-1.0.4 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# installing msgpack ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/msgpack-2.1.2.tgz && \
tar xvf msgpack-2.1.2.tgz && \
cd msgpack-2.1.2 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# installing memcache ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/memcache-8.0.tgz && \
tar xvf memcache-8.0.tgz && \
cd memcache-8.0 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# installing memcached ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/memcached-3.1.5.tgz && \
tar xvf memcached-3.1.5.tgz && \
cd memcached-3.1.5 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config \
--enable-memcached-igbinary --enable-memcached-json --enable-memcached-msgpack && \
make -j$(nproc) && \
make test && \
make install
# installing oci8 ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/oci8-3.0.1.tgz && \
tar xvf oci8-3.0.1.tgz && \
cd oci8-3.0.1 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config --with-oci8=instantclient,$ORACLE_HOME && \
make -j$(nproc) && \
make test && \
make install
# installing uploadprogress ====
cd /usr/systemd/rpm/php/ext/8.0 && \
git clone https://github.com/php/pecl-php-uploadprogress && \
cd pecl-php-uploadprogress && \
sed -i "31i\
ZEND_BEGIN_ARG_INFO_EX(arginfo_uploadprogress_get_info, 0, 0, 1)\
ZEND_ARG_INFO(0, identifier)\
ZEND_END_ARG_INFO()\
ZEND_BEGIN_ARG_INFO_EX(arginfo_uploadprogress_get_contents, 0, 0, 2)\
ZEND_ARG_INFO(0, identifier)\
ZEND_ARG_INFO(0, fieldname)\
ZEND_ARG_INFO(0, maxlen)\
ZEND_END_ARG_INFO()" uploadprogress.c && \
sed -i 's/PHP_FE(uploadprogress_get_info, NULL)/PHP_FE(uploadprogress_get_info, arginfo_uploadprogress_get_info)/g' \
uploadprogress.c && \
sed -i 's/PHP_FE(uploadprogress_get_contents, NULL)/PHP_FE(uploadprogress_get_contents, arginfo_uploadprogress_get_contents)/g' \
uploadprogress.c && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# installing ssh2 ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/ssh2-1.3.1.tgz && \
tar xvf ssh2-1.3.1.tgz && \
cd ssh2-1.3.1 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config && \
make -j$(nproc) && \
make test && \
make install
# installing redis ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/ssh2-1.3.1.tgz && \
tar xvf ssh2-1.3.1.tgz && \
cd ssh2-1.3.1 && \
/opt/php-8.0/bin/phpize && \
./configure --with-php-config=/opt/php-8.0/bin/php-config \
--enable-redis-igbinary --enable-redis-msgpack && \
make -j$(nproc) && \
make test && \
make install
# installing mongodb ====
cd /usr/systemd/rpm/php/ext/8.0 && \
wget https://pecl.php.net/get/mongodb-1.9.1.tgz && \
tar xvf mongodb-1.9.1.tgz && \
cd mongodb-1.9.1 && \
/opt/php-8.0/bin/phpize && \
env PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig:/opt/icu/lib/pkgconfig \
./configure --with-php-config=/opt/php-8.0/bin/php-config --with-openssl-dir=/opt/openssl && \
make -j$(nproc) all && \
make test && \
make install
# add extension to php.ini
echo extension=openssl.so >> /opt/php-8.0/lib/php.ini
echo extension=apcu.so >> /opt/php-8.0/lib/php.ini
echo extension=igbinary.so >> /opt/php-8.0/lib/php.ini
echo extension=imagick.so >> /opt/php-8.0/lib/php.ini
echo extension=mcrypt.so >> /opt/php-8.0/lib/php.ini
echo extension=msgpack.so >> /opt/php-8.0/lib/php.ini
echo extension=memcache.so >> /opt/php-8.0/lib/php.ini
echo extension=memcached.so >> /opt/php-8.0/lib/php.ini
echo extension=oci8.so >> /opt/php-8.0/lib/php.ini
echo extension=uploadprogress.so >> /opt/php-8.0/lib/php.ini
echo extension=ssh2.so >> /opt/php-8.0/lib/php.ini
echo extension=redis.so >> /opt/php-8.0/lib/php.ini
echo extension=mongodb.so >> /opt/php-8.0/lib/php.ini
echo zend_extension=opcache.so >> /opt/php-8.0/lib/php.ini
# opcache.ini (opcache confs on php.ini)
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.file_cache => 1 => 1
opcache.file_cache_consistency_checks => Off => Off
opcache.file_cache_only => Off => Off
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.interned_strings_buffer => 8 => 8
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 10000 => 10000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 1024 => 1024
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFEBFFF => 0x7FFEBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => Off => Off
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 0 => 0
opcache.revalidate_path => Off => Off
opcache.save_comments => Off => Off
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-8.0-fpm
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-8.0-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php-8.0/sbin/php-fpm
php_fpm_CONF=/opt/php-8.0/etc/php-fpm.conf
php_fpm_PID=/opt/php-8.0/var/run/php-8.0-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-exit"
exit 1
else
echo " done"
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment