mac编译php脚本
#!/bin/sh
# 用法如下
# curl --output make-php.sh https://qidizi.github.io/bash/make-php.sh && bash make-php.sh 要编译源码目录的路径
# 编译扩展时,步骤是:把扩展源放到ext目录下 > cd 到扩展目录 > ./qidizi/bin/phpize > bash configure --with-php-config=./qidizi/bin/php-config
# > make > make install 就能正常使用了
#有些系统默认不安装realpath命令,这里自己实现,shell的function返回字符中只能echo,然后调用时通过re=$(realPath 'kkk')来获得
function realPath() {
#得到当前文件的绝对路径,()会fork一个subshell,所以,cd并不会影响parentShell的pwd
realPath=$(cd `dirname "${1}"`; pwd)
name=$(basename "${1}");
if [[ "${name}" = "." || "${name}" = ".." ]];then
name="";
fi
realPath="${realPath}/${name}"
realPath="${realPath//\/\//\/}";
realPath="${realPath//\/.\//\/}";
echo "${realPath}"
return 0;
}
# exit2fail 上个命令退出值 退出提示[操作失败] 退出码[1]
function exit2fail () {
if [[ "$1" -ne "0" ]];then
if [[ -z "$2" ]];then
echo "操作失败";
else
echo "$2";
fi
if [[ -z "$3" ]];then
exit 1;
else
exit $3;
fi
fi
}
# 目录不存在就退出,参数1为目录路径
function exit2notDir() {
if [[ ! -d "${1}" ]];then
echo -n "目录 \n[${1}] 不存在";
exit 2;
fi
}
if [[ "$#" -eq "0" ]];then
echo "用法";
echo "${0} php源码文件夹路径";
exit;
fi
echo "jpeg-6b 编译时,需要手工创建build目录,和手工copy根src目录的h文件到build.d/include,和手工复制到*.a到build.d/lib";
echo "已了解提醒[回车继续]:"
read any;
myDir=$(realPath $1);
#echo $myDir;exit;
exit2notDir "$myDir"
if [[ ! -d "${myDir}/ext/xdebug" ]];then
echo "请到 https://xdebug.org/download.php 下载xdebug扩展并解压到${myDir}/ext/xdebug;如:"
echo "curl -o x.tgz --location http://xdebug.org/files/xdebug-2.7.2.tgz && tar -vxf x.tgz && rm -rf x.tgz && mv xdebug-2.7.2 ${myDir}/ext/xdebug "
exit;
fi
cd "${myDir}"
echo "清空旧编译..."
make clean
echo "配置 ${myDir}..."
qidizi="${myDir}/qidizi"
bash configure \
--prefix="${qidizi}" \
--with-config-file-path=${qidizi}/etc \
--enable-fpm \
--disable-short-tags \
--disable-ipv6 \
--enable-bcmath \
--enable-mbstring \
--enable-zip \
--with-bz2=${myDir}/../bzip2/qidizi \
--with-zlib=${myDir}/../zlib/qidizi/ \
--enable-mysqlnd \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mcrypt="${myDir}/../libmcrypt/qidizi" \
--enable-sockets \
--enable-debug \
--with-mhash \
--with-curl="${myDir}/../curl/qidizi" \
--with-libzip="${myDir}/../libzip/build/qidizi/usr/local" \
--with-openssl="${myDir}/../openssl/qidizi" \
--with-gd \
--with-png-dir="${myDir}/../libpng/qidizi" \
--enable-gd-native-ttf \
--with-jpeg-dir="${myDir}/../jpeg-6b/qidizi" \
--with-iconv-dir="${myDir}/../libiconv/qidizi" \
--with-freetype-dir="${myDir}/../freetype/qidizi" \
--enable-shmop \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--without-iconv
# 目前iconv还不能编译
exit2fail $?
echo -e "\n\n 配置成功!\n\n"
make
exit2fail $?
echo -e "\n\n 编译成功 \n\n"
# 指定安装目录
make install
exit2fail $?
echo -e "\n\n\n ${myDir} build成功"
echo "编译xdebug扩展..."
# 这是一个扩展的编译流程,若有其它的也可以加,或是独立手工操作
cd ${myDir}/ext/xdebug;
${myDir}/qidizi/bin/phpize;
exit2fail $?
bash configure --with-php-config=${myDir}/qidizi/bin/php-config
exit2fail $?
make
exit2fail $?
make install
exit2fail $?
cd ${myDir}
# 如果提示 Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
# error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in Proxy.php on line 183
# 可以到 https://curl.haxx.se/docs/caextract.html 下载cacert.pem 放到 php -r "print_r(openssl_get_cert_locations());"
# 打印出来的 [default_cert_file] =>路径下即可
echo -e "\n\n 如果需要请通过 ./php/qidizi/bin/pecl install redis 安装redis"
# 删除脚本
rm -rf $0
echo "操作完成"
发表于 2019.12.19 14:50:24