apt-get安装
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php #追加一个存储库 sudo apt update
sudo apt install php8.0 sudo apt install libapache2-mod-php8.0 #与apache2交互的模块 sudo a2enmod proxy_fcgi setenvif sudo a2enconf php8.0-fpm
编译安装
#! /bin/bash
read -p "请输入安装路径:" installdir
if [ ! $installdir ]
then
echo "安装路径不得为空!";
exit -1
fi
#rm -rf $installdir
source=/etc/apt/sources.list
if [ `grep -c "deb http://mirrors.aliyun.com/ubuntu/" $source` -eq '0' ]
then
mv $source /etc/apt/sources.list.bak
touch $source
elif [ ! -e "$source" ]
then
touch $source
fi
chmod 777 $source
if [ `grep -c "deb http://mirrors.aliyun.com/ubuntu/" $source` -eq '0' ]
then
cat > "$source" << EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF
fi
#无法关闭文件
# echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" >> $source
# echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" >> $source
# echo "\n" >> $source
# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> $source
# echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> $source
# echo "\n" >> $source
# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> $source
# echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> $source
# echo "\n" >> $source
# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> $source
# echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> $source
# echo "\n" >> $source
# echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> $source
# echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> $source
add-apt-repository ppa:ondrej/php
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install gcc pkg-config libxml2-dev libsqlite3-dev \
libssl-dev libonig-dev libpng-dev libcurl4-openssl-dev zlib1g-dev libzip-dev \
software-properties-common build-essential autoconf bison re2c
./configure \
--prefix=${installdir} \
--bindir=${installdir}bin \
--sbindir=${installdir}sbin \
--libdir=${installdir}lib \
--libexecdir=${installdir}libexec \
--includedir=${installdir}include \
--mandir=${installdir}man \
--infodir=${installdir}info \
--oldincludedir=${installdir}oldinclude \
--datadir=${installdir}data \
--localedir=${installdir}localedir \
--with-config-file-path=${installdir}etc \
--with-config-file-scan-dir=${installdir}etc/conf.d \
--with-pear=${installdir}pear \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-mhash \
--with-zlib \
--with-xmlrpc \
--with-iconv \
--with-curl \
--enable-intl
--enable-pdo \
--enable-mysqlnd \
--enable-ftp \
--enable-mbstring \
--enable-gd \
--enable-gd-jis-conv \
--enable-sockets \
--enable-fpm \
--enable-cli \
--enable-xml \
--enable-soap \
--enable-pcntl \
--enable-debug \
--enable-calendar \
--enable-opcache \
--enable-maintainer-zts
make clean && make && make install
cp ./php.ini-development ${installdir}etc/php.ini
export PATH="echo $PATH:${installdir}bin:${installdir}sbin"
php_path=/etc/profile.d/php_path.sh
if [ ! -e "$php_path" ]
then
cat > "$php_path" <<EOF
export PATH="echo $PATH:${installdir}bin:${installdir}sbin"
EOF
chmod 744 $php_path
`source $php_path`
fi
//单独安装pear方法
wget http://pear.php.net/go-pear.phar -O go-pear.php
php go-pear.php