#先新建文件
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