Php源码安装脚本

PHP源码安装脚本

系统环境:CentOS 7.4 软件版本:7.3.7

[root@localhost ~]# cat auto_install_php.sh

#!/usr/bin/env bash
# 2020-3-12 14:35:50
# Author: ^~^
# Auto Install PHP Server
 
source /etc/rc.d/init.d/functions
 
#Define PHP path variables
PHP_URL=http://mirrors.sohu.com/php
PHP_FILE=php-7.3.7.tar.gz
PHP_FILE_DIR=php-7.3.7
PHP_PREFIX=/usr/local/php
USER=www
 
#Define ZIP path variables
ZIP_URL=https://nih.at/libzip
ZIP_FILE=libzip-1.2.0.tar.gz
ZIP_FILE_DIR=libzip-1.2.0
 
function install_libzip (){
yum –y install wget gcc gcc-c++
wget -c ${ZIP_URL}/${ZIP_FILE}
tar zxf ${ZIP_FILE}
cd ${ZIP_FILE_DIR}
./configure
if [ $? -eq 0 ];then
    make && make install
    action "The Libzip Install Sussess..." /bin/true
else
    action "The Libzip Install Failed..." /bin/false
    exit 1
fi
    
cat >/etc/ld.so.conf <<EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
ldconfig -v
}
 
function install_php {
if [ ! -d ${PHP_PREFIX} ];then
#Install Package
yum -y install epel-release
yum -y install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devellibxml2 libxml2-devel  bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel cmake
cd ~ && wget -c ${PHP_URL}/${PHP_FILE}
tar zxf ${PHP_FILE}
cd ${PHP_FILE_DIR}
./configure --prefix=${PHP_PREFIX} \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=${USER} \
--with-fpm-group=${USER} \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
if [ $? -eq 0 ];then
    \cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
    make && make install
    action "The PHP Install Sussess..." /bin/true
else
    action "The PHP Install Failed..." /bin/false
    exit 1
fi
else
    echo -e "\033[31mThe PHP already Install...\033[0m"
    exit 1
fi
}
 
function config_php {
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
[www]
listen = 0.0.0.0:9000
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000
rlimit_files = 1024
slowlog = log/$pool.log.slow
EOF
systemctl enable php-fpm
systemctl start php-fpm
}
 

function main (){
install_libzip
install_php
config_php
}
 
main

Last updated