linux 安装 php 任意版本

ubuntu

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

For PHP 5.5.36

sudo apt-get install php5.5

For PHP 5.6.22

sudo apt-get install php5.6

To verify the version installed, run the following command:

sudo php -v

If you want to remove PHP installed, then run the following commands:

sudo apt-get update
sudo apt-get purge php5-common -y
sudo apt-get --purge autoremove -y

debian

sudo apt install apt-transport-https lsb-release ca-certificates curl
curl -sSL https://packages.sury.org/php/apt.gpg | sudo apt-key add -
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt install php8.1-cli

centos

# 安装yum-utils并启用EPEL存储库
yum install epel-release yum-utils -y
# 下载并安装remirepo
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# 配置PHP 7.0存储库
yum-config-manager --enable remi-php70
# 配置PHP 7.1存储库
yum-config-manager --enable remi-php71
# 配置PHP 7.2存储库
yum-config-manager --enable remi-php72
# 配置PHP 7.3存储库
yum-config-manager --enable remi-php73
# 安装PHP以及依赖项
yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y
# 搜索所有PHP模块
yum search php | more

安装PHP

sudo yum install -y php php-fpm php-zip php-gd php-pdo php-pdo_mysql php-xml php-mbstring php-ctype php-json php-openssl
sudo systemctl enable php-fpm