Clannaddada

导航

lamp架构部署,通过lamp架构部署phpmyadmin项目

lamp架构部署phpmyadmin项目

Lamp架构介绍

LAMP架构介绍 LAMP架构包含了 Linux+Apache (httpd)+ MySQL +PHP ,简称LAMP,一般用来建立web应用平台

  • Linux是操作系统,比如centos,Ubuntu都是linux操作系统
  • Apache提供web服务软件,其真正名字为 httpd,习惯称之为Apache
  • MySQL存储软件,存的是数据、字符串,不是图片
  • PHP是脚本语言,和shell相似,但比shell复杂,PHP是由 C语言 开发的,通常用于做网站(主要)

LAMP 是指Linux(操作系统)+ Apache (HTTP 服务器)+ MySQL(数据库)和 PHP(网络编程语言),一般用来建立 web 应用平台。LAMP 具有 Web 资源丰富、轻量、快速开发等特点.

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的特征码一样,也就是说包是完整的

image

安装依赖包

[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

//编辑php-fpm配置文件
[root@136 ~]# vim /usr/local/php7/etc/php-fpm.conf
...省略
;  - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children =50        //添加下面四行,同事提供50个进程提供50个并发服务
pm.start_servers = 5       //启东市启动五个进程
pm.min_spare_servers = 2   //最小空闲数
pm.max_spare_servers = 8   //最大空闲进程

//取消httpd.conf的注释,启动httpd的相关模块
[root@136 ~]# vim /usr/local/apache/conf/httpd.conf  //搜索proxy,取消下面两行的注释
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

//编写测试文件
[root@136 ~]# mkdir -p /usr/local/apache/htdocs/runtime
[root@136 ~]# vim /usr/local/apache/htdocs/runtime/index.php
[root@136 ~]# cat /usr/local/apache/htdocs/runtime/index.php
<?php
   phpinfo();
?>
[root@136 ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@136 ~]# ll -d /usr/local/apache/htdocs/
drwxr-xr-x. 3 apache apache 39 Aug  4 08:20 /usr/local/apache/htdocs/

//配置虚拟主机
[root@136 ~]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
//先将原本存在的配置文件删除,在配置文件的最后加入以下内容
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName runtime.example.com
    ErrorLog "logs/runtime.example.com-error_log"
    CustomLog "logs/runtime.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/runtime/$1
    <Directory "/usr/local/apache/htdocs/runtime">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

//搜索AddType,添加以下内容
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php           //添加
    AddType application/x-httpd-php-source .phps   //添加

//搜索DirectoryIndex,在中间添加一个index.php
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

//搜索Include,找到下面此行将注释删除
#Include conf/extra/httpd-vhosts.conf

//重启php httpd
[root@136 ~]# service php-fpm restart 
[root@136 ~]# systemctl restart httpd
[root@136 ~]# ss -anlt
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            127.0.0.1:9000          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               [::]:*    

查看结果

image

lamp架构上部署phpmyadmin

先在数据库中创建一个用户并授权

[root@136 ~]# mysql -uroot -p123456
mysql> create database admin;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on admin.* to 'admin'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all on admin.* to 'admin'@'localhost' identified by '123456';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

下载phpmyadmin并解压配置

[root@136 ~]# wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.tar.gz
[root@136 ~]# tar xf phpMyAdmin-5.2.0-all-languages.tar.gz -C /usr/local/apache/htdocs/runtime/
[root@136 ~]# cd /usr/local/apache/htdocs/runtime/
[root@136 runtime]# ls
index.php  phpMyAdmin-5.2.0-all-languages
[root@136 runtime]# mv phpMyAdmin-5.2.0-all-languages/* .
mv: overwrite './index.php'? y
[root@136 runtime]# cp config.sample.inc.php config.inc.php
[root@136 runtime]# vim config.inc.php
$cfg['Servers'][$i]['host'] = '127.0.0.1';		//把localhost改成为127.0.0.1
[root@136 runtime]# systemctl restart httpd

查看结果

image

输入用户admin密码123456登入

image

posted on 2022-08-04 08:56  linux-ada  阅读(120)  评论(0编辑  收藏  举报