安装ubuntu20.04安装PHP运行环境

这两天因为台风影响导致服务器损坏又要重装运行环境,教程中的ubuntu20.04 标配php7.4 mysql8.0 安装过程中也遇到了一点问题.由于原来使用的ubuntu16.04+php7.3+mysql5.7 所以做了一点点修改,并把安装过程中遇到的一点问题一并解决.
接下来的步骤是从是干净的系统开始的整个安装过程希望帮到有用的人.

一、切换镜像源 这里我使用是阿里镜像源 并 追加清华源

1. 先备份镜像源文件

cd /etc/apt
cp source.list source.list.bak

2. 安装curl 和 vim

apt  install curl  
apt  install vim

3. 打开source.list,修改为阿里镜像源 并增加清华源

vim source.list
#按d + G 清空文件所有的内容
#Ubuntu20.04 focal
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

# 清华镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

二、由于ubuntu 默认安装MySQL8.0 , 如果需要安装低版本的多进行这一步 卸载一下自带的mysql数据库

查看本地mysql依赖项情况
dpkg --list | grep mysql
卸载mysql-common
sudo apt remove mysql-common
卸载并清除mysql5.7 mysql8.0
sudo apt autoremove --purge mysql-server-5.7
sudo apt autoremove --purge mysql-server-8.0
清除残留数据
dpkg -l | grep ^rc| awk '{print$2}'| sudo xargs dpkg -P
再次检查依赖项情况
dpkg --list | grep mysql
再次检查依赖项情况
dpkg --list | grep mysql
#如果输出的结果为空,说明已经卸载干净了,可进行第二步安装,如果不为空继续进行删除卸载
再次执行删除
sudo apt autoremove --purge mysql-apt-config

编辑完文件进行镜像源的更新操作

apt-get update
sudo apt-get upgrade

三、防止资源被强 先解析一下IP (如果第3步没有反应则表示IP失效 需要重新ping raw.githubusercontent.com 获取最新的IP, 再修改第1步IP)

1.解析 raw.githubusercontent.com

sudo vim /etc/hosts
#在最后一行增加 
185.199.110.133 raw.githubusercontent.com    

2. 修改阿里DNS

sudo vim /etc/ressolv.conf
nameserver 223.5.5.5
nameserver 223.6.6.6

3. 下载安装包

由于该脚本只支持 Ubuntu 20.04,请确保你的服务器系统无误。 默认安装PHP7.4 MySQL8
cd ~
wget -qO- https://raw.githubusercontent.com/summerblue/laravel-ubuntu-init/master/download.20.04.sh - | bash
下载完成后 如果需要执行安装php、MySQL版本,则中止初始化 修改脚本
cd ~/laravel-ubuntu-init/20.04/
vim /laravel-ubuntu-init/20.04/install.sh
#替换 修改PHP安装版本
function install_php { 
    apt-get install -y php7.3-bcmath php7.3-cli php7.3-curl php7.3-fpm php7.3-gd php7.3-mbstring php7.3-mysql php7.3-opcache php7.3-pgsql php7.3-readline php7.3-xml php7.3-zip php7.3-sqlite3 php7.3-redis
}
#替换    修改MySQL安装版本
function install_others {
    apt-get remove -y apache2
    debconf-set-selections <<< "mysql-server-5.7 mysql-server/root_password password ${MYSQL_ROOT_PASSWORD}"
    debconf-set-selections <<< "mysql-server-5.7 mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD}"
    apt-get install -y nginx mysql-server-5.7 redis-server memcached beanstalkd sqlite3
    chown -R ${WWW_USER}.${WWW_USER_GROUP} /var/www/
    systemctl enable nginx.service
}

执行安装脚本

sudo ./install.sh
# 多开一个terminal 用来看安装日志
tail -f /var/log/laravel-ubuntu-init.log

安装完毕之后会在屏幕上输出 Mysql 的 root 密码,请妥善保存。

生效alias指令

source ~/.bash_aliases

验证版本

php -v
mysql --version

附带常见错误的解决方案


#1. 找不到有效的OpenPGP数据
wget http://packages.ros.org/ros.key
sudo apt-key add ros.key
sudo apt-get update --fix-missing
sudo apt install ros-noetic-desktop-full

#2./etc/apt/sources.list:12中被配置多次 解决方法
#删除 /etc/apt/sources.list.d/  下的list文件, 例如下方命令
rm /etc/apt/sources.list.d/nodesource.list

#3. 如果报错是 NO_PUBKEY F0ABA0F98 ,是由于没有公钥,无法验证下列签名,直接运行–send-keys 后的公钥根据:
gpg –keyserver keyserver.ubuntu.com –send-keys F0ABA0F98
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!