Hugh's Blog

Linux 安装 PHP

 

Linux 选择安装特定 PHP 版本,做个记录。

CentOS 安装 PHP

安装源:

# centos 7
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

# centos 6
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm

安装 PHP:

# yum 命令包
yum install yum-utils

# 可以选择版本
# yum-config-manager --enable remi-php55   [Install PHP 5.5]
# yum-config-manager --enable remi-php56   [Install PHP 5.6]
# yum-config-manager --enable remi-php72   [Install PHP 7.2]
# yum-config-manager --enable remi-php74   [Install PHP 7.4]

# 安装
yum-config-manager --enable remi-php56
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-fileinfo

卸载 PHP:

yum remove php*

Ubuntu/Debian 安装 PHP

安装源:

sudo apt install ca-certificates apt-transport-https 
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ buster main" | sudo tee /etc/apt/sources.list.d/php.list

# 更新
sudo apt update

安装 PHP:

# 7.4
sudo apt install php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-mbstring php7.4-mysql php7.4-xml

# 7.3
sudo apt install php7.3 php7.3-cli php7.3-common php7.3-curl php7.3-mbstring php7.3-mysql php7.3-xml

# 7.2
sudo apt install php7.2 php7.2-cli php7.2-common php7.2-curl php7.2-mbstring php7.2-mysql php7.2-xml

# 5.6
sudo apt install php5.6 php5.6-cli php5.6-common php5.6-curl php5.6-mbstring php5.6-mysql php5.6-xml

卸载 PHP:

sudo apt autoremove php7.4

使用 ppa:ondrej/php 源:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

sudo apt install php7.3 php7.3-common php7.3-cli php7.3-fpm php7.3-bcmath php7.3-bz2 php7.3-curl php7.3-gd php7.3-intl php7.3-json php7.3-mbstring php7.3-readline php7.3-xml php7.3-zip

参考

How to Install PHP 5.6 on CentOS 7

How To Install PHP (7.4, 7.3 & 5.6) on Debian 9 Stretch

Install/Upgrade to PHP 7.3 - Ubuntu & Debian