CentOS8搭建Web服务器笔记1 Nginx+Php8基础环境
- 1. Nginx
- 2. PHP
-
- 2.1 REMI存储库安装稳定版
- 2.2 手动编译安装最新版
- 2.3 PHP-FPM 调优
1. Nginx
1.1 Yum工具安装
1.1.1 查询Yum默认安装源版本
yum info nginx
[root@VM-0-16-centos ~]# yum info nginx
Last metadata expiration check: 1:35:28 ago on Fri 19 Feb 2021 02:07:01 AM CST.
Available Packages
Name : nginx
Epoch : 1
Version : 1.14.1
Release : 9.module_el8.0.0+184+e34fea82
Architecture : x86_64
Size : 570 k
Source : nginx-1.14.1-9.module_el8.0.0+184+e34fea82.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server
URL : http://nginx.org/
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
: IMAP protocols, with a strong focus on high concurrency, performance and low
: memory usage.
1.1.2 配置最新安装源
- 编辑安装源配置
vim /etc/yum.repos.d/nginx.repo
[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
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
- 系统默认安装稳定版本,需要默认安装源主线版本用命令
yum-config-manager --enable nginx-mainline
[root@VM-32-7-centos ~]# yum-config-manager --enable nginx-mainline
-bash: yum-config-manager: command not found
报错command not found,安装yum-utils工具包
yum -y install yum-utils
- 可以直接修改 nginx.repo 设置默认安装版本
修改/etc/yum.repos.d/nginx.repo中相应版本的enabled=1 or enabled=0
重新查看默认安装版本
yum info nginx
[root@VM-0-16-centos ~]# yum info nginx
nginx stable repo 6.5 kB/s | 2.9 kB 00:00
Available Packages
Name : nginx
Epoch : 1
Version : 1.18.0
Release : 2.el8.ngx
Architecture : x86_64
Size : 799 k
Source : nginx-1.18.0-2.el8.ngx.src.rpm
Repository : nginx-stable
Summary : High performance web server
URL : http://nginx.org/
License : 2-clause BSD-like license
Description : nginx [engine x] is an HTTP and reverse proxy server, as well as
: a mail proxy server.
1.1.3 yum安装nginx
yum install nginx
[root@VM-0-16-centos ~]# yum install nginx
Last metadata expiration check: 0:02:47 ago on Fri 19 Feb 2021 04:26:32 AM CST.
Dependencies resolved.
====================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================
Installing:
nginx x86_64 1:1.18.0-2.el8.ngx nginx-stable 799 k
Transaction Summary
====================================================================================================================
Install 1 Package
Total download size: 799 k
Installed size: 2.7 M
Is this ok [y/N]: y
Downloading Packages:
nginx-1.18.0-2.el8.ngx.x86_64.rpm 559 kB/s | 799 kB 00:01
--------------------------------------------------------------------------------------------------------------------
Total 559 kB/s | 799 kB 00:01
warning: /var/cache/dnf/nginx-stable-614ef03fac352fea/packages/nginx-1.18.0-2.el8.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
nginx stable repo 1.8 kB/s | 1.5 kB 00:00
Importing GPG key 0x7BD9BF62:
Userid : "nginx signing key <signing-key@nginx.com>"
Fingerprint: 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
From : https://nginx.org/keys/nginx_signing.key
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: nginx-1:1.18.0-2.el8.ngx.x86_64 1/1
Installing : nginx-1:1.18.0-2.el8.ngx.x86_64 1/1
Running scriptlet: nginx-1:1.18.0-2.el8.ngx.x86_64 1/1
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* http://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* http://nginx.com/products/
----------------------------------------------------------------------
Verifying : nginx-1:1.18.0-2.el8.ngx.x86_64 1/1
Installed:
nginx-1:1.18.0-2.el8.ngx.x86_64
Complete!
1.1.4 启动nginx服务
[root@VM-0-16-centos ~]# systemctl start nginx
开机自启动
[root@VM-0-16-centos ~]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
1.1.5 查看状态和站点
查看nginx运行状态
[root@VM-0-16-centos ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-02-19 05:04:20 CST; 41s ago
Docs: http://nginx.org/en/docs/
Main PID: 3255 (nginx)
Tasks: 2 (limit: 11508)
Memory: 2.0M
CGroup: /system.slice/nginx.service
├─3255 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─3256 nginx: worker process
Feb 19 05:04:20 VM-0-16-centos systemd[1]: Starting nginx - high performance web server...
Feb 19 05:04:20 VM-0-16-centos systemd[1]: nginx.service: Can't open PID file /var/run/nginx.pi>
Feb 19 05:04:20 VM-0-16-centos systemd[1]: Started nginx - high performance web server.
命令行查看80端口是否正确返回页面内容
[root@VM-0-16-centos ~]# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
- 浏览器输入公网IP查看
1.2. 手动下载编译安装
1.2.1查询Nginx官网最新版本
https://nginx.org/
1.2.2 创建临时下载目录
在/usr/local目录下创建临时下载目录
/usr/local:用户级的程序目录,相当windows的C:/Progrem Files
[root@VM-0-16-centos ~]# mkdir /usr/local/downloads
[root@VM-0-16-centos ~]# cd /usr/local/downloads
1.2.3 下载nginx源码包
wget http://nginx.org/download/nginx-1.19.7.tar.gz
[root@VM-0-16-centos downloads]#wget http://nginx.org/download/nginx-1.19.7.tar.gz
--2021-02-19 00:05:47-- http://nginx.org/download/nginx-1.19.7.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1056631 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.19.7.tar.gz’
nginx-1.19.7.tar.gz 100%[====================================>] 1.01M 19.4KB/s in 55s
2021-02-19 00:06:43 (18.8 KB/s) - ‘nginx-1.19.7.tar.gz’ saved [1056631/1056631]
[root@VM-0-16-centos downloads]# ls
nginx-1.19.7.tar.gz
- 解压安装文件到downloads目录
tar -zxvf /usr/local/downloads/nginx-1.19.7.tar.gz -C /usr/local/downloads
[root@VM-0-16-centos downloads]# mkdir /usr/local/software
[root@VM-0-16-centos downloads]# mkdir /usr/local/software/nginx
[root@VM-0-16-centos downloads]# cd /usr/local/software/nginx
[root@VM-0-16-centos nginx]# tar -zxvf /usr/local/downloads/nginx-1.19.7.tar.gz -C /usr/local/software/nginx
[root@VM-0-16-centos nginx]#
1.2.4安装gcc编译器及pcre库等环境
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@VM-0-16-centos nginx]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 1:19:41 ago on Thu 18 Feb 2021 11:05:56 PM CST.
Package gcc-8.3.1-5.el8.0.2.x86_64 is already installed.
Package pcre-8.42-4.el8.x86_64 is already installed.
Package zlib-1.2.11-13.el8.x86_64 is already installed.
Package zlib-devel-1.2.11-13.el8.x86_64 is already installed.
Package openssl-1:1.1.1c-15.el8.x86_64 is already installed.
Dependencies resolved.
=======================================================================================================
Package Architecture Version Repository Size
=======================================================================================================
Installing:
openssl-devel x86_64 1:1.1.1g-12.el8_3 BaseOS 2.3 M
pcre-devel x86_64 8.42-4.el8 BaseOS 551 k
Upgrading:
cpp x86_64 8.3.1-5.1.el8 AppStream 10 M
e2fsprogs x86_64 1.45.6-1.el8 BaseOS 1.0 M
e2fsprogs-libs x86_64 1.45.6-1.el8 BaseOS 233 k
gcc x86_64 8.3.1-5.1.el8 AppStream 23 M
krb5-libs x86_64 1.18.2-5.el8 BaseOS 837 k
libcom_err x86_64 1.45.6-1.el8 BaseOS 49 k
libgcc x86_64 8.3.1-5.1.el8 BaseOS 78 k
libgomp x86_64 8.3.1-5.1.el8 BaseOS 204 k
libselinux x86_64 2.9-4.el8_3 BaseOS 165 k
libselinux-utils x86_64 2.9-4.el8_3 BaseOS 242 k
libss x86_64 1.45.6-1.el8 BaseOS 53 k
openssl x86_64 1:1.1.1g-12.el8_3 BaseOS 707 k
openssl-libs x86_64 1:1.1.1g-12.el8_3 BaseOS 1.5 M
pcre2 x86_64 10.32-2.el8 BaseOS 246 k
python3-libselinux x86_64 2.9-4.el8_3 BaseOS 283 k
zlib x86_64 1.2.11-16.el8_2 BaseOS 102 k
zlib-devel x86_64 1.2.11-16.el8_2 BaseOS 57 k
Installing dependencies:
keyutils-libs-devel x86_64 1.5.10-6.el8 BaseOS 48 k
krb5-devel x86_64 1.18.2-5.el8 BaseOS 558 k
libcom_err-devel x86_64 1.45.6-1.el8 BaseOS 38 k
libkadm5 x86_64 1.18.2-5.el8 BaseOS 185 k
libselinux-devel x86_64 2.9-4.el8_3 BaseOS 199 k
libsepol-devel x86_64 2.9-1.el8 BaseOS 86 k
libverto-devel x86_64 0.3.0-5.el8 BaseOS 18 k
pcre-cpp x86_64 8.42-4.el8 BaseOS 47 k
pcre-utf16 x86_64 8.42-4.el8 BaseOS 195 k
pcre-utf32 x86_64 8.42-4.el8 BaseOS 186 k
pcre2-devel x86_64 10.32-2.el8 BaseOS 605 k
pcre2-utf16 x86_64 10.32-2.el8 BaseOS 229 k
pcre2-utf32 x86_64 10.32-2.el8 BaseOS 220 k
Transaction Summary
========================================================