安装编译所需的依赖
apt install -y pkg-config g++ libxml2 libxml2-dev libssl-dev libsqlite3-dev zlib1g-dev libcurl4-gnutls-dev libonig-dev build-essential
获取 php
https://www.php.net/downloads.php (opens in a new tab) 下载页获取所需版本的 php 包
curl -O https://www.php.net/distributions/php-8.3.1.tar.gz
# wget https://www.php.net/distributions/php-8.3.1.tar.gz
解压、创建安装路径、编译安装
tar -zxvf php-*.tar.gz
mkdir /usr/local/php
cd "$(find . -maxdepth 1 -type d -name 'php-*' -print -quit)"
#./configure --prefix=/usr/local/php 不带任何扩展
./configure --prefix=/usr/local/php --with-zlib --with-openssl --enable-sockets --with-curl --enable-mbstring
make && make install
make clean
配置环境变量
echo 'export PATH=/usr/local/php/bin:$PATH' >> /etc/profile
source /etc/profile