替换源 & 更新软件

sudo mv sources.list sources.list.bak && sudo vim sources.list

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

sudo apt update && sudo apt upgrade

Apache2

安装

sudo apt install apache2

启动 & 开机自启

sudo service apache2 start && sudo systemctl enable apache2 

PHP7.4 & PHP8.0

添加源

sudo sh -c "echo 'deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main'  > /etc/apt/sources.list.d/ppa_ondrej_php.list"

sudo apt update

如果产生以下错误:

W: GPG error: ppa.launchpad.net/ondrej/php/ubuntu focal InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6C

运行

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C (key 对应  waring 中的key)

安装

#8.0
sudo apt install -y php8.0 php8.0-cli php8.0-dev php8.0-pgsql php8.0-sqlite3 php8.0-gd php8.0-curl php8.0-memcached php8.0-imap php8.0-mysql php8.0-mbstring php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap php8.0-intl php8.0-readline php8.0-msgpack php8.0-igbinary php8.0-ldap php8.0-redis

#7.4
sudo apt install -y php7.4 php7.4-cli php7.4-dev php7.4-pgsql php7.4-sqlite3 php7.4-gd php7.4-curl php7.4-memcached php7.4-imap php7.4-mysql php7.4-mbstring php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap php7.4-intl php7.4-readline php7.4-pcov php7.4-msgpack php7.4-igbinary php7.4-ldap php7.4-redis

## 以上扩展按照自己的需求选装

版本切换

cli

sudo update-alternatives --config php 输入数字切换对应版本

apache-php

sudo a2dismod php7.0 && sudo a2enmod php8.0 此示例表示停用php7.4,启用php8.0

Mysql

安装

sudo apt install -y mysql-server

启动 & 开机自启

sudo service mysql start

sudo systemctl enable mysql

设置密码

查看默认用户及密码

sudo cat /etc/mysql/debian.cnf

使用默认用户登录

mysql -u用户名 -p密码

设置 root 密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Redis

安装

sudo apt install -y redis

启动 & 开机自启

sudo service redis start

sudo systemctl enable redis-server