lamp部署
lamp
一、lamp简介
lamp是一个常用的web架构。
所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
LAMP 是指Linux(操作系统)+ Apache (HTTP 服务器)+ MySQL(数据库)和 PHP(网络编程语言),一般用来建立 web 应用平台。 和 Java/J2EE 架构相比, LAMP 具有 Web 资源丰富、轻量、快速开发等特点;与微软的.NET 架构相比,LAMP具有通用、跨平台、高性能、低价格的优势。
类似的架构还有:
lamt lnmp lnmt lnamp lnamt lnnmp lnnmt
二、web服务器工作流程
web服务器的资源分为两种,静态资源和动态资源
- 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
- 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端
那么web服务器如何执行程序并将结果返回给客户端呢?下面通过一张图来说明一下web服务器如何处理客户端的请求
如上图所示
阶段①显示的是httpd服务器(即apache)和php服务器通过FastCGI协议进行通信,且php作为独立的服务进程运行
阶段②显示的是php程序和mysql数据库间通过mysql协议进行通信。php与mysql本没有什么联系,但是由Php语言写成的程序可以与mysql进行数据交互。同理perl和python写的程序也可以与mysql数据库进行交互
1.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.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方式来加载动态资源
3.web工作流程
通过上面的图说明一下web的工作流程:
- 客户端通过http协议请求web服务器资源
- web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
- 若是静态资源则直接从本地文件系统取之返回给客户端。
- 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
三、lamp平台构建
环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
centos8 | 192.168.118.136 | httpd-2.4 mysql-5.7 php php-mysql |
lamp平台软件安装次序:
httpd --> mysql --> php
注意:php要求httpd使用prefork MPM
1.编译安装httpd
配置阿里云yum源
安装链接:阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)
//备份或删除本地yum源,建议新建目录备份
[root@136 ~]# cd /etc/yum.repos.d/
[root@136 yum.repos.d]# ls
CentOS-Stream-AppStream.repo CentOS-Stream-Media.repo
CentOS-Stream-BaseOS.repo CentOS-Stream-NFV.repo
CentOS-Stream-Debuginfo.repo CentOS-Stream-PowerTools.repo
CentOS-Stream-Extras-common.repo CentOS-Stream-RealTime.repo
CentOS-Stream-Extras.repo CentOS-Stream-ResilientStorage.repo
CentOS-Stream-HighAvailability.repo CentOS-Stream-Sources.repo
[root@136 yum.repos.d]# rm -rf *
[root@136 yum.repos.d]# ls
//下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
[root@136 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 19:05:04-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.204.213, 119.96.204.212, 27.22.58.236, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.96.204.213|: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/Cen 100%[===================>] 2.44K --.-KB/s in 0s
2022-08-02 19:05:05 (36.9 MB/s) - '/etc/yum.repos.d/CentOS-Base.repo' saved [2495/2495]
[root@136 yum.repos.d]# ls
CentOS-Base.repo
//删除云相关的东西
[root@136 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
//安装 epel 配置包
[root@136 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
//将 repo 配置中的地址替换为阿里云镜像站地址,并查看
[root@136 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@136 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@136 yum.repos.d]# ls
CentOS-Base.repo epel-testing-modular.repo epel.repo
epel-modular.repo epel-testing.repo
[root@136 yum.repos.d]# cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux 8 - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
baseurl=https://mirrors.aliyun.com/epel/8/Everything/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-8&arch=$basearch&infra=$infra&content=$contentdir
//可以看见已经换成阿里云的源了
...省略
//删除缓存后生成缓存
[root@136 yum.repos.d]# cd
[root@136 ~]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
43 files removed
[root@136 ~]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com 120 kB/s | 3.9 kB 00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 82 kB/s | 1.5 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 224 kB/s | 4.3 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 34 kB/s | 4.7 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - 71 kB/s | 3.0 kB 00:00
Metadata cache created.
安装开发工具包,依赖包
[root@136 ~]# dnf -y install epel-release vim
[root@136 ~]# dnf groups mark install 'Development Tools'
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:03:17 ago on Tue Aug 2 19:30:47 2022.
Dependencies resolved.
=================================================================================
Package Architecture Version Repository Size
=================================================================================
Installing Groups:
Development Tools
Transaction Summary
=================================================================================
Is this ok [y/N]: y
Complete!
[root@136 ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make vim wget
创建apache用户
[root@136 ~]# useradd -r -M -s /sbin/nologin apache
下载apr以及apr-util和httpd
[root@136 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
--2022-08-02 19:44:41-- 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'
apr-1.7.0.tar.gz 100%[===================>] 1.04M 23.7KB/s in 43s
2022-08-02 19:45:25 (24.8 KB/s) - 'apr-1.7.0.tar.gz' saved [1093896/1093896]
[root@136 ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
--2022-08-02 19:46:10-- 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'
apr-util-1.6.1.tar.g 100%[===================>] 541.31K 19.8KB/s in 21s
2022-08-02 19:46:32 (25.8 KB/s) - 'apr-util-1.6.1.tar.gz' saved [554301/554301]
编译apr以及apr-util和httpd
apr
[root@136 ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
[root@136 ~]# tar xf apr-1.7.0.tar.gz
[root@136 ~]# tar xf apr-util-1.6.1.tar.gz
[root@136 ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.54.tar.gz
[root@136 ~]# cd apr-1.7.0/
[root@136 apr-1.7.0]# ls
CHANGES apr.dsp configure libapr.mak strings
CMakeLists.txt apr.dsw configure.in libapr.rc support
LICENSE apr.mak docs locks tables
Makefile.in apr.pc.in dso memory test
Makefile.win apr.spec emacs-mode misc threadproc
NOTICE atomic encoding mmap time
NWGNUmakefile build file_io network_io tools
README build-outputs.mk helpers passwd user
README.cmake build.conf include poll
apr-config.in buildconf libapr.dep random
apr.dep config.layout libapr.dsp shmem
[root@136 apr-1.7.0]# vim configure
//进入后搜索cfgfile
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行注释掉
[root@136 apr-1.7.0]# ./configure --prefix=/usr/local/apr //配置
...省略
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/apr.h
config.status: creating build/apr_rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating apr-1-config
config.status: creating apr.pc
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@136 apr-1.7.0]# make //编译
...省略
sed -e 's,^\(apr_build.*=\).*$,\1/usr/local/apr/build-1,' -e 's,^\(top_build.*=\).*$,\1/usr/local/apr/build-1,' < build/apr_rules.mk > build/apr_rules.out
make[1]: Leaving directory '/root/apr-1.7.0'
[root@136 apr-1.7.0]# make install //编译安装
...省略
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
apr-util
[root@136 apr-1.7.0]# cd ../apr-util-1.6.1/
[root@136 apr-util-1.6.1]# ls
CHANGES aprutil.dep configure.in libaprutil.mak
CMakeLists.txt aprutil.dsp crypto libaprutil.rc
LICENSE aprutil.dsw dbd memcache
Makefile.in aprutil.mak dbm misc
Makefile.win apu-config.in docs redis
NOTICE buckets encoding renames_pending
NWGNUmakefile build export_vars.sh.in strmatch
README build-outputs.mk hooks test
README.FREETDS build.conf include uri
README.cmake buildconf ldap xlate
apr-util.pc.in config.layout libaprutil.dep xml
apr-util.spec configure libaprutil.dsp
[root@136 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
...省略
configure: creating ./config.status
config.status: creating Makefile
config.status: creating export_vars.sh
config.status: creating build/pkg/pkginfo
config.status: creating apr-util.pc
config.status: creating apu-1-config
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@136 apr-util-1.6.1]# make
...省略
export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> aprutil.exp
sed 's,^\(location=\).*$,\1installed,' < apu-1-config > apu-config.out
make[1]: Leaving directory '/root/apr-util-1.6.1'
[root@136 apr-util-1.6.1]# make install
...省略
/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
//查看一下
[root@136 apr-util-1.6.1]# cd
[root@136 ~]# ls /usr/local/
apr apr-util bin etc games include lib lib64 libexec sbin share src
httpd
[root@136 ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.54.tar.gz
[root@136 ~]# tar xf httpd-2.4.54.tar.gz
[root@136 ~]# cd httpd-2.4.54/
[root@136 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
...省略
configure: summary of build options:
Server Version: 2.4.54
Install prefix: /usr/local/apache
C compiler: gcc
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@136 httpd-2.4.54]# make
...省略
make[1]: Leaving directory '/root/httpd-2.4.54'
[root@136 httpd-2.4.54]# make install
...省略
make[1]: Leaving directory '/root/httpd-2.4.54'
配置apeche环境变量
//让系统能找到apeche的命令
[root@136 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@136 ~]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
[root@136 ~]# source /etc/profile.d/httpd.sh
[root@136 ~]# which httpd
/usr/local/apache/bin/httpd
//给头文件做软连接
[root@136 ~]# ls /usr/local/apache/
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@136 ~]# ln -s /usr/local/apache/include/ /usr/include/apache
//man文件
[root@136 ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man //添加此行
配置启动方式
[root@136 ~]# cd /usr/lib/systemd/system
[root@136 system]# cp sshd.service httpd.service
[root@136 system]# vim httpd.service
[root@136 system]# cat 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@136 system]# cd
[root@136 ~]# systemctl daemon-reload
[root@136 ~]# systemctl start httpd //启动httpd
[root@136 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 [::]:514 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@136 ~]# systemctl enable httpd //开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
2.源码安装mysql
安装依赖包
可能前面有安装过,但为了以防万一再安装一次也没问题
[root@136 ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建用户
[root@136 ~]# useradd -r -M -s /sbin/nologin mysql
下载二进制格式的myhsql软件包
[root@136 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-08-02 20:32:25-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 23.2.135.207, 2600:140b:2:99c::2e31, 2600:140b:2:99d::2e31
Connecting to downloads.mysql.com (downloads.mysql.com)|23.2.135.207|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [following]
--2022-08-02 20:32:26-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.55.248.248
Connecting to cdn.mysql.com (cdn.mysql.com)|23.55.248.248|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 674830866 (644M) [application/x-tar-gz]
Saving to: 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz'
mysql-5.7.38-linux-g 100%[===================>] 643.57M 3.65MB/s in 2m 57s
2022-08-02 20:35:25 (3.63 MB/s) - 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866]
解压软件包并更改属主属组
[root@136 ~]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@136 ~]# cd /usr/local/
[root@136 local]# ls
apache bin include libexec share
apr etc lib mysql-5.7.38-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
[root@136 local]# mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql //改个名字方便查找
[root@136 local]# ls
apache apr-util etc include lib64 mysql share
apr bin games lib libexec sbin src
[root@136 local]# chown -R mysql.mysql mysql //更改属主属组
[root@136 local]# ll |grep mysql
drwxr-xr-x. 9 mysql mysql 129 Aug 2 20:43 mysql
配置头文件,库文件,帮助文档
[root@136 local]# cd mysql/
[root@136 mysql]# ls
LICENSE README bin docs include lib man share support-files
[root@136 mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql/ //头文件
[root@136 mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf//库文件
[root@136 mysql]# vim /etc/man_db.conf //帮助文档
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@136 mysql]# cd
[root@136 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@136 ~]# source /etc/profile.d/mysql.sh
[root@136 ~]# which mysql
/usr/local/mysql/bin/mysql
初始化数据
//建立数据存放目录
[root@136 ~]# mkdir /opt/data
[root@136 ~]# chown -R mysql.mysql /opt/data/
[root@136 ~]# mysqld --initialize --user mysql --datadir /opt/data/
2022-08-02T12:52:05.079921Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T12:52:05.210057Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T12:52:05.248192Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T12:52:05.260111Z 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: e93d78d2-1261-11ed-93ec-000c290801b6.
2022-08-02T12:52:05.260623Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T12:52:05.422628Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T12:52:05.422655Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T12:52:05.423083Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T12:52:05.487829Z 1 [Note] A temporary password is generated for root@localhost: pfV0x2C:i(#k
[root@136 ~]# echo 'pfV0x2C:i(#k' > mysqlpass //保存密码
//查询到还有mariadb的软件包,将他们卸载
[root@136 ~]# rpm -qa |grep mariadb
mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64
mariadb-connector-c-config-3.1.11-2.el8_3.noarch
mariadb-devel-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-connector-c-3.1.11-2.el8_3.x86_64
[root@136 ~]# dnf -y remove mariadb*
[root@136 ~]# vim /etc/my.cnf
[root@136 ~]# 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
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
配置启动脚本
[root@136 ~]# cp /usr/lib/systemd/system/sshd.service .
[root@136 ~]# mv sshd.service mysqld.service
[root@136 ~]# vim mysqld.service
[root@136 ~]# cat mysqld.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@136 ~]# mv mysqld.service /usr/lib/systemd/system/
[root@136 ~]# systemctl daemon-reload
//关闭防火墙和selinux
[root@136 ~]# systemctl stop firewalld
[root@136 ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@136 ~]# vim /etc/selinux/config
[root@136 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@136 ~]# setenforce 0
//
[root@136 ~]# systemctl start mysqld
[root@136 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 [::]:514 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@136 ~]# systemctl enable mysqld.service //开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
重启一下验证是否开机自启
[root@136 ~]# reboot
[root@136 ~]# 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 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
进入mysql,更改密码
[root@136 ~]# cat mysqlpass
pfV0x2C:i(#k
[root@136 ~]# mysql -uroot -p'pfV0x2C:i(#k'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//缺少libncurses.so.5相关的软件包,查询并下载就好
[root@136 ~]# dnf whatprovides libncurses.so.5
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 1:29:53 ago on Tue Aug 2 19:54:53 2022.
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo : base
Matched from:
Provide : libncurses.so.5
[root@136 ~]# dnf -y install ncurses-compat-libs
[root@136 ~]# mysql -uroot -p'pfV0x2C:i(#k'
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.38
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> exit
Bye
[root@136 ~]# mysql -uroot -p123456
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.源码安装php
下载php源码包
[root@136 ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
--2022-08-02 21:41:12-- https://www.php.net/distributions/php-7.4.30.tar.xz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10419136 (9.9M) [application/octet-stream]
Saving to: 'php-7.4.30.tar.xz'
php-7.4.30.tar.xz 100%[===================>] 9.94M 22.3KB/s in 8m 42s
2022-08-02 21:49:57 (19.5 KB/s) - 'php-7.4.30.tar.xz' saved [10419136/10419136]
[root@136 ~]# sha256sum php-7.4.30.tar.xz
ea72a34f32c67e79ac2da7dfe96177f3c451c3eefae5810ba13312ed398ba70d php-7.4.30.tar.xz
//可以看见与下图官方网站里的包sha256的特征码一样,也就是说包是完整的
安装依赖包
[root@136 ~]# 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@136 ~]# tar xf php-7.4.30.tar.xz
[root@136 ~]# cd php-7.4.30/
[root@136 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
[root@136 php-7.4.30]# make
编译过程省略
[root@136 php-7.4.30]# make install
安装过程省略
设置环境变量
[root@136 php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@136 php-7.4.30]# source /etc/profile.d/php7.sh
[root@136 php-7.4.30]# which php
/usr/local/php7/bin/php
配置php-fpm
[root@136 php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@136 php-7.4.30]# cd sapi/
[root@136 sapi]# ls
apache2handler cgi cli embed fpm litespeed phpdbg
[root@136 sapi]# cd fpm/
[root@136 fpm]# ls
CREDITS init.d.php-fpm php-fpm.conf status.html.in
LICENSE init.d.php-fpm.in php-fpm.conf.in tests
Makefile.frag php-fpm php-fpm.service www.conf
config.m4 php-fpm.8 php-fpm.service.in www.conf.in
fpm php-fpm.8.in status.html
[root@136 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@136 fpm]# chmod +x /etc/init.d/php-fpm
[root@136 ~]# cd /usr/local/php7/
[root@136 php7]# ls
bin etc include lib php sbin var
[root@136 php7]# cd etc/
[root@136 etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@136 etc]# cp php-fpm.conf.default php-fpm.conf
[root@136 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@136 etc]# cd php-fpm.d/
[root@136 php-fpm.d]# ls
www.conf.default
[root@136 php-fpm.d]# cp www.conf.default www.conf
//启动php,设置开机自启
[root@136 php-fpm.d]# service php-fpm start
Starting php-fpm done
[root@136 php-fpm.d]# 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 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
[root@136 php-fpm.d]# cd
[root@136 ~]# chkconfig --add php-fpm
[root@136 ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd 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]'.
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?