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

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

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

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

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

groupadd "$userGroup"

useradd -g "$userGroup" "$userName"

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

sudo php-fpm


2.命令
chmod +x ./install-php.sh

./install-php.sh 
#./install-php.sh 7.3.9  /usr/local/php


作者:Renew全栈工程师
链接:https://www.jianshu.com/p/c984bff9110c
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
---
信息
想要留言? 请 登录 您的账号。还没有? 你可以 免费创建账号