修改更新源
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade
安装PHP7以及常用扩展
sudo apt install php7.4-common php7.4-cgi php7.4-gd php7.4-mysql php7.4-xml php7.4-cli php7.4-json php7.4-sqlite3 php7.4-xmlrpc php7.4-bcmath php7.4-enchant
php7.4-opcache php7.4-readline php7.4-xsl php7.4-bz2 php7.4-curl php7.4-fpm php7.4-mbstring php7.4-pgsql php7.4-tidy php7.4-zip
安装PHP8以及常用扩展
sudo apt install php8.0-common php8.0-cgi php8.0-gd php8.0-mysql php8.0-xml php8.0-cli php8.0-sqlite3 php8.0-xmlrpc php8.0-bcmath php8.0-enchant php8.0-opcache php8.0-readline php8.0-xsl php8.0-bz2 php8.0-curl php8.0-fpm php8.0-mbstring php8.0-pgsql php8.0-tidy php8.0-zip
composer安装以及使用
安装composer
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
配置composer使用镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
运行composer时指定PHP版本
php8.0 /usr/local/bin/composer
php7.4 /usr/local/bin/composer
alias composer7='php7.4 /usr/local/bin/composer'
alias composer8='php8.0 /usr/local/bin/composer'
使用symfony composer以及.php_version文件指定PHP版本
查看本地所有PHP版本
symfony local:php:list
显示结果
┌─────────┬────────────┬────────────┬─────────┬─────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼────────────┼────────────┼─────────┼─────────┼─────────┼─────────┤
│ 7.4.14 │ /usr/local │ bin/php │ │ │ PHP CLI │ * │
│ 7.4.16 │ /usr │ bin/php7.4 │ │ │ PHP CLI │ │
└─────────┴────────────┴────────────┴─────────┴─────────┴─────────┴─────────┘
指定symfony composer
使用PHP7
echo 7 > .php-version
指定symfony composer
使用PHP8
echo 8 > .php-version
使用symfony composer
安装或者更新包
symfony composer install
参考