linux环境下安装php 5.5/5.6简易脚本,根据我们平时的安装流程:安装依赖库、下载、编译安装以及设置配置文件,都简单的概括到内。个别报错的,请根据实际情况进行调试处理。手工安装请参考 文章linux环境下安装php 5.5.x 。当然这里只是安装,没有针对php设置一些参数优化,请根据具体服务器的配置以及实际需求进行参数优化。
脚本执行结果如图:
#!/bin/bash #auto install php 5.5 or 5.6 for centos 6.x #author 21yunwei downloaddir="/usr/local/src" cpuinfo=`cat /proc/cpuinfo | grep -c processor` function checkroot(){ if [ $UID -ne 0 ] then echo "Please login as root" exit; fi } function create_user_nginx(){ gflag=`cat /etc/group |awk -F':' '{print $1}' | grep nginx` [[ $gflag != "" ]] && echo "group 'nginx' already exists" || groupadd nginx uflag=`cat /etc/passwd |awk -F':' '{print $1}' | grep nginx` [[ $uflag != "" ]] && echo "user 'nginx' already exists" ||useradd -r nginx -g nginx -s /sbin/nologin } function install_required_libs(){ echo "Install required libs,please wait:" yum -y install gcc automake autoconf libtool make >/dev/null yum -y install gcc gcc-c++ glibc >/dev/null yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libicu-devel libc-client-devel bzip2-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel > /dev/null wget -O ${downloaddir}/libiconv-1.13.1.tar.gz http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz >/dev/null tar -zxf ${downloaddir}/libiconv-1.13.1.tar.gz -C ${downloaddir} cd ${downloaddir}/libiconv-1.13.1 && ./configure --prefix=/usr/local/libiconv >/dev/null && make -j $cpuinfo >/dev/null 2>&1 && make install >/dev/null 2>&1 [ $? -eq 0 ] && echo "Required libs install complete " || echo "Required libs installed failed ,please check" } function menu(){ echo "###############################################################" cat < <EOF Please choose php version which you want to install: 1,PHP 5.5.x 2,PHP 5.6.x EOF echo "###############################################################" } function php_version(){ read -p "please choose php version that you want to install:" flag } function php_download(){ case $flag in 1) version="php-5.5.29" echo "PHP 5.5.29 will be installed" && wget -O ${downloaddir}/${version}.tar.gz http://cn2.php.net/distributions/${version}.tar.gz ;; 2) version="php-5.6.31" echo "php-5.6.31 will be installed" && wget -O ${downloaddir}/${version}.tar.gz http://cn.php.net/distributions/${version}.tar.gz ;; *) echo "Please input 1 or 2,other novalid" php_version php_download esac } function php_install(){ cd ${downloaddir} && tar zxf ${version}.tar.gz && cd ${version} && echo "Pre_configure PHP now,please wait:" ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mcrypt=/usr/include --with-openssl --with-mhash --with-zlib --with-mysql --enable-mysqlnd --with-mysqli --with-pdo-mysql --with-gd --with-iconv --enable-inline-optimization --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache=no --enable-fpm --enable-fastcgi --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --enable-maintainer-zts --enable-intl >/dev/null 2>&1 echo "Compiling php now, please wait:"&& make ZEND_EXTRA_LIBS='-liconv' -j $cpuinfo >/dev/null 2>&1 && make install >/dev/null #set php config cp php.ini-development /usr/local/php/etc/php.ini && cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && sed -i "s/nobody/nginx/g" /usr/local/php/etc/php-fpm.conf #set php-fpm start with system start cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig php-fpm on #set php env echo "export PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH">> /etc/profile && source /etc/profile } function php_check_status(){ #start php /etc/init.d/php-fpm restart && netstat -tunlp | grep php-fpm if [ $? -eq 0 ];then phpversion=`php -v | awk 'NR==1{print $1 $2}'` echo "PHP start sucess,and php version is :" ${phpversion} else echo "PHP start failed ,please check" exit; fi } function main(){ checkroot create_user_nginx install_required_libs menu php_version php_download php_install php_check_status } main
转载请注明:西数超哥博客www.ysidc.top» [原创]linux环境下安装php5.5.29以及php5.6.31简易脚本
https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top