php-fpm編譯安裝腳本

  PHP是開源、輕量級、高效的開發語言,特別適合web項目開發,在中小型互聯網公司中經常使用於開發web後端。PHP常與Nginx及MySQL數據庫結合,搭建LNMP環境。如下爲centos7系統下php-fpm的一鍵編譯安裝腳本,代碼以下:php

#!/bin/bash
#
#********************************************************************
#Author:        Eddie.Peng
#URL:           https://www.cnblogs.com/eddie1127/
#Date:          2019-10-18
#FileName:      php-fpm_install.sh
#Description:   The script for install php-fpm
#********************************************************************

# Set colour
COLORBEG="\033[1;31m"
COLOREND="\033[0m"

# Check if user is root
if [ $(id -u) !=0 ];then
    echo -e "${COLORBEG} Error! You must be root to run this script. ${COLOREND}"
    exit 10
fi

clear
echo "========================================================================"
echo " "
echo "The script for install php-fpm"
echo " "
echo "========================================================================="


# Install dependent software packge
yum -y install epel-release wget gcc \
    curl-devel openssl-devel libxml2-devel \
    bzip2-devel libmcrypt-devel php-gd php-mysqlnd

#Check files if exits
echo "========================== Check files ===================================="
CUR_DIR=$(pwd)
NAME=php-7.3.10
FULL_NAME=${CUR_DIR}/${NAME}.tar.xz
INSTALL_PATH=/usr/local/php

cd $CUR_DIR
if [ -s $FULL_NAME ];then
    echo "$FULL_NAME found!"
else
    echo -e "${COLORBEG} $FULL_NAME not found!!! download now... ${COLOREND}"
    wget -c https://www.php.net/distributions/$NAME.tar.xz
fi

#Install php-fpm
echo "========================== Install php-fpm ===================================="
cd $CUR_DIR
tar -xf $FULL_NAME -C /usr/local/src
cd /usr/local/src/$NAME
./configure --prefix=$INSTALL_PATH \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-curl \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo

make -j $(nproc) && make install

if [ $? -ne 0 ];then
    echo -e "${COLORBEG} Error!make failed,please check. ${COLOREND}"
    exit 20
fi

#Prepare configuration files
cp $INSTALL_PATH/etc/php-fpm.conf.default $INSTALL_PATH/etc/php-fpm.conf
cp $INSTALL_PATH/etc/php-fpm.d/www.conf.default $INSTALL_PATH/etc/php-fpm.d/www.conf
cp /usr/local/src/$NAME/php.ini-production /etc/php.ini

#Open opcache extension
mkdir /etc/php.d
cat > /etc/php.d/opcache.ini << EOF
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
EOF

#Check install
echo "========================== Check install ==========================================="
clear
INSTALL=""

echo "Checking..."
if [ -s $INSTALL_PATH/sbin/php-fpm ] && [ -s $INSTALL_PATH/etc/php-fpm.conf ] && [ -s /etc/php.ini ];then
    echo -e "\033[1;32m php-fpm install OK \033[0m"
    INSTALL="OK"
else
    echo -e "${COLORBEG} Error! $INSTALL_PATH/etc/php-fpm.conf not found! php-fpm install failed,please check. ${COLOREND}"
fi

if [ "$INSTALL" = "OK" ];then
    echo -e "\033[1;32m Congratulation!php-fpm install completed! Enjoy it. \033[0m"
    echo "================================================================================"
    echo "The path of some dirs:"
    echo "php-fpm_exec_dir: $INSTALL_PATH/sbin"
    echo "php-fpm config_dir: $INSTALL_PATH/etc"
    echo "php configfile: /etc/php.ini"
    echo "================================================================================="
else
    echo -e "${COLORBEG} Sorry,php-fpm install Failed! Please check and reinstall. ${COLOREND}"
    exit 30
fi

#Add php-fpm service on start up
cp /usr/local/src/$NAME/sapi/fpm/php-fpm.service /usr/lib/systemd/system
systemctl daemon-reload
systemctl enable --now php-fpm.service

#Check startup
if [ $? -eq 0 ];then 
    echo -e "\033[1;32m php-fpm service start success \033[0m"
else
    echo -e "${COLORBEG} php-fpm service start failed,please check ${COLOREND}"
fi
相關文章
相關標籤/搜索