自动化(YUM/编译)安装PHP(5.3/5.5/7.0/7.1)脚本

自动化(YUM/编译)安装PHP(5.3/5.5/7.0/7.1)脚本


 PHP(外文名:PHP Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。

它可以比CGI或者Perl更快速地执行动态网页。为方便快安装部署php,可以参考一下脚本。


1.YUM安装PHP(5.3/5.5/7.0/7.1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#Date 2017/1/18
#mail xuel@51idc.com
 
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
which  ntpdate
if [ $? -eq 0 ];then
    ntpdate time1.aliyun.com
else
    yum install ntpdate
    ntpdate time1.aliyun.com
fi
yum remove `yum list installed | grep php` -y
clear
if [ -n "`grep 'CentOS Linux release 7' /etc/redhat-release`" ];then
        CentOS_REL=el7
        rpm -ivh http://repo.webtatic.com/yum/el7/epel-release.rpm
        ls /etc/yum.repos.d/webtatic.repo
        if [ $? -eq 0 ];then
            sed -i "s/#baseurl=/baseurl=/g" /etc/yum.repos.d/webtatic.repo
            sed -i "s/mirrorlist=/#mirrorlist=/g" /etc/yum.repos.d/webtatic.repo
        fi
elif [ -n "`grep 'CentOS release 6' /etc/redhat-release`" ];then
        CentOS_REL=6
        rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
    if [ $? -eq 0 ];then
        sed -i "s/#baseurl=/baseurl=/g" /etc/yum.repos.d/webtatic.repo
        sed -i "s/mirrorlist=/#mirrorlist=/g" /etc/yum.repos.d/webtatic.repo
    fi
elif [ -n "`grep 'CentOS release 5' /etc/redhat-release`" ];then
        CentOS_REL=5
        rpm -ivh http://repo.webtatic.com/yum/el5/latest.rpm
    if [ $? -eq 0 ];then
        sed -i "s/#baseurl=/baseurl=/g" /etc/yum.repos.d/webtatic.repo
        sed -i "s/mirrorlist=/#mirrorlist=/g" /etc/yum.repos.d/webtatic.repo
    fi
else
        echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m"
        exit 1
fi
clear
echo "##########################################"
echo "#                                           #"
echo "#   Auto 编译安装 PHP5.5/5.6/7.0/7.1.    #"
echo "#                                           #"
echo "##########################################"
echo "1 Install PHP-5.5"
echo "2 Install PHP-5.6"
echo "3 Install PHP-7.0"
echo "4 Install PHP-7.1"
echo "5 EXIT"
read -p "Please input your choice:" I
if "$I" == "1" ];then
    VER="php55w"
elif "$I" == "2" ];then
    VER="php56w"
elif "$I" == "3" ];then
    VER="php70w"
elif "$I" == "4" ];then
    VER="php71w"
elif "$I" == "5" ];then
        echo "you choce channel!"
        exit 1;
else
        echo "input Error! Place input{1|2|3|4|5}"
        exit 0;
fi
clear
echo -e "\033[32m You choice install $VER.Install\033[0m"
echo -e "\033[32m Press any key to start install $VER... \033[0m"
read -n 1
ls /etc/yum.repos.d/webtatic.repo
if [ $? -eq 0 ];then
        yum -y install `yum list|grep php71w|awk '{printf ("%s ",$1)}'` --skip-broken
fi
chkconfig php-fpm on
service php-fpm start /tmp/php-install.log 2>&1
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
    echo -e "\033[32m PHP is install success! \033[0m"
else
    echo -e "\033[32m PHP install file.please check /tmp/php-install.log \033[0m"
fi


2.编译安装PHP(5.3/5.5/7.0/7.1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#Date 2017/1/10
#mail xuel@51idc.com
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
clear
echo "##########################################"
echo "#                                           #"
echo "#   Auto yum安装 PHP5.5/5.6/7.0/7.1      #"
echo "#                                           #"
echo "##########################################"
echo "1 Install PHP-5.5.38"
echo "2 Install PHP-5.6.29"
echo "3 Install PHP-7.0.14"
echo "4 Install PHP-7.1.0"
echo "5 EXIT"
read -p "Please input your choice:" I
if "$I" == "1" ];then
        URL="http://cn2.php.net/distributions/php-5.5.38.tar.gz"
    VER="php-5.5.38"
elif "$I" == "2" ];then
        URL="http://cn2.php.net/distributions/php-5.6.29.tar.gz"
    VER="php-5.6.29"
elif "$I" == "3" ];then
        URL="http://cn2.php.net/distributions/php-7.0.14.tar.gz"
    VER="php-7.0.14"
elif "$I" == "4" ];then
        URL="http://cn2.php.net/distributions/php-7.1.0.tar.gz"
    VER="php-7.1.0"
elif "$I" == "5" ];then
        echo "you choce channel!"
        exit 1;
else
        echo "input Error! Place input{1|2|3|4|5}"
        exit 0;
fi
read -p "Please input php install dirname:(example:/data/php)" DIR
if [ ! -d $DIR ];then
        mkdir -p $DIR
fi
if [ $? -eq 1 ];then
        echo "$DIR fail! Please intput ture dirname."
        exit 1
fi
clear
echo -e "\033[32m You choice install $VER.Install dirname:$DIR \033[0m"
echo -e "\033[32m Press any key to start install $VER... \033[0m"
read -n 1
 
which tar >/dev/null 2>&1
if [ $? -eq 0 ];then
    echo "tar is installed">/tmp/php-install.log
else
    yum install tar -y >/dev/null 2>&1
fi
TDIR="/tools"
yum install -y wget autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap libXpm* gcc gcc-c++ bison git ntpdate
ntpdate ntpdate time1.aliyun.com >/dev/null 2>&1
if [ ! -d $TDIR ];then
        /bin/mkdir $TDIR && cd $TDIR
fi
/usr/bin/wget -c -O $TDIR/$VER.tar.gz $URL
if [ $? -eq 0 ];then
        tar -zxvf $TDIR/$VER.tar.gz -C $TDIR
else
        yum install tar -y >/dev/null 2>&1
        tar -zxvf $TDIR/$VER.tar.gz >/dev/null 2>&1
fi
cd  $TDIR/$VER
if [ $? -eq 0 ];then
        ./configure --prefix=$DIR  --exec-prefix=$DIR  --bindir=$DIR/bin --sbindir=$DIR/sbin --includedir=$DIR/include --libdir=$DIR/lib/php --mandir=$DIR/php/man  --with-config-file-path=$DIR/etc --with-mysql-sock=/tmp/mysql.sock  --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --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 --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm
fi
make && make install >>/tmp/php-install.log 2>&1
if [ $? -eq 0 ];then
        /bin/cp $DIR/etc/php-fpm.conf.default $DIR/etc/php-fpm.conf && cp $DIR/etc/php-fpm.d/www.conf.default $DIR/etc/php-fpm.d/www.conf && cp -R $DIR/sbin/php-fpm /etc/init.d/php-fpm && /bin/cp `find  /  -name php.ini-production` /data/php/etc/php.ini >>/tmp/php-install.log 2>&1
fi
id www
USER=`echo $?`
if [ $USER -eq 1 ];then
    useradd -s /sbin/nologin www
fi
echo "export PATH=$PATH:$DIR/bin">>/etc/profile  && source /etc/profile
/etc/init.d/php-fpm >>/tmp/php-install.log 2>&1
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
        echo -e "\033[32m $VER is install success! \033[0m"
else
        echo -e "\033[32m $VER install file.please check /tmp/php-install.log \033[0m"
fi









本文转自 KaliArch 51CTO博客,原文链接:http://blog.51cto.com/kaliarch/1899117,如需转载请自行联系原作者
### 在 CentOS 7 上通过 Yum 编译安装 PHP 5.3 的方法 尽管 CentOS 7 默认的软件仓库中不再提供 PHP 5.3,但仍可以通过手动配置第三方源或自行编译的方式实现安装。以下是具体的操作说明: #### 配置 EPEL 源 EPEL 是一个由 Fedora 社区维护的附加软件包集合,可以扩展 CentOS 的可用软件范围。虽然它不直接支持 PHP 5.3,但它提供了许多必要的依赖项[^2]。 ```bash sudo yum install epel-release -y ``` #### 添加 Remi 或其他旧版本源 Remi 提供了一个专门用于老版本 PHP 的存储库。为了获取 PHP 5.3,需启用该存储库中的 `remi-php53` 子集[^4]。 ```bash sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y sudo yum-config-manager --enable remi-php53 ``` #### 安装 PHP 及其常用模块 一旦启用了合适的存储库,就可以像平常一样使用 `yum` 命令来安装所需的 PHP 组件及其扩展。 ```bash sudo yum install php php-cli php-common php-mysqlnd php-pdo php-gd php-mbstring php-xml php-json -y ``` 需要注意的是,在某些情况下可能需要额外的手动操作以解决兼容性问题,比如调整 Nginx 或 Apache 中关于 PHP-FPM 的设置[^1]。 #### 处理缺失的扩展 如果发现有特定功能未被默认包含进来,则可按照如下方式单独构建这些插件[^3]: 进入对应扩展所在的路径执行相应命令: ```bash cd /path/to/php-source/ext/[extension_name] /usr/local/php5.3/bin/phpize ./configure --with-php-config=/usr/local/php5.3/bin/php-config make && sudo make install ``` 最后记得更新主程序配置文件(`php.ini`)使新加入的功能生效。 --- ### 注意事项 上述过程假设读者已经具备基本 Linux 系统管理技能,并熟悉如何处理可能出现的各种错误提示信息。对于生产环境中部署低级别的解释型语言运行时应格外谨慎评估安全风险因素。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值