热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

快如闪电的安装php8.2套件(centos7)

快如闪电的安装php8.2套件(centos7)本文只考虑centos7本文编写时间:2023-01-11,文章较新,是我自己仔细测试过的。remi是一个php安装仓库。是rpm包











快如闪电的安装php8.2套件(centos 7)

本文只考虑centos7

本文编写时间:2023-01-11,文章较新,是我自己仔细测试过的。
remi是一个php安装仓库。是rpm包。
到底有多快?主要取决于php 8 的安装,全部软件的安装时间总共约3到5分钟(不含操作系统)。


本文各软件版本

centos 7.9.2009
php 8.2.1
nginx 1.22.1
mysql 8.0.31
redis 7.0.7
git 2.24.4



首先,安装阿里的 centos 仓库。(centos 7)

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum repolist




安装阿里的 epel 仓库。(centos 7)

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum repolist




安装阿里的 remi 的仓库(centos 7)

yum install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
sed -i 's/https*:\/\/rpms.remirepo.net/https:\/\/mirrors.aliyun.com\/remi/g' /etc/yum.repos.d/remi*
sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/remi*
sed -i 's|^mirrorlist|#mirrorlist|' /etc/yum.repos.d/remi*
yum makecache
yum repolist
yum -y install yum-utils




安装 php 8(centos 7)

yum-config-manager --enable remi-php82
yum install -y php82 php82-php-devel php82-php-fpm php82-php-mbstring php82-php-memcache php82-php-memcached php82-php-redis php82-php-mysqlnd php82-php-pdo php82-php-bcmath php82-php-xml php82-php-gd php82-php-gmp php82-php-igbinary php82-php-imagick php82-php-mcrypt php82-php-pdo_mysql php82-php-posix php82-php-simplexml php82-php-opcache php82-php-xsl php82-php-xmlwriter php82-php-xmlreader php82-php-swoole php82-php-zip php82-php-phalcon php82-php-yaml php82-php-yar php82-php-yaf php82-php-uuid

执行上面这个命令,大约3分钟左右。主要是因为共安装两百多个包。
总体其实速度是很快的。




安装阿里的 composer 镜像源(centos 7)

ln -s /usr/bin/php82 /usr/bin/php
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 服务(centos 7)

# 下面这个echo是一句命令,得一起复制
echo $'[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true '
> /etc/yum.repos.d/nginx.repo
# 上面是一条echo命令。
yum makecache
yum install -y nginx
systemctl enable nginx
systemctl enable php82-php-fpm
sed -i 's/user\ =\ apache/user\ =\ nginx/g' /etc/opt/remi/php82/php-fpm.d/www.conf
sed -i 's/group\ =\ apache/group\ =\ nginx/g' /etc/opt/remi/php82/php-fpm.d/www.conf
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 文件如下:

vi /usr/share/nginx/html/1.php
<?php
phpinfo();

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

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




安装mysql 8(centos 7)

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm
# 下面这句安装mysql服务,时间大概1到3分钟左右。
yum --enablerepo=mysql80-community install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
# 查看初始密码:
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;
set global validate_password.policy=LOW;
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客户端无法连接!




安装阿里镜像源 ius 内的 git(centos 7)

安装这个的理由是 centos7 带的 git 大版本是 1,真的太老了。
另外这里也一定要薅到阿里的羊毛~

yum install -y https://mirrors.aliyun.com/ius/ius-release-el7.rpm
sed -i 's/https:\/\/repo.ius.io/https:\/\/mirrors.aliyun.com\/ius/g' /etc/yum.repos.d/ius*
yum makecache
yum install -y git224




安装 redis 7 以及其他常用库(centos 7)

yum --enablerepo=remi install -y redis
yum install -y wget vim zip unzip p7zip rsync crontabs supervisor net-tools python3
systemctl enable redis
systemctl start redis

注意和上面版本不同,如想安装redis5,但不可以同时安装reids 5和7 (centos 7)

yum install redis5

总结(centos 7)

用了国内镜像会速度极快,下载包的速度:3MB/秒,惊人的快
mysql安装今天非常快。今天20230111实测的结果:本文只有php有点慢了。
另外感谢阿里云镜像库,非常快速和方便。




推荐阅读
author-avatar
乐天小散_608
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有