lamp架构介绍及环境搭建
文章目录
1. web工作流程
通过上面的图说明一下web的工作流程:
- 客户端通过http协议请求web服务器资源
- web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
- 若是静态资源则直接从本地文件系统取之返回给客户端。
- 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
2.lamp平台构建
环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
centos8 redhat8 |
192.168.223.153 | httpd-2.4.54 mysql-5.7.38 php php-mysql |
lamp平台软件安装次序:
httpd --> mysql --> php
注意:php要求httpd使用prefork MPM
2.1 安装httpd
//YUM源配置
[root@localhost ~]# yum -y install vim wget make
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-08-02 08:44:02-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 43.224.184.230, 43.224.184.231, 45.253.17.211, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|43.224.184.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2495 (2.4K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
/etc/yum.repos.d 100%[==========>] 2.44K --.-KB/s in 0.002s
2022-08-02 08:44:02 (1.53 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2495/2495]
[root@localhost yum.repos.d]# cd
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
CentOS-8.5.2111 - Base - mirrors.aliyun.com 15 kB/s | 3.9 kB 00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 4.9 kB/s | 1.5 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 42 kB/s | 4.3 kB 00:00
epel-release-latest-8.noarch.rpm 164 kB/s | 24 kB 00:00
Dependencies resolved.
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools'
Extra Packages for Enterprise Linux Modular 8 - x86_6 629 kB/s | 1.0 MB 00:01
Extra Packages for Enterprise Linux 8 - x86_64 8.3 MB/s | 13 MB 00:01
.....
Is this ok [y/N]: y
Complete!
//创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache
//安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
Last metadata expiration check: 0:03:02 ago on Tue 02 Aug 2022 08:17:10 PM CST.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Package libtool-2.4.6-25.el8.x86_64 is already installed.
Package gcc-8.4.1-1.el8.x86_64 is already installed.
Package gcc-c++-8.4.1-1.el8.x86_64 is already installed.
Dependencies resolved.
.....
zlib-devel-1.2.11-17.el8.x86_64
Complete!
/下载和安装apr以及apr-util
[root@localhost src]# wget https://downloads.apache.org/apr/apr-1.6.5.tar.bz2
--2022-08-03 10:30:32-- https://downloads.apache.org/apr/apr-1.6.5.tar.bz2
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... conne