lamp安装操作讲解

article/2025/9/23 6:03:54

1. lamp简介

有了前面学习的知识的铺垫,今天可以来学习下第一个常用的web架构了。
所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。

2. web服务器工作流程

在说lamp架构平台的搭建前,我们先来了解下什么是CGI,什么是FastCGI,什么是…
web服务器的资源分为两种,静态资源和动态资源

  • 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
  • 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端

那么web服务器如何执行程序并将结果返回给客户端呢?下面通过一张图来说明一下web服务器如何处理客户端的请求
在这里插入图片描述

如上图所示
阶段①显示的是httpd服务器(即apache)和php服务器通过FastCGI协议进行通信,且php作为独立的服务进程运行
阶段②显示的是php程序和mysql数据库间通过mysql协议进行通信。php与mysql本没有什么联系,但是由Php语言写成的程序可以与mysql进行数据交互。同理perl和python写的程序也可以与mysql数据库进行交互

2.1 cgi与fastcgi

上图阶段①中提到了FastCGI,下面我们来了解下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上下文切换而导致耗时

2.2 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通信

较于CGI方式,FastCGI更为常用,很少有人使用CGI方式来加载动态资源

2.3 web工作流程

通过上面的图说明一下web的工作流程:

  • 客户端通过http协议请求web服务器资源
  • web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
    • 若是静态资源则直接从本地文件系统取之返回给客户端。
    • 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。

3. lamp平台构建

环境说明:

系统平台IP需要安装的服务
centos7
redhat7192.168.141.135httpd-2.4
mysql-5.7
php
php-mysql

lamp平台软件安装次序:
httpd –> mysql --> php
注意:php要求httpd使用prefork MPM

3.1安装httpd

//YUM源配置
[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 20:13:14--  https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 223.76.171.230, 223.76.170.231, 223.76.170.226, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|223.76.171.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/Cent 100%[=======================>]   2.44K  --.-KB/s    in 0s      2022-08-02 20:13:14 (82.5 MB/s) -/etc/yum.repos.d/CentOS-Base.repo’ saved [2495/2495]
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@localhost yum.repos.d]# 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.repos.d]# //安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools'
[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!//安装依赖包
[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!
[root@localhost ~]# //创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# id apache 
uid=987(apache) gid=983(apache) groups=983(apache)
[root@localhost ~]# //下载和安装apr以及apr-util 如果无法下载可以进入https://apache.org/ 在官网下载
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
--2022-08-02 20:27:08--  https://downloads.apache.org/apr/apr-1.7.0.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/x-gzip]
Saving to: ‘apr-1.7.0.tar.gz’
......[root@localhost src]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
--2022-08-02 20:27:53--  https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/x-gzip]
Saving to: ‘apr-util-1.6.1.tar.gz’
......#解压压缩包并进入
[root@localhost src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  kernels
[root@localhost src]# tar xf apr-1.7.0.tar.gz 
[root@localhost src]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost src]# ls
apr-1.7.0  apr-1.7.0.tar.gz  apr-util-1.6.1  apr-util-1.6.1.tar.gz  debug  kernels
[root@localhost src]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure   #查找/cfgfilecfgfile="${ofile}T"                         trap "$RM \"$cfgfile\"; exit 1" 1 2 15# $RM "$cfgfile"        //将此行加上注释,或者删除此行 [root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
配置过程略...
[root@localhost apr-1.7.0]# make 
先编译安装查看是否有错,过程略...
[root@localhost apr-1.7.0]# make install#进入apr-util-1.6.1
[root@localhost src]# cd /usr/src/apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
配置过程略...
[root@localhost apr-util-1.6.1]# make  
编译安装过程略...
[root@localhost apr-util-1.6.1]# make install
[root@localhost apr-util-1.6.1]# ls /usr/local/
apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
#查看是否有apr  apr-util//编译安装httpd
[root@localhost ~]# cd /usr/src
[root@localhost src]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.38.tar.gz
[root@localhost src]# ls
apr-1.7.0         apr-util-1.6.1         debug                kernels
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@localhost src]# tar xf httpd-2.4.54.tar.gz 
[root@localhost src]# cd httpd-2.4.54/
[root@localhost httpd-2.4.54]# ./configure --prefix=/usr/local/apache \
--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
......Server Version: 2.4.54Install prefix: /usr/local/apacheC compiler:     gccCFLAGS:          -g -O2 -pthread  CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  LDFLAGS:           LIBS:             C preprocessor: gcc -E[root@localhost httpd-2.4.54]# make 
编译安装过程略...
[root@localhost httpd-2.4.54]# make install
编译安装过程略...//安装后配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# cat /etc/profile.d/httpd.sh 
export PATH=/usr/local/apache/bin:$PATH     #查看配置配置成功了吗
[root@localhost ~]# ls /usr/local/
apache  apr-util  etc    include  lib64    sbin   src
apr     bin       games  lib      libexec  share
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd   #查看是否有httpd
[root@localhost ~]# [root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# vim /etc/man_db.conf 
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man #添加
#---------------------------------------------------------//编写配置文件启动apache
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim httpd.service 
[Unit]
Description=web server daemon
Documentation=man:httpd(5)
After=network.target sshd-keygen.target[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/local/apache/bin/apachectl stop[Install]
WantedBy=multi-user.target[root@localhost system]# cd
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status httpd
● httpd.service - web server daemonLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: di>Active: inactive (dead)Docs: man:httpd(5)
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0        128                   [::]:22                 [::]:*                
LISTEN   0        128                      *:80                    *:*                
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl status httpd
● httpd.service - web server daemonLoaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: dis>Active: active (running) since Tue 2022-08-02 21:07:42 CST; 34s agoDocs: man:httpd(5)Main PID: 68977 (httpd)Tasks: 6 (limit: 49288)Memory: 5.5MCGroup: /system.slice/httpd.service├─68977 /usr/local/apache/bin/httpd -k start├─68978 /usr/local/apache/bin/httpd -k start├─68979 /usr/local/apache/bin/httpd -k start├─68980 /usr/local/apache/bin/httpd -k start├─68981 /usr/local/apache/bin/httpd -k start└─68982 /usr/local/apache/bin/httpd -k startAug 02 21:07:42 localhost.localdomain systemd[1]: Starting web server daemon...
Aug 02 21:07:42 localhost.localdomain apachectl[68974]: AH00558: httpd: Could not rel>
Aug 02 21:07:42 localhost.localdomain systemd[1]: Started web server daemon.
[root@localhost ~]# 

3.2 安装mysql

//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
配置过程略...
Complete!
[root@localhost ~]# //创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql 
uid=986(mysql) gid=982(mysql) groups=982(mysql)
[root@localhost ~]# //下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz//解压软件至/usr/local/
[root@localhost src]# ls
apr-1.7.0         apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
apr-1.7.0.tar.gz  debug                  kernels
apr-util-1.6.1    httpd-2.4.54           mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz[root@localhost src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ 
[root@localhost src]# ls /usr/local/
apache  apr-util  etc    include  lib64    mysql-5.7.38-linux-glibc2.12-x86_64  share
apr     bin       games  lib      libexec  sbin                                 src
[root@localhost local]# mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql #更改名字
[root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src#修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll /usr/local/mysql -d
drwxr-xr-x. 9 mysql mysql 129 Aug  2 21:22 /usr/local/mysql
[root@localhost local]# #添加环境变量
[root@localhost local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# vim /etc/man_db.conf 
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man
#---------------------------------------------------------
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh 
[root@localhost ~]# which mysql
/usr/local/mysql/bin/mysql
[root@localhost ~]# //建立数据存放目录
[root@localhost ~]# mkdir -p /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 Aug  2 21:33 /opt/data/
[root@localhost ~]# //初始化数据库
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-08-02T13:35:57.012249Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T13:35:58.235577Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T13:35:58.423485Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T13:35:58.509663Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0ac776a9-1268-11ed-bb60-000c29aeb0ec.
2022-08-02T13:35:58.516741Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T13:35:58.704242Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T13:35:58.704299Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T13:35:58.705310Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T13:35:58.773428Z 1 [Note] A temporary password is generated for root@localhost: (sgO)6r8K4d(
[root@localhost ~]# 
//请注意,这个命令的最后会生成一个临时密码,每个的密码不一样,此处密码是(sgO)6r8K4d(
#保存密码    
[root@localhost ~]# echo '(sgO)6r8K4d(' > pass
[root@localhost ~]# cat pass 
(sgO)6r8K4d(
[root@localhost ~]# #查看/etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]#
# include all files from the config directory
#
!includedir /etc/my.cnf.d#这个配置是mariadb无法使用卸载mariadb
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-devel-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64
mariadb-connector-c-config-3.1.11-2.el8_3.noarch
mariadb-connector-c-3.1.11-2.el8_3.x86_64
[root@localhost ~]# dnf -y remove mariadb*
[root@localhost ~]# rpm -qa | grep mariadb
#没有找到mariadb卸载成功//生成配置文件
[root@localhost ~]# vim /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//配置服务启动脚本
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld 
# overwritten by settings in the MySQL configuration files.
#添加如下配置
basedir=/usr/local/mysql 
datadir=/opt/data# Default value, in seconds, afterwhich the script should timeout waiting
# for server start. 
[root@localhost support-files]# chmod +x /etc/init.d/mysqld //启动mysql
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
. SUCCESS! 
[root@localhost ~]# ss -antl
State    Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0         128                   [::]:22                 [::]:*                
LISTEN   0         80                       *:3306                  *:*                
LISTEN   0         128                      *:80                    *:*                #设置开机自启
[root@localhost ~]# chkconfig --add mysqld 
[root@localhost ~]# chkconfig --list Note: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
#在2:on	3:on	4:on	5:on是开启的关闭防火墙    
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# vim /etc/selinux/config
[root@localhost ~]# setenforce 0//修改密码
//使用临时密码登录
#先安装这个软件,如果有疑问为什么要安装这个可以看问题和解决方法
[root@localhost ~]# dnf -y install ncurses-compat-libs     [root@localhost ~]# mysql -uroot -p'(sgO)6r8K4d('
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38Copyright (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> //设置新密码
mysql> set password = password('long123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> quit
Bye#测试修改的密码是否登录
[root@localhost ~]# mysql -uroot -plong123!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.38 MySQL Community Server (GPL)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> 

3.3 安装php

//下载php
[root@localhost ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
--2022-08-02 22:07:40--  https://www.php.net/distributions/php-7.4.30.tar.xz
....
[root@localhost ~]# ls
anaconda-ks.cfg  pass  php-7.4.30.tar.xz
[root@localhost ~]# sha256sum php-7.4.30.tar.xz 
ea72a34f32c67e79ac2da7dfe96177f3c451c3eefae5810ba13312ed398ba70d  php-7.4.30.tar.xz
#在官网php.net通过他提供的检测方式检测是否成功下载正确的PHP//安装依赖包
[root@localhost ~]# dnf -y install libxml2 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 php-mysqlnd
安装过程略....//编译安装php
[root@localhost ~]# tar xf php-7.4.30.tar.xz 
[root@localhost ~]# 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 \
--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
#因为版本不同出现的问题不同,如果有问题看问题和解决方法
#安装成功没有问题的演示如下
+--------------------------------------------------------------------+
| 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
[root@localhost php-7.4.30]# make install//安装后配置
[root@localhost php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.4.30]# source /etc/profile.d/php7.sh 
[root@localhost php-7.4.30]# which php
/usr/local/php7/bin/php
[root@localhost php-7.4.30]# php -v
PHP 7.4.30 (cli) (built: Aug  2 2022 23:06:55) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@localhost php-7.4.30]# //配置php-fpm
[root@localhost fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# chmod +x /etc/init.d/php-fpm 
[root@localhost fpm]# cd
[root@localhost ~]# service php-fpm status 
php-fpm is stopped
[root@localhost ~]# cd /usr/local/php7/etc/
[root@localhost etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ls
www.conf  www.conf.default
[root@localhost php-fpm.d]# service php-fpm start 
Starting php-fpm  done
[root@localhost php-fpm.d]# ss -anlt
State    Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0         128              127.0.0.1:9000            0.0.0.0:*                
LISTEN   0         128                   [::]:22                 [::]:*                
LISTEN   0         80                       *:3306                  *:*                
LISTEN   0         128                      *:80                    *:*                
[root@localhost php-fpm.d]# [root@localhost ~]# chkconfig --add php-fpm 
[root@localhost ~]# chkconfig --list Note: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@localhost ~]# 

出现的问题和解决方法

mysql为什么要安装dnf -y install ncurses-compat-libs的原因

[root@localhost ~]# mysql -uroot -p'(sgO)6r8K4d('
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# dnf provides libncurses.so.5
Last metadata expiration check: 0:55:43 ago on Tue 02 Aug 2022 09:02:01 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]
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : base
Matched from:
Provide    : libncurses.so.5
[root@localhost ~]# dnf -y install ncurses-compat-libs

编译安装php问题和解决方法

//编译安装php问题和解决方法
[root@localhost ~]# tar xf php-7.4.30.tar.xz 
[root@localhost ~]# 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
#因为版本不同出现的问题不同,本次操作出现的问题如下
checking for sqlite3 > 3.7.4... no
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:Package 'sqlite3', required by 'virtual:world', not foundConsider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.Alternatively, you may set the environment variables SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
#需要安装sqlite3
[root@localhost ~]# dnf list all | grep sqlite3
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]
#安装如下的这个包
libsqlite3x-devel.x86_64                                          20071018-26.el8                                        epel         
[root@localhost ~]# dnf -y install libsqlite3x-devel#安装后重新编译安装php,出现新的问题再重复以上的操作
Package 'oniguruma', required by 'virtual:world', not foundConsider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.#重新查找但没有我们需要的包,所以通过https://pkgs.org/网站下载
#搜索Oniguruma-devel,然后找到CentOS 8 Stream
[root@localhost ~]# dnf list all | grep oniguruma
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]
oniguruma.x86_64                                                  6.8.2-2.el8                                            @AppStream   
oniguruma.i686                                                    6.8.2-2.el8                                            AppStream    
[root@localhost ~]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
#通过这个命令安装,然后重新编译安装#注意出现这个没有错误就成功了
+--------------------------------------------------------------------+
| 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.configure: WARNING: unrecognized options: --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-zip
#但出现警告,把警告过滤
[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 (onlyfor 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]# 
#没有显示证明这个不需要[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]# #这有出现新的问题
[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#出现的新的问题
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not foundConsider 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.
See the pkg-config man page for more details.[root@localhost ~]# dnf list all | grep zip | grep lib
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]
bzip2-libs.i686                                                   1.0.6-26.el8                                           @base        
bzip2-libs.x86_64                                                 1.0.6-26.el8                                           @anaconda    
libzip.x86_64                                                     1.5.1-2.module_el8.2.0+313+b04d0a66                    AppStream    
libzip-devel.x86_64                                               1.5.1-2.module_el8.2.0+313+b04d0a66                    AppStream    
libzip-tools.x86_64                                               1.5.1-2.module_el8.2.0+313+b04d0a66                    AppStream    
zziplib.i686                                                      0.13.68-9.el8                                          AppStream    
zziplib.x86_64                                                    0.13.68-9.el8                                          AppStream    
zziplib-utils.x86_64                                              0.13.68-9.el8                                          AppStream    
[root@localhost ~]# dnf -y install libzip-devel
#安装后重新编译

http://chatgpt.dhexx.cn/article/YCSca4w6.shtml

相关文章

LAMP安装

目录 一、LAMP架构介绍 LAMP概述 (平台)Linux (前台)Apache (后台)MySQL (中间连接)PHP/Perl/Python LAMP各组件安装顺序 二、编译安装Apache httpd服务 1.关闭防火墙,将安装Apache所需软件包传到/opt目录下 2.安装环境依赖包 3.配置软件模块 4.编译及安…

LAMP源码编译安装之Apache

LAMP源码编译安装之Apache 一.LAMP的基本架构概述1.LAMP架构2.各组件的主要作用如下 二.编译安装Apache httpd服务1.关闭防火墙,将安装Apache所需软件包传到/opt目录下2.安装环境依赖包3.配置软件模块4.编译及安装5.优化配置文件路径6.添加httpd系统服务7.修改httpd…

LAMP-手动架构部署

1. lamp简介 有了前面学习的知识的铺垫,今天可以来学习下第一个常用的web架构了。 所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越…

搭建LAMP架构 (百分百成功)

1.LAMP的含义 2.各自含义的作用 3.搭建LAMP所需要的环境 4.安装步骤 LAMP的含义: L:代表的是Linux操作系统 A:代表的是httpd服务,对外提供的网站 M:代表的是网站后台所使用的mysql数据库服务 P:代表的是php语言 各自含义的作用: Linux就不…

LAMP环境搭建

前言 一、在虚拟机上安装Linux系统 二、安装Apache 1.下载好后,看了看版本,不是太老,就没有继续安装。 2.开启Apache服务 3.设置Apache开机启动服务 4.尝试一下是否启动了服务(访问虚拟机IP) 三、安装mysql 1.…

LAMP安装详细教程

准备: 一台CentOS 7 虚拟机 yum更新完毕! 打开终端 第一步:systemctl stop firewalld //关闭防火墙 第二步:systemctl disable firewalld //禁用防火墙 第三步:yum install httpd //下载apache systemctl sta…

backtracking及其应用

文章目录 应用场景N-QueensPermutationsPermutations II 参考资料 backtracking(回溯法)是一种算法,主要用来解决带限制条件的计算问题( CSP)。 特点如下: 和暴力匹配算法一样,会尝试所有的可能性。比暴力匹配算法好,会在尝试的过…

bt5 mysql字典,backtrack5下载

对于喜欢使用linux操作系统的盆友们来说,backtrack5将会是你们不错的选择,它完美支持Live CD和Live USB启动方式,可以让用户直接从移动介质启动该系统。有了BT5,您就不用担心网络无法进行访问,因为它可是拥有无线射频技…

BackTrack5使用3proxy实现内网穿透

本次实验使用BT5攻击机中的3proxy实现内网穿透实验。 实验机IP地址:192.168.113.140 首先使用搭建apache2服务,监听本地80端口 apache2服务搭建: 进入/etc/apache2中,确认apache2.conf的根目录。并确定ports.conf的监听端口为8…

backtracking及其应用2

文章目录 SubsetsSubsets II 接上文: backtracking及其应用 Subsets 链接:https://leetcode.com/problems/subsets/ 如果没有接触过backtracking,这道题的常规解法应该是位操作 func subsets(nums []int) [][]int {lth : len(nums)cnt : i…

Backtracking algorithm梳理

回溯法简介 注意下面这句话 由于回溯通常结果集都记录在回溯树的路径上,因此如果不进行撤销操作, 则可能在回溯后状态不正确导致结果有差异, 因此需要在递归到底部往上冒泡的时候进行撤销状态。 如果你每次递归的过程都拷贝了一份数据&#x…

ARM backtrace 实战分析

记录一下arm backtrace 分析过程 前言 嵌入式开发中,如果发生异常如内存访问越界等情况,有时会非常难debug到底是哪里出错,近来看了一下back trace回溯的功能及实现,在这里做个笔记。 backtrace就是回溯堆栈,简单的说就是可以列…

backtrack 5 r3

1.BT5默认用户名:root.密码:toor(公司是yeslabccies) 2.进入图形化界面命令:startx 3.更改密码:sudo passwd root 扫描工具 第一部分网络配置: 4.网络配置文件有两个: /etc/network/interfaces 和 /etc/resolv.conf 前一个存放网卡接口…

backtrack3安装使用教程

一、准备篇 1、一个有可破解无线信号的环境。如我在家随便搜索出来的信号。 2、带无线网卡的电脑一台(笔记本台式机均可,只要无线网卡兼容BT3),我用的是三星R467的上网本。  3、2G以上优盘一个(我用的是2G的&#x…

安装BackTrack5 R3

最近买了本《Python绝技》,里面的很多实例都是在BackTrack系统中运行的。初次接触BackTrack系统,才知道它是一套专业的计算机安全检测的Linux操作系统,内部集成了200多种安全检查工具。虽然现在BackTrack已经被Kali Linux所代替,不…

BackTrack5(BT5)各版本下载

BT5R3(最新版本)http://www.nigesb.com/backtrack-5-r3-released.html BT5R2 KDE版32位: http://ftp.halifax.rwth-aachen.de/backtrack/BT5R2-KDE-32.iso GNOME32位:http://ftp.halifax.rwth-aachen.de/backtrack/BT5R2-GNOME-32.iso BT5R1 KDE版32位…

小白使用backtrack5

在此先感谢飞飞老师录制的教学视频 在这几天的了解中知道了这样一个过程 linux–>Debian–>Ubuntu–>backtrack–>kali 可能理解有点片面,但是可以让我了解到linux系统是基础,而且linux的内核大部分都是用C写的,部分是汇编语言…

虚拟机安装BackTrack 5 的教程详解!

废话不多说,直接上教程!如在安装过程中有些步骤界面没显示,即直接下一步即可。 打开虚拟机,新建虚拟机 选择自定义安装 选择你的映像文件,点击下一步 这里要注意了,系统选择Linux,版本选择U…

struts2漏洞升级至2.5.30额外补充

由于部分老项目需要还在使用struts2框架,由于最新发布struts2漏洞,需要将其版本升级至struts2.5.30,同步还有其他依赖和配置需要调整,大概可参考这个文章: struts升级至2.5.26遇到的各种bug及解决方案_谷同学的博客-C…

linux struts2漏洞,Struts2漏洞分析,漏洞波及全系版本

Struts漏洞分析 Apache Struts团队已经发布了Struts 2.3.15.1安全更新版本。在Struts2.3.15.1版本之前,存在着严重的安全漏洞,如果现在一些比较大的网站是用JAVA做的,没有把版本升级,还用的是Strtus2.3.15.1版本之前的话&#xff…