mdserver-web/plugins/php/versions/74/install.sh

185 lines
5.3 KiB
Bash
Raw Normal View History

2019-11-29 02:52:49 -05:00
#!/bin/bash
2023-11-10 05:47:32 -05:00
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
export PATH=$PATH:/opt/homebrew/bin
2019-11-29 02:52:49 -05:00
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
sourcePath=${serverPath}/source
sysName=`uname`
install_tmp=${rootPath}/tmp/mw_install.pl
2022-07-27 05:50:11 -04:00
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
function version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; }
function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
2022-08-22 18:52:54 -04:00
version=7.4.26
2019-11-30 05:28:34 -05:00
PHP_VER=74
2019-11-29 02:52:49 -05:00
Install_php()
{
#------------------------ install start ------------------------------------#
2023-11-10 05:47:32 -05:00
echo "安装php-${version} ..."
2019-11-29 02:52:49 -05:00
mkdir -p $sourcePath/php
mkdir -p $serverPath/php
2023-11-10 05:47:32 -05:00
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/php/lib && /bin/bash libzip.sh
# cd /www/server/mdserver-web/plugins/php/lib && /bin/bash libzip.sh
2022-09-20 02:29:46 -04:00
cd ${rootPath}/plugins/php/lib && /bin/bash freetype_new.sh
cd ${rootPath}/plugins/php/lib && /bin/bash zlib.sh
cd ${rootPath}/plugins/php/lib && /bin/bash libzip.sh
# redat ge 8
which yum
if [ "$?" == "0" ];then
cd ${rootPath}/plugins/php/lib && /bin/bash oniguruma.sh
fi
2019-11-30 05:28:34 -05:00
if [ ! -d $sourcePath/php/php${PHP_VER} ];then
2020-07-12 03:10:39 -04:00
# ----------------------------------------------------------------------- #
# 中国优化安装
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
LOCAL_ADDR=common
2023-10-01 08:34:27 -04:00
if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then
LOCAL_ADDR=cn
fi
if [ "$LOCAL_ADDR" == "cn" ];then
if [ ! -f $sourcePath/php/php-${version}.tar.xz ];then
wget --no-check-certificate -O $sourcePath/php/php-${version}.tar.xz https://mirrors.sohu.com/php/php-${version}.tar.xz
fi
fi
# ----------------------------------------------------------------------- #
2020-07-12 03:10:39 -04:00
if [ ! -f $sourcePath/php/php-${version}.tar.xz ];then
2022-06-24 09:48:39 -04:00
wget --no-check-certificate -O $sourcePath/php/php-${version}.tar.xz https://museum.php.net/php7/php-${version}.tar.xz
2020-07-12 03:10:39 -04:00
fi
2023-10-10 14:16:27 -04:00
#检测文件是否损坏.
md5_file_ok=0cbaae3de6c02cf8d7b82843fdfdf53d
if [ -f $sourcePath/php/php-${version}.tar.xz ];then
md5_file=`md5sum $sourcePath/php/php-${version}.tar.xz | awk '{print $1}'`
if [ "${md5_file}" != "${md5_file_ok}" ]; then
echo "PHP${version} 下载文件不完整,重新安装"
rm -rf $sourcePath/php/php-${version}.tar.xz
fi
fi
2020-07-12 03:10:39 -04:00
cd $sourcePath/php && tar -Jxf $sourcePath/php/php-${version}.tar.xz
mv $sourcePath/php/php-${version} $sourcePath/php/php${PHP_VER}
2019-11-29 02:52:49 -05:00
fi
2022-08-16 05:29:10 -04:00
if [ ! -d $sourcePath/php/php${PHP_VER} ];then
rm -rf $sourcePath/php/php-${version}.tar.xz
echo "reinstall php${version}"
exit 1
fi
2022-07-15 21:33:43 -04:00
2020-07-14 00:12:54 -04:00
cd $sourcePath/php/php${PHP_VER}
2019-11-29 02:52:49 -05:00
2023-11-10 14:17:10 -05:00
OPTIONS='--without-iconv'
2019-11-29 02:52:49 -05:00
if [ $sysName == 'Darwin' ]; then
2023-11-10 14:17:10 -05:00
2023-11-10 05:47:32 -05:00
OPTIONS="${OPTIONS} --with-curl"
OPTIONS="${OPTIONS} --with-external-pcre=$(brew --prefix pcre2)"
# BREW_DIR=`which brew`
# BREW_DIR=${BREW_DIR/\/bin\/brew/}
# XML_LIB_DEPEND_DIR=`brew info libxml2 | grep /opt/homebrew/Cellar/libxml2 | cut -d \ -f 1 | awk 'END {print}'`
# XML_LIB_DEPEND_DIR=`brew info libxml2 | grep ${BREW_DIR}/Cellar/libxml2 | cut -d \ -f 1 | awk 'END {print}'`
# OPTIONS="${OPTIONS} --with-libxml=${XML_LIB_DEPEND_DIR}"
2019-11-30 03:55:45 -05:00
2019-11-29 02:52:49 -05:00
else
OPTIONS="${OPTIONS} --with-curl"
2023-11-19 08:37:41 -05:00
OPTIONS="${OPTIONS} --with-readline"
2019-11-29 02:52:49 -05:00
fi
2022-07-15 21:33:43 -04:00
IS_64BIT=`getconf LONG_BIT`
if [ "$IS_64BIT" == "64" ];then
OPTIONS="${OPTIONS} --with-libdir=lib64"
fi
2022-06-27 05:26:59 -04:00
2020-07-14 00:12:54 -04:00
echo "$sourcePath/php/php${PHP_VER}"
2019-11-30 03:55:45 -05:00
2022-07-27 03:37:14 -04:00
ZIP_OPTION='--with-zip'
libzip_version=`pkg-config libzip --modversion`
2022-07-27 05:50:11 -04:00
if version_lt "$libzip_version" "0.11.0" ;then
2022-11-28 21:19:56 -05:00
cd ${rootPath}/plugins/php/lib && /bin/bash libzip.sh
2022-07-27 05:50:11 -04:00
export PKG_CONFIG_PATH=$serverPath/lib/libzip/lib/pkgconfig
ZIP_OPTION="--with-zip=$serverPath/lib/libzip"
2022-07-27 03:37:14 -04:00
fi
2022-10-06 02:16:46 -04:00
# ----- cpu start ------
if [ -z "${cpuCore}" ]; then
cpuCore="1"
fi
if [ -f /proc/cpuinfo ];then
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
fi
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
cpuCore="${MEM_INFO}"
fi
else
cpuCore="1"
fi
2022-10-06 03:32:30 -04:00
2022-11-05 22:10:34 -04:00
if [ "$cpuCore" -gt "2" ];then
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
else
cpuCore="1"
2022-10-06 03:32:30 -04:00
fi
2022-10-06 02:16:46 -04:00
# ----- cpu end ------
2020-07-13 21:02:10 -04:00
if [ ! -d $serverPath/php/${PHP_VER} ];then
2022-06-29 10:48:38 -04:00
cd $sourcePath/php/php${PHP_VER} && make clean
2023-08-05 05:23:52 -04:00
# ./buildconf --force
2019-11-30 03:55:45 -05:00
./configure \
2020-07-13 21:02:10 -04:00
--prefix=$serverPath/php/${PHP_VER} \
--exec-prefix=$serverPath/php/${PHP_VER} \
--with-config-file-path=$serverPath/php/${PHP_VER}/etc \
2019-11-29 10:00:04 -05:00
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir=$serverPath/lib/zlib \
2022-07-27 03:37:14 -04:00
$ZIP_OPTION \
2019-11-29 10:00:04 -05:00
--enable-ftp \
2022-07-16 03:13:19 -04:00
--enable-mbstring \
2019-11-29 10:00:04 -05:00
--enable-sockets \
--enable-simplexml \
--enable-soap \
--enable-posix \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
2022-06-11 23:10:54 -04:00
--disable-intl \
2019-11-29 10:00:04 -05:00
--disable-fileinfo \
$OPTIONS \
2022-06-24 10:19:26 -04:00
--enable-fpm
2022-10-06 02:16:46 -04:00
make clean && make -j${cpuCore} && make install && make clean
2023-10-30 13:05:23 -04:00
2023-10-30 15:13:13 -04:00
# rm -rf $sourcePath/php/php${PHP_VER}
2023-11-10 05:47:32 -05:00
echo "安装php-${version}成功"
2019-11-29 10:00:04 -05:00
fi
2019-11-29 02:52:49 -05:00
#------------------------ install end ------------------------------------#
}
Uninstall_php()
{
2020-07-13 21:08:19 -04:00
$serverPath/php/init.d/php${PHP_VER} stop
rm -rf $serverPath/php/${PHP_VER}
2023-11-10 05:47:32 -05:00
echo "卸载php-${version}..."
2019-11-29 02:52:49 -05:00
}
action=${1}
if [ "${1}" == 'install' ];then
Install_php
else
Uninstall_php
fi