php安装文档

ubuntu22.04安装php7(或者升级到php8.2)

参考:https://kifarunix.com/install-php-7-1-7-2-7-3-7-4-on-ubuntu-22-04/

apt-cache policy php
add-apt-repository ppa:ondrej/php --yes &> /dev/null
apt update
apt install php7.4
php7.4 -m
apt-cache search php7.4-mysql
apt install php7.4-mysql
apt install php7.4-xxxxxxxxx

如果多个php版本,可以选择默认:
update-alternatives --config php

php -v
apt install php7.4-fpm
systemctl status php7.4-fpm.service
ps -ef|grep fpm
systemctl enable php7.4-fpm.service
systemctl status nginx
systemctl enable nginx
apt install mysql-server
mysqld –version
ps -ef|grep mysql
mysql
mysql_secure_installation
mysql
systemctl status mysql
systemctl enable mysql

下面是升级到php8.2的过程
https://www.liquidweb.com/kb/install-php-on-ubuntu/

apt-get update
apt-get install php8.2
ls /usr/bin/php8.2
update-alternatives --set php /usr/bin/php8.2
php -v
ls /etc/apache2/mods-available/php*
a2dismod php7.4
a2enmod php8.2
安装mailwizz需要的扩展:https://www.mailwizz.com/faq/what-kind-of-hosting-do-i-need/
安装常用的扩展:
apt-get install php8.2-fpm php8.2-mysql php8.2-gd php8.2-imap php8.2-zip php8.2-mbstring php8.2-curl php8.2-xml php8.2-json

systemctl stop php7.4-fpm.service
systemctl disable php7.4-fpm.service
systemctl status php8.2-fpm.service
systemctl enable php8.2-fpm.service
systemctl restart php8.2-fpm.service

升级完毕,可以删除旧的php7.4:

apt-get purge `dpkg -l | grep php7.4| awk '{print $2}' |tr "\n" " "`
apt-get purge php7.4
update-alternatives --config php
whereis php
# /usr/bin/php -v
PHP 8.2.17 (cli) (built: Mar 16 2024 08:42:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.17, Copyright (c), by Zend Technologies