0

0

教你最快速度安装php8.2套件(ubuntu 20.04 focal)

藏色散人

藏色散人

发布时间:2023-01-13 10:03:36

|

5500人浏览过

|

来源于learnku

转载

本篇文章给大家带来了关于php8.2的相关知识,其中主要介绍了教大家怎么快速安装php8.2套件?到底有多快呢?大概可能20分钟左右...下面一起来看一下,希望对大家有帮助。

快速安装php8.2套件(ubuntu 20.04 focal)

到底有多快?我这边尝试的结果是总共大约 20 分钟左右(不含操作系统)。

另外,同样是我的电脑,同样阿里云镜像库,装 centos 系统各类软件含 php 就很快,但装这个 ubuntu 就比较慢,原因不太清楚(可能的一个原因是因为 ubuntu 用的人太多,阿里限制了源的下载速率来稍微省点钱。)。

本文各软件版本

立即学习PHP免费学习笔记(深入)”;

ubuntu 20.04
php 8.2.1
nginx 1.22.1
mysql 8.0.31
redis 7.0.7
git 2.24.4

首先,安装阿里的 仓库

首先必须 apt update
安装 vim

vim /etc/apt/sources.list
内容如下,就是搞阿里云镜像。但是http的,被我改的。不搞无法更新。
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

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

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

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

然后
apt update

apt install -y --reinstall ca-certificates

现在,再把阿里云镜像库中的 http 改成标准的 https,
vim /etc/apt/sources.list

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
然后。再次
apt update

安装 php 8

apt install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils systemd gnupg2 lsb-release ubuntu-keyring

上面的命令需要选择多个选项。选亚洲 asia。选上海 shanghai

curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null

echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list


apt-get update

apt-get install -y php8.2-cli php8.2-dev  php8.2-pgsql php8.2-sqlite3 php8.2-gd  php8.2-curl  php8.2-imap php8.2-mysql php8.2-mbstring  php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap   php8.2-intl php8.2-readline  php8.2-ldap  php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole  php8.2-memcached php8.2-pcov  php8.2-fpm php8.2-gmp php8.2-imagick php8.2-mcrypt php8.2-uuid php8.2-yaml

执行上面这些命令,大约 15 分钟左右,主要耗时就是这里。

安装阿里的 composer 镜像源

curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar

chmod +x /usr/local/bin/composer

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

使用 root 身份执行 composer 命令,会提示输入 yes ,挺麻烦,则

vim /etc/environment

文字

export COMPOSER_ALLOW_SUPERUSER=1

然后

source /etc/environment

安装 nginx 并整合 php-fpm 服务

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx"  | tee /etc/apt/sources.list.d/nginx.list

apt update
apt install nginx

改php-fpm 配置。
sed -i 's/listen\ =\ \/run\/php\/php8.2-fpm.sock/listen\ =\ 127.0.0.1:9000/g' /etc/php/8.2/fpm/pool.d/www.conf


修改 /etc/nginx/nginx.conf
第一行 
user  www-data;

然后,
rm -f /etc/nginx/conf.d/default.conf
vi /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf 文件内容如下

server {
    listen       80;
    server_name  localhost;
    charset utf-8 ;
    access_log  /var/log/nginx/host.access.log  main;
    root   /usr/share/nginx/html;
    index index.php  index.html index.htm;
    error_page 404  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

添加一个 php 文件如下:

Dreamlike.art
Dreamlike.art

内置5种模型的AI图像生成器

下载
vi /usr/share/nginx/html/1.php

启动 php-fpm 和 nginx 并验证安装正确

/etc/init.d/nginx start
/etc/init.d/php8.2-fpm start

curl localhost/1.php
# 如果能看到很多的大量输出,说明php和nginx正确安装了。

安装 mysql 8

apt install mysql-server-8.0 mysql-client-8.0



# 查看初始密码:
grep 'temporary password' /var/log/mysqld.log

# 用查看到的密码进入mysql 的 shell
mysql -uroot -p

下面,整套设置新用户流程,先改初始,再加新用户并授权,再删除老用户。

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'tb4Wn3BthR.';
flush privileges;

create user 'root'@'%' identified by 'root1234';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root1234';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
drop user root@localhost;
flush privileges;

退出 shell,重新进入。

现在就可以直接进入 shell

mysql -uroot -proot1234

# 这句话查看用户的加密方式。
select user, host, plugin from mysql.user\G;

# plugin: caching_sha2_password 表示老的MySQL客户端无法连接!

安装 redis 6 以及其他常用库

说明,安装 redis 7 需要下二进制包编译,坚决不编译,所以没搞。

curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list

apt-get update

apt-get install redis-stack-server

注意和上面版本不同,如想安装 redis5

如想redis5,啥源都不需要,直接

apt install redis-server

总结

感谢阿里云镜像库,但是速度不是太快。

推荐学习:《PHP视频教程

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
php文件怎么打开
php文件怎么打开

打开php文件步骤:1、选择文本编辑器;2、在选择的文本编辑器中,创建一个新的文件,并将其保存为.php文件;3、在创建的PHP文件中,编写PHP代码;4、要在本地计算机上运行PHP文件,需要设置一个服务器环境;5、安装服务器环境后,需要将PHP文件放入服务器目录中;6、一旦将PHP文件放入服务器目录中,就可以通过浏览器来运行它。

1696

2023.09.01

php怎么取出数组的前几个元素
php怎么取出数组的前几个元素

取出php数组的前几个元素的方法有使用array_slice()函数、使用array_splice()函数、使用循环遍历、使用array_slice()函数和array_values()函数等。本专题为大家提供php数组相关的文章、下载、课程内容,供大家免费下载体验。

1120

2023.10.11

php反序列化失败怎么办
php反序列化失败怎么办

php反序列化失败的解决办法检查序列化数据。检查类定义、检查错误日志、更新PHP版本和应用安全措施等。本专题为大家提供php反序列化相关的文章、下载、课程内容,供大家免费下载体验。

1030

2023.10.11

php怎么连接mssql数据库
php怎么连接mssql数据库

连接方法:1、通过mssql_系列函数;2、通过sqlsrv_系列函数;3、通过odbc方式连接;4、通过PDO方式;5、通过COM方式连接。想了解php怎么连接mssql数据库的详细内容,可以访问下面的文章。

948

2023.10.23

php连接mssql数据库的方法
php连接mssql数据库的方法

php连接mssql数据库的方法有使用PHP的MSSQL扩展、使用PDO等。想了解更多php连接mssql数据库相关内容,可以阅读本专题下面的文章。

1396

2023.10.23

html怎么上传
html怎么上传

html通过使用HTML表单、JavaScript和PHP上传。更多关于html的问题详细请看本专题下面的文章。php中文网欢迎大家前来学习。

1228

2023.11.03

PHP出现乱码怎么解决
PHP出现乱码怎么解决

PHP出现乱码可以通过修改PHP文件头部的字符编码设置、检查PHP文件的编码格式、检查数据库连接设置和检查HTML页面的字符编码设置来解决。更多关于php乱码的问题详情请看本专题下面的文章。php中文网欢迎大家前来学习。

1438

2023.11.09

php文件怎么在手机上打开
php文件怎么在手机上打开

php文件在手机上打开需要在手机上搭建一个能够运行php的服务器环境,并将php文件上传到服务器上。再在手机上的浏览器中输入服务器的IP地址或域名,加上php文件的路径,即可打开php文件并查看其内容。更多关于php相关问题,详情请看本专题下面的文章。php中文网欢迎大家前来学习。

1302

2023.11.13

笔记本电脑卡反应很慢处理方法汇总
笔记本电脑卡反应很慢处理方法汇总

本专题整合了笔记本电脑卡反应慢解决方法,阅读专题下面的文章了解更多详细内容。

1

2025.12.25

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号