lamp服务管理

lamp

web服务器工作流程

在说lamp架构平台的搭建前,我们先来了解下什么是CGI,什么是FastCGI,什么是…

web服务器的资源分为两种,静态资源和动态资源

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

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

lamp平台构建

安装httpd

//下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Stream-AppStream.repo
CentOS-Stream-BaseOS.repo
CentOS-Stream-Debuginfo.repo
CentOS-Stream-Extras.repo
CentOS-Stream-HighAvailability.repo
CentOS-Stream-Media.repo
CentOS-Stream-PowerTools.repo
CentOS-Stream-RealTime.repo
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- 100  2495  100  2495    0     0  11550      0 --:--:-- --:--:-- --:--:-- 11550
[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

//下载新repo 到/etc/yum.repos.d/
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirror 451 kB/s | 4.6 MB     00:10    
CentOS-8.5.2111 - Extras - mirr  42 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - m 379 kB/s | 8.4 MB     00:22    
epel-release-latest-8.noarch.rp  63 kB/s |  24 kB     00:00    
Dependencies resolved.
================================================================
 Package         Arch      Version        Repository       Size
================================================================
Installing:
 epel-release    noarch    8-16.el8       @commandline     24 k

Transaction Summary
================================================================
Install  1 Package

Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                        1/1 
  Installing       : epel-release-8-16.el8.noarch           1/1 
  Running scriptlet: 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.

  Verifying        : epel-release-8-16.el8.noarch           1/1 
Installed products updated.

Installed:
  epel-release-8-16.el8.noarch                                  

Complete!
[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]# ls
CentOS-Base.repo   epel-testing-modular.repo  epel.repo
epel-modular.repo  epel-testing.repo
  
//清理缓存
[root@localhost ~]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
18 files removed
[root@localhost ~]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirror 666 kB/s | 4.6 MB     00:07    
CentOS-8.5.2111 - Extras - mirr 4.4 kB/s |  10 kB     00:02    
CentOS-8.5.2111 - AppStream - m 380 kB/s | 8.4 MB     00:22    
Extra Packages for Enterprise L 180 kB/s | 1.0 MB     00:05    
Extra Packages for Enterprise L 366 kB/s |  13 MB     00:35    
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]
Metadata cache created.

//安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools'
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:01:21 ago on Tue Aug  2 17:55:56 2022.
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]
Dependencies resolved.
================================================================
 Package       Architecture Version         Repository     Size
================================================================
Installing Groups:
 Development Tools
                                                               

Transaction Summary
================================================================

Is this ok [y/N]: y
Complete!

//创建apache服务的用户和组    
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

//安装依赖包
[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make vim wget
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:03:49 ago on Tue Aug  2 17:55:56 2022.
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]
Dependencies resolved.

................................

  pkgconf-pkg-config-1.4.2-1.el8.x86_64                         
  vim-common-2:8.0.1763-16.el8.x86_64                           
  vim-enhanced-2:8.0.1763-16.el8.x86_64                         
  vim-filesystem-2:8.0.1763-16.el8.noarch                       
  wget-1.19.5-10.el8.x86_64                                     
  zlib-devel-1.2.11-17.el8.x86_64                               

Complete!

//下载和安装apr以及apr-util
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
--2022-08-02 18:05:35--  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:4f9:3a:2c57::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.g 100%[=======>]   1.04M   280KB/s    in 3.8s    

2022-08-02 18:05:40 (280 KB/s) - 'apr-1.7.0.tar.gz' saved [1093896/1093896]

--2022-08-02 18:05:40--  https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
Reusing existing connection to downloads.apache.org:443.
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. 100%[=======>] 541.31K   297KB/s    in 1.8s    

2022-08-02 18:05:42 (297 KB/s) - 'apr-util-1.6.1.tar.gz' saved [554301/554301]

FINISHED --2022-08-02 18:05:42--
Total wall clock time: 7.0s
Downloaded: 2 files, 1.6M in 5.6s (285 KB/s)


[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz
[root@localhost ~]# tar xf apr-1.7.0.tar.gz 
[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# 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
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# ls
CHANGES         apr.mak           emacs-mode  network_io
CMakeLists.txt  apr.pc.in         encoding    passwd
LICENSE         apr.spec          file_io     poll
Makefile.in     atomic            helpers     random
Makefile.win    build             include     shmem
NOTICE          build-outputs.mk  libapr.dep  strings
NWGNUmakefile   build.conf        libapr.dsp  support
README          buildconf         libapr.mak  tables
README.cmake    config.layout     libapr.rc   test
apr-config.in   configure         locks       threadproc
apr.dep         configure.in      memory      time
apr.dsp         docs              misc        tools
apr.dsw         dso               mmap        user
[root@localhost apr-1.7.0]# vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#    $RM "$cfgfile"                //将此行加上注释

[root@localhost apr-1.7.0]# ./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.7.0
checking for chosen layout... apr
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
................................................

[root@localhost apr-1.7.0]# make && make install
make[1]: Entering directory '/root/apr-1.7.0'
/bin/sh /root/apr-1.7.0/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/root/apr-1.7.0/include/arch/unix -I./include/arch/unix -I/root/apr-1.7.0/include/arch/unix -I/root/apr-1.7.0/include -I/root/apr-1.7.0/include/private -I/root/apr-1.7.0/include/private  -o encoding/apr_encode.lo -c encoding/apr_encode.c && touch encoding/apr_encode.lo
/root/apr-1.7.0/build/mkdir.sh tools
......................................


[root@localhost apr-1.7.0]# cd ../apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ls
CHANGES         apu-config.in      include
CMakeLists.txt  buckets            ldap
LICENSE         build              libaprutil.dep
Makefile.in     build-outputs.mk   libaprutil.dsp
Makefile.win    build.conf         libaprutil.mak
NOTICE          buildconf          libaprutil.rc
NWGNUmakefile   config.layout      memcache
README          configure          misc
README.FREETDS  configure.in       redis
README.cmake    crypto             renames_pending
apr-util.pc.in  dbd                strmatch
apr-util.spec   dbm                test
aprutil.dep     docs               uri
aprutil.dsp     encoding           xlate
aprutil.dsw     export_vars.sh.in  xml
aprutil.mak     hooks
[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
APR-util Version: 1.6.1
checking for chosen layout... apr-util
checking for gcc... gcc
checking whether the C compiler works... yes
.............................

[root@localhost apr-util-1.6.1]# make && make install
make[1]: Entering directory '/root/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I/root/apr-util-1.6.1/include -I/root/apr-util-1.6.1/include/private  -I/usr/local/apr/include/apr-1    -o buckets/apr_brigade.lo -c buckets/apr_brigade.c && touch buckets/apr_brigade.lo
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I/root/apr-util-1.6.1/include -I/root/apr-util-1.6.1/include/private  -I/usr/local/apr/include/apr-1    -o buckets/apr_buckets.lo -c buckets/apr_buckets.c && touch buckets/apr_buckets.lo
..........................................


//编译安装httpd
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
--2022-08-02 18:19:46--  https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/x-gzip]
Saving to: 'httpd-2.4.54.tar.gz.1'

httpd-2.4.54.ta 100%[=======>]   9.29M   275KB/s    in 66s     

2022-08-02 18:20:53 (143 KB/s) - 'httpd-2.4.54.tar.gz.1' saved [9743277/9743277]

[root@localhost ~]# 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@localhost ~]# tar xf httpd-2.4.54.tar.gz 
[root@localhost ~]# 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 
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/gre
p
checking for egrep... /usr/bin/grep -E
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
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to " -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
.........................................

[root@localhost httpd-2.4.54]# make && make install
................................

mkdir /usr/local/apache/icons
mkdir /usr/local/apache/logs
Installing CGIs
mkdir /usr/local/apache/cgi-bin
Installing header files
mkdir /usr/local/apache/include
Installing build system files
mkdir /usr/local/apache/build
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory '/root/httpd-2.4.54'


//安装后配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[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
[root@localhost ~]# 
[root@localhost ~]# ls /usr/local/apache/
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost ~]# ln -s /usr/local/apache/include /usr/include/apache
[root@localhost ~]# 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@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 daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disable>
   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                *:80              *:*            
LISTEN 0      128             [::]:22           [::]:*            
[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 daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled>
   Active: active (running) since Tue 2022-08-02 18:51:32 CST; 56>
     Docs: man:httpd(5)
 Main PID: 165120 (httpd)
    Tasks: 6 (limit: 12221)
   Memory: 4.7M
   CGroup: /system.slice/httpd.service
           ├─165120 /usr/local/apache/bin/httpd -k start
           ├─165121 /usr/local/apache/bin/httpd -k start
           ├─165122 /usr/local/apache/bin/httpd -k start
           ├─165123 /usr/local/apache/bin/httpd -k start
           ├─165124 /usr/local/apache/bin/httpd -k start
           └─165125 /usr/local/apache/bin/httpd -k start

Aug 02 18:51:32 localhost.localdomain systemd[1]: Starting web se>
Aug 02 18:51:32 localhost.localdomain apachectl[165117]: AH00558:>
Aug 02 18:51:32 localhost.localdomain systemd[1]: Started web ser>

安装mysql

//安装依赖包
[root@localhost ~]# cd /usr/src/
[root@localhost ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:59:23 ago on Tue Aug  2 17:55:56 2022.
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 openssl-devel-1:1.1.1k-5.el8_5.x86_64 is already installed.
Package openssl-1:1.1.1k-5.el8_5.x86_64 is already installed.
Dependencies resolved.
==================================================================
 Package              Arch   Version              Repo       Size

//创建用户和组
 [root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

 //下载二进制格式的mysql软件包
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-08-02 19:01:47--  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:1404:dc00:2a1::2e31, 2600:1404:dc00:296::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 19:01:48--  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.206.124.230
Connecting to cdn.mysql.com (cdn.mysql.com)|23.206.124.230|: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-lin 100%[========>] 643.57M  2.15MB/s    in 7m 21s                                                    ]  46.64M  1.01MB/s    eta 13m 25s

2022-08-02 19:09:11 (1.46 MB/s) - 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866] 
 
//解压软件至/usr/local/
[root@localhost src]# ls
debug  kernels  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]# cd
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.22-linux-glibc2.12-x86_64/'
[root@localhost local]# ll
total 0
drwxr-xr-x. 14 root root 164 Aug  2 18:37 apache
drwxr-xr-x.  6 root root  58 Aug  2 18:13 apr
drwxr-xr-x.  5 root root  43 Aug  2 18:16 apr-util
drwxr-xr-x.  2 root root   6 May 19  2020 bin
drwxr-xr-x.  2 root root   6 May 19  2020 etc
drwxr-xr-x.  2 root root   6 May 19  2020 games
drwxr-xr-x.  2 root root   6 May 19  2020 include
drwxr-xr-x.  2 root root   6 May 19  2020 lib
drwxr-xr-x.  3 root root  17 Jun 27 19:38 lib64
drwxr-xr-x.  2 root root   6 May 19  2020 libexec
lrwxrwxrwx.  1 root root  36 Aug  2 19:11 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 root root 129 Aug  2 19:11 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root root   6 May 19  2020 sbin
drwxr-xr-x.  5 root root  49 Jun 27 19:38 share
drwxr-xr-x.  2 root root   6 May 19  2020 src

//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll
total 0
drwxr-xr-x. 14 root  root  164 Aug  2 18:37 apache
drwxr-xr-x.  6 root  root   58 Aug  2 18:13 apr
drwxr-xr-x.  5 root  root   43 Aug  2 18:16 apr-util
drwxr-xr-x.  2 root  root    6 May 19  2020 bin
drwxr-xr-x.  2 root  root    6 May 19  2020 etc
drwxr-xr-x.  2 root  root    6 May 19  2020 games
drwxr-xr-x.  2 root  root    6 May 19  2020 include
drwxr-xr-x.  2 root  root    6 May 19  2020 lib
drwxr-xr-x.  3 root  root   17 Jun 27 19:38 lib64
drwxr-xr-x.  2 root  root    6 May 19  2020 libexec
lrwxrwxrwx.  1 mysql mysql  36 Aug  2 19:11 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 root  root  129 Aug  2 19:11 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root  root    6 May 19  2020 sbin
drwxr-xr-x.  5 root  root   49 Jun 27 19:38 share
drwxr-xr-x.  2 root  root    6 May 19  2020 src

[root@localhost local]# ls /usr/local/mysql/
LICENSE  bin   include  man    support-files
README   docs  lib      share
[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 
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 ~]# mkdir -p /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug  2 20:25 data

//初始化数据库
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-02T12:26:36.094822Z 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:26:36.232475Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T12:26:36.253937Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T12:26:36.307525Z 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: 59e9d26f-125e-11ed-8c19-000c296afe0a.
2022-08-02T12:26:36.308174Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T12:26:36.558632Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T12:26:36.558644Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T12:26:36.558920Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T12:26:36.651796Z 1 [Note] A temporary password is generated for root@localhost: ltOuw=1ywN0A
[root@localhost ~]# echo 'ltOuw=1ywN0A' > pass
[root@localhost ~]# cat pass
ltOuw=1ywN0A

//生成配置文件
[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
LICENSE  bin   include  man    support-files
README   docs  lib      share
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
magic  mysql-log-rotate  mysql.server  mysqld_multi.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld 
basedir=/usr/local/mysql    //添加
datadir=/opt/data
[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      80                 *:3306            *:*            
LISTEN 0      128                *:80              *:*            
LISTEN 0      128             [::]:22           [::]:*  
 
//开机自启    
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# 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]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
    
//修改密码
[root@localhost ~]# cat pass
ltOuw=1ywN0A
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
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> 
mysql> set password = password('jiang123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye

安装php

//下载php
[root@localhost ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
--2022-08-02 20:59:02--  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.x 100%[++++++++>]   9.94M  13.8KB/s    in 57s     

2022-08-02 21:12:58 (19.8 KB/s) - 'php-7.4.30.tar.xz' saved [10419136/10419136]

//安装依赖包
[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
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 1:45:08 ago on Tue Aug  2 19:30:35 2022.
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 libxml2-2.9.7-9.el8.x86_64 is already installed.
Package openssl-1:1.1.1k-5.el8_5.x86_64 is already installed.
Package openssl-devel-1:1.1.1k-5.el8_5.x86_64 is already installed
...............................................


//编译安装php
[root@localhost ~]# ls
anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.54.tar.gz
apr-1.7.0         apr-util-1.6.1.tar.gz  pass
apr-1.7.0.tar.gz  httpd-2.4.54           php-7.4.30.tar.xz
[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
.......................................
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
pharcommand.inc
invertedregexiterator.inc
directorytreeiterator.inc
directorygraphiterator.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

[root@localhost php-7.4.30]# make instal
make: *** No rule to make target 'instal'.  Stop.
[root@localhost php-7.4.30]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM defconfig:     /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
...........................................

//设置环境变量
[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 21:34:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

//配置php-fpm
[root@localhost php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-7.4.30]# cd sapi/
[root@localhost sapi]# ls
apache2handler  cgi  cli  embed  fpm  litespeed  phpdbg
[root@localhost sapi]# cd fpm/
[root@localhost fpm]# ls
CREDITS            php-fpm             status.html
LICENSE            php-fpm.8           status.html.in
Makefile.frag      php-fpm.8.in        tests
config.m4          php-fpm.conf        www.conf
fpm                php-fpm.conf.in     www.conf.in
init.d.php-fpm     php-fpm.service
init.d.php-fpm.in  php-fpm.service.in
[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 ~]# cd /usr/local/php7/
[root@localhost php7]# ls
bin  etc  include  lib  php  sbin  var
[root@localhost php7]# cd 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

//启动php-fpm
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@localhost php-fpm.d]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:Port Process 
LISTEN 0      128        127.0.0.1:9000      0.0.0.0:*            
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*            
LISTEN 0      80                 *:3306            *:*            
LISTEN 0      128                *:80              *:*            
LISTEN 0      128             [::]:22           [::]:*  

//设置开机自启
[root@localhost ~]# chkconfig --add php-fpm
[root@localhost ~]# 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]'.

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值