Shell 脚本一键编译并且安装 php

#先新建文件

sudo vim ./install-php.sh

#1.不多说,上代码

#!/bin/bash

userName="www"
userGroup="www"

version=$1;
if [ -z "$version" ]; then
    version="7.3.9"
fi

installDir="$2"
if [ -z "$installDir" ]; then
    installDir="/usr/local/php"
fi

fileName="php-$version.tar.bz2"

if ! wget -O "$fileName" "https://www.php.net/distributions/$fileName"; then echo "wget download php-$version fail"; exit 1; fi

if [ ! -f "$fileName" ]; then echo "$fileName not found"; exit 1; fi

if ! tar -xvf "$fileName"; then echo "decompression fail"; exit 1; fi

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install -y libxml2-dev

sudo apt-get install -y  build-essential

sudo apt-get install -y openssl

sudo apt-get install -y libssl-dev

sudo apt-get install -y curl

sudo apt-get install -y libcurl4-gnutls-dev

sudo apt-get install -y libjpeg-dev

sudo apt-get install -y libpng-dev

sudo apt-get install -y libmcrypt-dev

sudo apt-get install -y libreadline6-dev

sudo apt-get install -y libfreetype6-dev

sudo apt-get install -y libzip-dev

cd "./php-$version/"

./configure --prefix="$installDir" --with-config-file-path="$installDir/etc" --enable-fpm --with-fpm-user="$userName" --with-fpm-group="$userGroup" --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-fileinfo --enable-maintainer-zts

sudo make && sudo make install

sudo cp "$installDir/etc/php-fpm.conf.default"  "$installDir/etc/php-fpm.conf"

sudo cp "$installDir/etc/php-fpm.d/www.conf.default" "$installDir/etc/php-fpm.d/www.conf"

sudo groupadd "$userGroup"

sudo useradd -g "$userGroup" "$userName"

sudo ln -s "$installDir"/bin/* /usr/bin
sudo ln -s "$installDir"/sbin/* /usr/sbin

sudo php-fpm

#2.命令

sudo chmod +x ./install-php.sh

sudo ./install-php.sh 
#./install-php.sh 7.3.9  /usr/local/php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值