华为云 CentOS 8 下 Nginx 1.20 & PHP 8.2 安装

Nginx 1.20 版本安装  

使用 dnf module 选择 nginx 版本,如果不选择,默认安装 1.14 版 

1、先 RESET 一下 

[xxx@ecs-209716 ~]$ sudo dnf module reset  nginx
Repository extras is listed more than once in the configuration
Last metadata expiration check: 2:51:44 ago on Fri 16 Dec 2022 03:57:21 PM CST.
Dependencies resolved.
===================================================================
 Package                      Architecture                Version                       Repository                    Size
===================================================================
Resetting modules:       nginx                                                                                                                    

Transaction Summary
====================================================================

Is this ok [y/N]: y
Complete!

2、选择版本,这里选择最新的 1.20 

[xxx@ecs-209716 ~]$sudo  dnf module enable nginx:1.20
Repository extras is listed more than once in the configuration
Last metadata expiration check: 2:52:00 ago on Fri 16 Dec 2022 03:57:21 PM CST.
Dependencies resolved.
============================================================
 Package                      Architecture                Version                       Repository                    Size
============================================================
Enabling module streams:   nginx                    1.20                                                            

Transaction Summary
=============================================================

Is this ok [y/N]: y
Complete!

检查一下是否生效 

[xxx@ecs-209716 ~]$ sudo  dnf module list  nginx
[sudo] password for fjy: 
Repository extras is listed more than once in the configuration
Last metadata expiration check: 3:00:29 ago on Fri 16 Dec 2022 03:57:21 PM CST.
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
Name                       Stream                        Profiles                           Summary                            
nginx                      1.14 [d]                      common [d]                     nginx webserver                    
nginx                      1.16                           common [d]                     nginx webserver                    
nginx                      1.18                           common [d]                     nginx webserver                    
nginx                      1.20 [e]                      common [d]                     nginx webserver                    
 

3、执行安装指令 

sudo dnf install nginx 

4、检查安装版本 

[xxx@ecs-209716 ~]$ sudo nginx  -V
nginx version: nginx/1.20.0

5、启动 nginx 

[xxx@ecs-209716 ~]$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Dec 16 18:18:58 ecs-209716 systemd[1]: nginx.service: Unit cannot be reloaded because it is inactive. 

启动 nginx 

sudo systemctl start nginx  

再次检查 nginx 转态,已经成功启动 

[xxx@ecs-209716 ~]$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-12-16 18:22:20 CST; 4s ago
  Process: 1527294 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1527292 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1527290 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1527295 (nginx)
    Tasks: 3 (limit: 23712)
   Memory: 5.0M
   CGroup: /system.slice/nginx.service
           ├─1527295 nginx: master process /usr/sbin/nginx
           ├─1527296 nginx: worker process
           └─1527297 nginx: worker process 

6、nginx 服务设为开机自动启动

sudo systemctl enable nginx 

7、浏览器访问测试

PHP 8.2 的安装  

1、 添加  epel 和 Remi 存储库

CentOS 8 ,对应 epel-release-latest-8.noarch.rpm 

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

这里需要检查对应的版本号,CentOS 版本为 8.5 ,选择对应的 rpm 包 

[root@ecs-209716 ~]# dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.5.rpm  

检查是否多了 remi 仓库 

[root@ecs-209716 ~]# dnf repolist
repo id                                       repo name
AppStream                                     CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
appstream                                     CentOS Linux 8 - AppStream
base                                          CentOS-8.5.2111 - Base - mirrors.aliyun.com
epel                                          Extra Packages for Enterprise Linux 8 - x86_64
epel-archive                                  Extra Packages for Enterprise Linux 8 - x86_64
extras                                        CentOS-8.5.2111 - Extras - mirrors.aliyun.com
mysql-connectors-community                    MySQL Connectors Community
mysql-tools-community                         MySQL Tools Community
mysql80-community                             MySQL 8.0 Community Server
remi-modular                                  Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe                                     Safe Remi's RPM repository for Enterprise Linux 8 - x86_64

检查 php 模块 

[root@ecs-209716 ~]# dnf module list php
Last metadata expiration check: 0:02:17 ago on Fri 16 Dec 2022 09:31:36 PM CST.
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
Name                Stream                  Profiles                                  Summary                              
php                 7.2 [d]                 common [d], devel, minimal      PHP scripting language               
php                 7.3                     common [d], devel, minimal       PHP scripting language               
php                 7.4                     common [d], devel, minimal       PHP scripting language         Remi's Modular repository for Enterprise Linux 8 - x86_64
Name                Stream                  Profiles                                  Summary                              
php                 remi-7.2                common [d], devel, minimal     PHP scripting language         
php                 remi-7.3                common [d], devel, minimal     PHP scripting language               
php                 remi-7.4                common [d], devel, minimal     PHP scripting language               
php                 remi-8.0                common [d], devel, minimal     PHP scripting language               
php                 remi-8.1                common [d], devel, minimal     PHP scripting language               
php                 remi-8.2                common [d], devel, minimal     PHP scripting language               

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

安装 PHP 8.0 之前启用这个模块,要启用 php:remi-8.0 需执行:

[root@ecs-209716 ~]# dnf module enable php:remi-8.0 -y
Last metadata expiration check: 1:40:22 ago on Fri 16 Dec 2022 09:31:36 PM CST.
Dependencies resolved.
===================================================================== 
 Package                      Architecture                Version                       Repository                    Size
===================================================================== 
Enabling module streams:  php                     remi-8.0                     Transaction Summary
===================================================================== 

Complete!

如果切换到 php 8.2 版本 ,先 disanble ,再 enable 

[root@ecs-209716 ~]# dnf module disable php:remi-8.0 -y

[root@ecs-209716 ~]# dnf module enable php:remi-8.2 -y

采用 Nginx 服务器作为技术栈,在启用后安装 php-fpm 扩展:

[xxx@ecs-209716 ~]$ sudo  dnf install php php-cli php-common php-fpm

检查 php 版本 

[xxx@ecs-209716 ~]$ sudo php -v
PHP 8.2.0 (cli) (built: Dec  6 2022 14:26:47) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies

编辑一个最实用的 php 页面 

[fjy@ecs-209716 ~]$ sudo vi /usr/share/nginx/html/info.php 
[fjy@ecs-209716 ~]$ cat /usr/share/nginx/html/info.php 

<?php

phpinfo();

?>

使用 浏览器访问地址  http://116.205.242.110/info.php

PHP 扩展提供 PHP 标准库以的附加功能。使用 sudo dnf install php-{entension-name} 预发进行安装。

比如,需要 PHP 支持使用 MySQL,执行这个命令安装 PHP 扩展:

sudo dnf install php-mysql 

一些其他可能的扩展模块 

sudo dnf install php-gd

sudo dnf install php-imagick

sudo dnf install php-zip

验证扩展是否安装成功: 

php -m 

将 php-fpm 服务加载到系统初始化任务

启用系统服务:

sudo systemctl enable php-fpm

开启 php-fpm 服务并查看状态:

sudo systemctl start php-fpm

sudo systemctl status php-fpm

停止或重启服务:

sudo systemctl stop php-fpm

sudo systemctl restart php-fom

php 服务的状态 

[xxx@ecs-209716 ~]$ sudo systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-12-16 23:38:13 CST; 2min 24s ago
 Main PID: 1532542 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6 (limit: 23712)
   Memory: 17.8M
   CGroup: /system.slice/php-fpm.service
           ├─1532542 php-fpm: master process (/etc/php-fpm.conf)
           ├─1532544 php-fpm: pool www
           ├─1532545 php-fpm: pool www
           ├─1532546 php-fpm: pool www
           ├─1532547 php-fpm: pool www
           └─1532548 php-fpm: pool www

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值