Last active
March 15, 2024 02:48
-
-
Save Abukamel/dd6d7b7db83b8db4e685f4cb3c56c550 to your computer and use it in GitHub Desktop.
Install PHP with FPM support from source on Centos 7 Server. Usage: bash installPHPFromSource 7.1.0 php7fpm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Names of latest versions of PHP package | |
export VERSION_PHP="php-${1}" | |
export FPM="${2}" | |
# PHP mirror URL | |
export SOURCE_PHP=http://php.net/get/${VERSION_PHP}.tar.bz2/from/this/mirror | |
# Path to local build | |
export BUILD_DIR=/usr/local/src/php | |
if [[ $# -ne 2 ]]; then | |
echo "Usage: ${0} php_version php_prefix" | |
exit 1 | |
fi | |
function setup() { | |
# create and clean build directory | |
mkdir -p ${BUILD_DIR} | |
rm -Rf ${BUILD_DIR}/* | |
# install build environment tools | |
yum -y groupinstall "Development Tools" | |
yum -y install libxml2-devel \ | |
bzip2-devel \ | |
libjpeg-devel \ | |
libX11-devel \ | |
gd-devel \ | |
libmcrypt-devel \ | |
mysql-devel \ | |
mhash-devel \ | |
libevent-devel \ | |
libtool-ltdl-devel \ | |
curl-devel libc-client-devel \ | |
libc-client-devel \ | |
zlib-devel libpng-devel \ | |
libxslt-devel \ | |
freetype-devel \ | |
gmp-devel \ | |
libXpm-devel \ | |
gmp-devel \ | |
libxmp-devel \ | |
libjpeg-devel \ | |
libpng-devel \ | |
libcurl-devel \ | |
bzip2-devel \ | |
libxml2-devel \ | |
xml2 \ | |
systemd-devel \ | |
bzip2-devel \ | |
curl-devel \ | |
libjpeg-devel \ | |
freetype-devel \ | |
libc-client-devel \ | |
libmcrypt-devel | |
} | |
function download_sources() { | |
# todo: verify checksum / integrity of downloads! | |
echo "Download sources" | |
pushd ${BUILD_DIR} | |
wget ${SOURCE_PHP} -O ${VERSION_PHP}.tar.bz2 | |
popd | |
} | |
function extract_sources() { | |
pushd ${BUILD_DIR} | |
tar xvf ${VERSION_PHP}.tar.bz2 | |
popd | |
} | |
function compile_php() { | |
pushd ${BUILD_DIR}/${VERSION_PHP} | |
make clean | |
./configure \ | |
--prefix=/opt/${FPM} \ | |
--with-mysqli \ | |
-with-openssl \ | |
--with-pcre-dir \ | |
--with-pcre-regex \ | |
--enable-sockets \ | |
--enable-wddx \ | |
--with-pdo-mysql \ | |
--enable-exif \ | |
--enable-zip \ | |
--with-bz2 \ | |
--with-pic \ | |
--with-xmlrpc \ | |
--enable-bcmath \ | |
--enable-calendar \ | |
--with-mysql \ | |
--with-gd \ | |
--with-gettext \ | |
--with-libdir=lib64 \ | |
--with-iconv \ | |
--with-jpeg-dir \ | |
--with-zlib \ | |
--with-curl \ | |
--with-config-file-scan-dir=/opt/${FPM}/lib/php.d \ | |
--with-freetype-dir \ | |
--with-png-dir \ | |
--with-xpm-dir \ | |
--enable-gd-native-ttf \ | |
--with-gmp \ | |
--enable-ftp \ | |
--enable-magic-quotes \ | |
--enable-sysvsem \ | |
--enable-fpm \ | |
--enable-mbstring \ | |
--enable-sysvshm \ | |
--enable-sysvmsg \ | |
--with-kerberos \ | |
--enable-shmop \ | |
--with-libxml-dir \ | |
--enable-xml \ | |
--with-mcrypt \ | |
--enable-soap \ | |
--with-fpm-systemd | |
make && make install | |
/opt/${FPM}/bin/pecl config-set php_ini /opt/${FPM}/lib/php.ini | |
/opt/${FPM}/bin/pear config-set php_ini /opt/${FPM}/lib/php.ini && \ | |
/opt/${FPM}/bin/pecl config-set temp_dir /root || /opt/${FPM}/bin/pear config-set temp_dir /root | |
popd | |
# Create systemd service file | |
touch /etc/systemd/system/${FPM}.service | |
cat <<EOF > /etc/systemd/system/${FPM}.service | |
[Unit] | |
Description=The PHP FastCGI Process Manager | |
After=syslog.target network.target | |
[Service] | |
Type=notify | |
LimitNOFILE=100000 | |
PIDFile=/opt/${FPM}/var/run/${FPM}.pid | |
#EnvironmentFile=/etc/sysconfig/${FPM} | |
ExecStart=/opt/${FPM}/sbin/php-fpm --nodaemonize | |
ExecReload=/bin/kill -USR2 \$MAINPID | |
PrivateTmp=true | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
# Enable the service at startup | |
systemctl enable ${FPM} | |
} | |
echo "Building ${VERSION_PHP}" | |
setup && download_sources && extract_sources && compile_php | |
retval=$? | |
echo "" | |
if [ $retval -eq 0 ]; then | |
echo "Your php binary is located at /opt/${FPM}/sbin/php-fpm" | |
else | |
echo "Ooops, build failed. Check output!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment