LNMP(centos 9)

本文只考虑 centos 9

remi 是一个 php 安装仓库。是 rpm 包。

到底有多快?以下全部软件安装时间大概 2 分钟(不含操作系统)。

复制代码
CentOS Stream release 9
php 8.2.4
nginx 1.22.1
mysql 8.0.32
redis 6.2.7
git 2.39.1 

1、安装阿里的 centos 仓库。(centos stream 9)

复制代码
cd /etc/yum.repos.d
cp centos.repo centos.repo.bak
cp centos-addons.repo centos-addons.repo.bak

现在修改 centos.repo
把小节[baseos]和小节 [appstream]和小节[crb]下面的
metalink= 。。。 
都改成
# metalink= 。。。

然后,把小节[baseos]下面的  
# metalink 下面加一行
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/

然后,把小节[appstream]下面的 
# metalink 下面加一行
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/

然后,把小节[crb]下面的 
# metalink 下面加一行
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/CRB/x86_64/os/


dnf makecache
dnf repolist

安装 epel 仓库。(centos stream 9)

复制代码
dnf install 'dnf-command(config-manager)'
dnf --enable config-manager crb
dnf install -y epel-release epel-next-release

dnf makecache
dnf repolist

此时,/etc/yum.repos.d 目录下,多了 epel 的仓库,且源是外国的。

安装阿里的 remi 的仓库(centos stream 9)

复制代码
dnf install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-9.rpm

sed -i  's/http*:\/\/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*

dnf makecache
dnf repolist

dnf -y install yum-utils

安装 php 8.2(centos stream 9)

复制代码
dnf 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

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

复制代码
rm /usr/bin/php
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/ 
但现在应该使用腾讯云 2023 09 15
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/

安装 nginx 并整合 php-fpm 服务(centos stream 9)

复制代码
# 下面这个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命令。

dnf makecache
dnf 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

sed -i 's/listen\ =\ \/var\/opt\/remi\/php82\/run\/php-fpm\/www.sock/listen=9000/g' /etc/opt/remi/php82/php-fpm.d/www.conf

rm -f /etc/nginx/conf.d/default.conf
vim /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 stream 9)

复制代码
dnf install -y https://repo.mysql.com/mysql80-community-release-el9-1.noarch.rpm

# 下面这句安装mysql服务,时间大概1到3分钟左右。

dnf -y --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客户端无法连接!

安装 redis 6 以及其他常用库(centos stream 9)

复制代码
dnf --enablerepo=remi install -y redis
dnf install -y git wget vim zip unzip p7zip rsync crontabs supervisor net-tools python3
systemctl enable redis
systemctl start redis
相关推荐
天才奇男子5 小时前
HAProxy高级功能全解析
linux·运维·服务器·微服务·云原生
小李独爱秋5 小时前
“bootmgr is compressed”错误:根源、笔记本与台式机差异化解决方案深度指南
运维·stm32·单片机·嵌入式硬件·文件系统·电脑故障
学嵌入式的小杨同学5 小时前
【Linux 封神之路】信号编程全解析:从信号基础到 MP3 播放器实战(含核心 API 与避坑指南)
java·linux·c语言·开发语言·vscode·vim·ux
酥暮沐6 小时前
iscsi部署网络存储
linux·网络·存储·iscsi
❀͜͡傀儡师6 小时前
centos 7部署dns服务器
linux·服务器·centos·dns
Dying.Light7 小时前
Linux部署问题
linux·运维·服务器
S19017 小时前
Linux的常用指令
linux·运维·服务器
萤丰信息7 小时前
AI 筑基・生态共荣:智慧园区的价值重构与未来新途
大数据·运维·人工智能·科技·智慧城市·智慧园区
小义_7 小时前
【RH134知识点问答题】第7章 管理基本存储
linux·运维·服务器
运维小欣7 小时前
Agentic AI 与 Agentic Ops 驱动,智能运维迈向新高度
运维·人工智能