lamp架构
1:lamp简介
所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。
2:http协议
HTTP 协议是 Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网( WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议。
HTTP 是一个基于 TCP/IP 通信协议来传递数据(HTML 文件、图片文件、查询结果等)
HTTPS 经由 HTTP 进行通信,但利用 SSL/TLS 来加密数据包,HTTPS 开发的主要目的,是提供对网站服务器的身份认证,保护交换资料的隐私与完整性。
2.1 作用
HTTPS 的主要作用是在不安全的网络上创建一个安全信道,并可在使用适当的加密包和服务器证书可被验证且可被信任时,对窃听和中间人攻击提供合理的防护。
HTTPS 的信任基于预先安装在操作系统中的证书颁发机构(CA)
3:httpd与php结合的方式
httpd与php结合的方式有以下三种:
modules:php将以httpd的扩展模块形式存在,需要加载动态资源时,httpd可以直接通过php模块来加工资源并返回给客户端
httpd prefork:libphp5.so(多进程模型的php)
httpd event or worker:libphp5-zts.so(线程模型的php)
CGI:httpd需要加载动态资源时,通过CGI与php解释器联系,获得php执行的结果,此时httpd负责与php连接的建立和断开等
FastCGI:利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信
4:cgi与fastcgi
CGI(Common Gateway Interface,通用网关接口),CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。
FastCGI(Fast Common Gateway Interface)是CGI的改良版,CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,即启动一个master主进程,然后根据配置启动几个worker进程,当请求进来时,master会从worker进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时
5:lamp架构工作原理
客户端通过http协议请求web服务器资源
web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
若是静态资源则直接从本地文件系统取之返回给客户端。
否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
6:lamp架构部署
安装顺序
httpd>mysql>php
配置yum源
此处我用的是阿里云的源
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-08-02 15:26:25-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 223.76.171.231, 223.76.171.230, 223.76.170.229, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|223.76.171.231|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2495 (2.4K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
/etc/yum.repos.d/CentOS-Base.repo 100%[=============================================================================>] 2.44K --.-KB/s 用时 0.02s
2022-08-02 15:26:26 (124 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2495/2495])
[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 install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
CentOS-8.5.2111 - Base - mirrors.aliyun.com 594 kB/s | 4.6 MB 00:07
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 29 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 418 kB/s | 8.4 MB 00:20
epel-release-latest-8.noarch.rpm 44 kB/s | 24 kB 00:00
............
............ 1/1
安装 : epel-release-8-16.el8.noarch 1/1
运行脚本: epel-release-8-16.el8.noarch 1/1
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.
验证 : epel-release-8-16.el8.noarch 1/1
已安装:
epel-release-8-16.el8.noarch
完毕!
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost ~]#
安装httpd
下载编译安装所需要的组包和依赖包
[root@localhost ~]# yum -y groupinstall "Development Tools"
CentOS Stream 8 - AppStream 259 kB/s | 24 MB 01:34
CentOS Stream 8 - BaseOS 3.1 MB/s | 25 MB 00:07
CentOS Stream 8 - Extras 17 kB/s | 18 kB 00:01
依赖关系解决。
==============================================================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================================================
升级:
binutils x86_64 2.30-117.el8 baseos 5.8 M
elfutils-libelf x86_64 0.187-4.el8 baseos 231 k
............................
............................
systemtap-devel-4.7-1.el8.x86_64 systemtap-runtime-4.7-1.el8.x86_64
tbb-2018.2-9.el8.x86_64 tzdata-java-2022a-2.el8.noarch
valgrind-1:3.19.0-1.el8.x86_64 valgrind-devel-1:3.19.0-1.el8.x86_64
xorg-x11-fonts-ISO8859-1-100dpi-7.5-19.el8.noarch xz-devel-5.2.4-3.el8.x86_64
zlib-devel-1.2.11-17.el8.x86_64 zstd-1.4.4-1.el8.x86_64
完毕!
[root@localhost ~]#
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
Extra Packages for Enterprise Linux 8 - x86_64 394 kB/s | 13 MB 00:32
Extra Packages for Enterprise Linux Modular 8 - x86_64 274 kB/s | 1.0 MB 00:03
上次元数据过期检查:0:00:03 前,执行于 2022年08月02日 星期二 15时30分41秒。
软件包 libtool-2.4.6-25.el8.x86_64 已安装。
软件包 gcc-8.5.0-15.el8.x86_64 已安装。
软件包 gcc-c++-8.5.0-15.el8.x86_64 已安装。
依赖关系解决。
==============================================================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================================================
安装:
expat-devel x86_64 2.2.5-4.el8 base 55 k
.............
.............
已安装:
expat-devel-2.2.5-4.el8.x86_64 keyutils-libs-devel-1.5.10-9.el8.x86_64 krb5-devel-1.18.2-14.el8.x86_64 libcom_err-devel-1.45.6-2.el8.x86_64
libkadm5-1.18.2-14.el8.x86_64 libselinux-devel-2.9-5.el8.x86_64 libsepol-devel-2.9-3.el8.x86_64 libverto-devel-0.3.0-5.el8.x86_64
openssl-devel-1:1.1.1k-5.el8_5.x86_64 pcre-cpp-8.42-6.el8.x86_64 pcre-devel-8.42-6.el8.x86_64 pcre-utf16-8.42-6.el8.x86_64
pcre-utf32-8.42-6.el8.x86_64 pcre2-devel-10.32-2.el8.x86_64 pcre2-utf16-10.32-2.el8.x86_64 pcre2-utf32-10.32-2.el8.x86_64
完毕!
[root@localhost ~]#
创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
编译安装apr和apr-util
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
annobin apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 debug httpd-2.4.54.tar.bz2 kernels
[root@localhost apr-1.6.5]# vim configure
# $RM "$cfgfile"
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.5
checking for chosen layout... apr
checking for gcc... gcc
...................
...................
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
[root@localhost apr-1.6.5]# make -j4 && make install
make[1]: 进入目录“/usr/src/apr-1.6.5”
/usr/src/apr-1.6.5/build/mkdir.sh tools
/bin/sh /usr/src/apr-1.6.5/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I./include -I/usr/src/apr-1.6.5/include/arch/unix -I./include/arch/unix -I/usr/src/apr-1.6.5/include/arch/unix -I/usr/src/apr-1.6.5/include -I/usr/src/apr-1.6.5/include/private -I/usr/src/apr-1.6.5/include/private -o tools/gen_test_char.lo -c tools/gen_test_char.c && touch tools/gen_test_char.lo
.................
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 644 /usr/src/apr-1.6.5/build/apr_common.m4 /usr/local/apr/build-1
/usr/bin/install -c -m 644 /usr/src/apr-1.6.5/build/find_apr.m4 /usr/local/apr/build-1
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@localhost apr-1.6.5]#
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost src]# cd apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
........................
........................
config.status: creating include/private/apu_select_dbm.h
config.status: creating include/apr_ldap.h
config.status: creating include/apu.h
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
................
................
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
编译安装httpd
[root@localhost httpd-2.4.54]# ./configure --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd24 \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
过程省略
[root@localhost httpd-2.4.54]# make -j4 && make install
过程省略
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls
bin build cgi-bin error htdocs icons include logs man manual modules
安装完成后配置环境变量
[root@localhost apache]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost apache]# . /etc/profile.d/httpd.sh
[root@localhost apache]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost apache]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/apache/man
修改配置文件
[root@localhost /]# vim /etc/httpd24/httpd.conf
ServerName www.example.com:80
[root@localhost /]# httpd -t
Syntax OK
将apache启动方式设置为systemctl
[root@localhost /]# cd /usr/lib/systemd/system/
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim httpd.service
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl start httpd.service
[root@localhost system]# ss -antl
LISTEN 0 128 *:80 *:*
[root@localhost system]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
Execstop=/usr/locl/apache/bin/apachectl stop
KillMode=process
[Install]
WantedBy=multi-user.target
安装mysql
安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake
上次元数据过期检查:0:28:19 前,执行于 2022年08月02日 星期二 15时30分41秒。
软件包 openssl-devel-1:1.1.1k-5.el8_5.x86_64 已安装。
软件包 openssl-1:1.1.1k-5.el8_5.x86_64 已安装。
依赖关系解决。
.................
.................
已安装:
cmake-3.20.2-4.el8.x86_64 cmake-data-3.20.2-4.el8.noarch cmake-filesystem-3.20.2-4.el8.x86_64 cmake-rpm-macros-3.20.2-4.el8.noarch
libuv-1:1.41.1-1.el8_4.x86_64 ncurses-c++-libs-6.1-9.20180224.el8.x86_64 ncurses-devel-6.1-9.20180224.el8.x86_64
完毕!
创建用户和组
[root@localhost ~]# useradd -M -r -s /sbin/nologin mysql
安装mysql
[root@localhost ~]# cd /usr/src/
[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz mysql
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/mysql/man
[root@localhost local]# echo '/var/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# mkdir /opt/data/
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-02T08:10:34.107210Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T08:10:34.359408Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T08:10:34.983507Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T08:10:34.983541Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T08:10:34.983943Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T08:10:35.112979Z 1 [Note] A temporary password is generated for root@localhost: h0h8bdKBoB&A
[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
将mysql设置为可以用systemctl启动
[root@localhost mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data
[root@localhost mysql]# cd /usr/lib/systemd/system/
[root@localhost system]# cp httpd.service mysqld.service
[root@localhost system]# vim mysqld.service
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl start mysqld.service
[root@localhost system]# cat mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
Execstop=/etc/init.d/mysqld stop
KillMode=process
[Install]
WantedBy=multi-user.target
下载所需要的包
[root@localhost system]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost system]# yum -y install libncurses.so.5*
已安装:
ncurses-compat-libs-6.1-9.20180224.el8.x86_64
完毕!
[root@localhost system]#
启动mysql并更改密码
[root@localhost system]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
安装php
下载依赖包
[root@localhost system]# yum -y install libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
上次元数据过期检查:0:51:00 前,执行于 2022年08月02日 星期二 15时30分41秒。
软件包 openssl-1:1.1.1k-5.el8_5.x86_64 已安装。
软件包 openssl-devel-1:1.1.1k-5.el8_5.x86_64 已安装。
软件包 bzip2-1.0.6-26.el8.x86_64 已安装。
软件包 libcurl-7.61.1-22.el8.x86_64 已安装。
软件包 libjpeg-turbo-1.5.3-12.el8.x86_64 已安装。
软件包 libpng-2:1.6.34-5.el8.x86_64 已安装。
软件包 pcre-devel-8.42-6.el8.x86_64 已安装。
软件包 freetype-2.9.1-4.el8_3.1.x86_64 已安装。
软件包 gmp-1:6.1.2-10.el8.x86_64 已安装。
...............
...............
已降级:
libxml2-2.9.7-9.el8_4.2.x86_64 python3-libxml2-2.9.7-9.el8_4.2.x86_64
已安装:
bzip2-devel-1.0.6-26.el8.x86_64 cyrus-sasl-devel-2.1.27-5.el8.x86_64 freetype-devel-2.9.1-4.el8_3.1.x86_64 gmp-c++-1:6.1.2-10.el8.x86_64
gmp-devel-1:6.1.2-10.el8.x86_64 libcurl-devel-7.61.1-22.el8.x86_64 libgcrypt-devel-1.8.5-6.el8.x86_64 libgpg-error-devel-1.31-1.el8.x86_64
libicu-devel-60.3-2.el8_1.x86_64 libjpeg-turbo-devel-1.5.3-12.el8.x86_64 libmcrypt-2.5.8-26.el8.x86_64 libmcrypt-devel-2.5.8-26.el8.x86_64
libpng-devel-2:1.6.34-5.el8.x86_64 libxml2-devel-2.9.7-9.el8_4.2.x86_64 libxslt-devel-1.1.32-6.el8.x86_64 mhash-0.9.9.9-20.el8.x86_64
mhash-devel-0.9.9.9-20.el8.x86_64 openldap-devel-2.4.46-18.el8.x86_64 readline-devel-7.0-10.el8.x86_64
完毕!
[root@localhost system]#
下载php压缩包,并编译安装
[root@localhost system]# cd /usr/src/
[root@localhost src]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
--2022-08-02 16:23:08-- https://www.php.net/distributions/php-7.4.30.tar.xz
正在解析主机 www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
正在连接 www.php.net (www.php.net)|185.85.0.29|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:10419136 (9.9M) [application/octet-stream]
正在保存至: “php-7.4.30.tar.xz”
php-7.4.30.tar.xz 100%[=============================================================================>] 9.94M 598KB/s 用时 22s
2022-08-02 16:23:32 (463 KB/s) - 已保存 “php-7.4.30.tar.xz” [10419136/10419136])
[root@localhost src]# ls
annobin apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.54 kernels mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5 apr-util-1.6.1 debug httpd-2.4.54.tar.bz2 mysql php-7.4.30.tar.xz
[root@localhost src]# tar xf php-7.4.30.tar.xz
[root@localhost src]# cd php-7.4.30/
编译安装第一步报错报错方案
[root@localhost php-7.4.30]#./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
//报错为上
解决方案
[root@localhost php-7.4.30]# yum install sqlite-devel
继续编译安装
报新错为
configure: error: Package requirements (oniguruma) were not met:
解决方案
[root@localhost ~]# wget http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
--2022-08-02 16:32:03-- http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
正在解析主机 mirror.centos.org (mirror.centos.org)... 147.75.93.85, 2604:1380:3011:1f00::1
正在连接 mirror.centos.org (mirror.centos.org)|147.75.93.85|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:48540 (47K) [application/x-rpm]
正在保存至: “oniguruma-devel-6.8.2-2.el8.x86_64.rpm”
oniguruma-devel-6.8.2-2.el8.x86_64.rpm 100%[=============================================================================>] 47.40K 78.0KB/s 用时 0.6s
2022-08-02 16:32:05 (78.0 KB/s) - 已保存 “oniguruma-devel-6.8.2-2.el8.x86_64.rpm” [48540/48540])
[root@localhost ~]# yum localinstall oniguruma-devel-6.8.2-2.el8.x86_64.rpm
已安装:
oniguruma-devel-6.8.2-2.el8.x86_64
完毕!
[root@localhost ~]#
继续编译安装接着报错
报错为以下
configure: WARNING: unrecognized options: --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-zip
因为我的编译安装选项是centos7安装的版本更新了,大多选项不叫以前的名字了所以这里换上现版本的选项就ok了
[root@localhost php-7.4.30]# ./configure --help | grep gd
--with-gdbm[=DIR] DBA: GDBM support
--enable-gd Include GD support
--with-external-gd Use external libgd
--with-webp GD: Enable WEBP support (only for bundled libgd)
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
--with-xpm GD: Enable XPM support (only for bundled libgd)
libgd)
--enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support (only
for bundled libgd)
[root@localhost php-7.4.30]# ./configure --help | grep jpeg
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
[root@localhost php-7.4.30]# ./configure --help | grep png
[root@localhost php-7.4.30]# ./configure --help | grep freetype
--with-freetype GD: Enable FreeType 2 support (only for bundled
[root@localhost php-7.4.30]# ./configure --help | grep zip
--with-zip Include Zip read/write support
[root@localhost php-7.4.30]#
更新完后继续编译安装
又报错为没有libzip那就去安装
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables LIBZIP_CFLAGS
and LIBZIP_LIBS to avoid the need to call pkg-config.
解决方案
[root@localhost ~]# wget https://libzip.org/download/libzip-1.2.0.tar.gz
[root@localhost ~]# tar -zxvf libzip-1.2.0.tar.gz
[root@localhost ~]# cd libzip-1.2.0/
[root@localhost libzip-1.2.0]# ./configure
[root@localhost libzip-1.2.0]# make -j4 && make install
继续编译安装,安装成功
[root@localhost ~]# cd /usr/src/php-7.4.30/
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-json --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking build system type... x86_64-pc-linux-gnu
...............
...............
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[root@localhost php-7.4.30]# make -j 4 && make install
[root@localhost php-7.4.30]# cd /usr/local/php7/
[root@localhost php7]#
配置php
[root@localhost php7]# ls
bin etc include lib php sbin var
[root@localhost php7]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php7]# ln -s /usr/local/php7/include /usr/include/php
[root@localhost php7]# echo '/var/local/php7/lib' > /etc/ld.so.conf.d/php.conf
[root@localhost php7]#
[root@localhost php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.30]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost php7]# cd /usr/lib/systemd/system/
[root@localhost system]# cp mysqld.service php-fpm.service
[root@localhost system]# vim php-fpm.service
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl restart php-fpm.service
[root@localhost system]# cat php-fpm.service
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
Execstop=/etc/init.d/php-fpm stop
KillMode=process
[Install]
WantedBy=multi-user.target
[root@localhost system]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6011 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 128 [::1]:6011 [::]:*
[root@localhost system]#
配置apache
启用代理模块
[root@localhost system]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
[root@localhost system]# httpd -t
Syntax OK
配置虚拟主机目录和创建主页
[root@localhost system]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir phpshe1.8
[root@localhost htdocs]# vim phpshe1.8/index.php
[root@localhost htdocs]# cat phpshe1.8/index.php
<?php
phpinfo();
?>
[root@localhost
[root@localhost htdocs]# ls
phpshe1.8
[root@localhost httpd24]# vim /etc/httpd24/httpd.conf
Include /etc/httpd24/extra/httpd-vhosts.conf //去掉注释
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps //增加这两行
<IfModule dir_module>
DirectoryIndex index.php index.html //修改此行
</IfModule>
[root@localhost httpd24]# vim /etc/httpd24/extra/httpd-vhosts.conf
[root@localhost httpd24]# httpd -t
Syntax OK
[root@localhost httpd24]# cat /etc/httpd24/extra/httpd-vhosts.conf
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/phpshe1.8"
ServerName www.phpshe1.8.com
ErrorLog "logs/phpshe1.8_log"
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/phpshe1.8/$1
CustomLog "logs/phpshe1.8_log" common
<Directory "/usr/local/apache/htdocs/phpshe1.8">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
测试