搭建lamp

  • 搭建lamp已关闭评论
  • 8 次浏览
  • A+
所属分类:linux技术
摘要

lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件
LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。


lamp


1. lamp简介

lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件
LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。

2. web服务器工作流程

web服务器的资源分为两种,静态资源和动态资源
静态资源:当我们获取它的时候,它里面的源的表现形式与原文件相同不会发生什么改变。
动态资源:程序文件,我们日常执行的命令在不同的主机里面执行出来的结果是不一样的
搭建lamp
当我们在客户端访问web服务器资源的时候,前端会把这个请求转发给应用服务器这里,然后应用服务器会到数据库里面进行查询并反馈给前端,前端再反馈给客户端

3. lamp平台构建

环境说明:

系统平台 IP 需要安装的服务
centos8 redhat8 192.168.222.250 httpd-2.4,mysql5.7,php,phpmysql

lamp平台软件安装次序:
httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

3.1 安装httpd

yum源的配置: [root@lnh ~]# cd /etc/yum.repos.d/ [root@lnh yum.repos.d]#rm -rf * [root@lnh yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo //在阿里云网站里面复制的仓库链接 [root@lnh yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo [root@lnh yum.repos.d]# ls CentOS-Base.repo [root@lnh yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm [root@lnh yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* [root@lnh yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* //安装epel源,也是在阿里云网站里面复制链接 [root@lnh yum.repos.d]# ls CentOS-Base.repo   epel.repo                  epel-testing.repo epel-modular.repo  epel-testing-modular.repo [root@lnh 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 enabled=1 gpgcheck=1 countme=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8  [epel-debuginfo] name=Extra Packages for Enterprise Linux 8 - $basearch - Debug # 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/debug #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-8&arch=$basearch&infra=$infra&content=$contentdir enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 gpgcheck=1  [epel-source] name=Extra Packages for Enterprise Linux 8 - $basearch - Source # It is much more secure to use the metalink, but if you wish to use a local mirror # place it's address here. baseurl=https://mirrors.aliyun.com/epel/8/Everything/source/tree/ #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-8&arch=$basearch&infra=$infra&content=$contentdir enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 gpgcheck=1 [root@lnh yum.repos.d]# dnf makecache //缓存一下 [root@lnh ~]# dnf groups mark install 'Development Tools' //安装开发工具包 Last metadata expiration check: 0:03:41 ago on Tue 02 Aug 2022 09:17:12 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] Dependencies resolved. ===================================================================================  Package            Architecture      Version             Repository          Size =================================================================================== Installing Groups:  Development Tools                                                                  Transaction Summary ===================================================================================  Is this ok [y/N]: y Complete! [root@lnh ~]# useradd -r -M -s /sbin/nologin  apache //创建用户的时候它会创建一个和用户名相同名字的组   //创建apache服务的用户和组 [root@lnh ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget vim make //安装依赖包 [root@lnh ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz //在https://downloads.apache.org/官网里面下载 [root@lnh ~]# ls anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz [root@lnh ~]# tar -xf apr-1.7.0.tar.gz  [root@lnh ~]# tar -xf apr-util-1.6.1.tar.gz  [root@lnh ~]# tar -xf httpd-2.4.54.tar.gz  [root@lnh ~]# ls anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz apr-1.7.0        apr-util-1.6.1    httpd-2.4.54 [root@lnh ~]# cd apr-1.7.0/ [root@lnh apr-1.7.0]# ls apr-config.in  build-outputs.mk  helpers       misc           strings apr.dep        CHANGES           include       mmap           support apr.dsp        CMakeLists.txt    libapr.dep    network_io     tables apr.dsw        config.layout     libapr.dsp    NOTICE         test apr.mak        configure         libapr.mak    NWGNUmakefile  threadproc apr.pc.in      configure.in      libapr.rc     passwd         time apr.spec       docs              LICENSE       poll           tools atomic         dso               locks         random         user build          emacs-mode        Makefile.in   README build.conf     encoding          Makefile.win  README.cmake buildconf      file_io           memory        shmem [root@lnh apr-1.7.0]# vim configure #    $RM "$cfgfile"    //删除或者注释掉这个 [root@lnh apr-1.7.0]# ./configure --prefix=/usr/local/apr ... 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@lnh apr-1.7.0]# make [root@lnh apr-1.7.0]# make install [root@lnh apr-1.7.0]# cd ../apr-util-1.6.1/ [root@lnh apr-util-1.6.1]# ls aprutil.dep       CHANGES            include         NWGNUmakefile aprutil.dsp       CMakeLists.txt     ldap            README aprutil.dsw       config.layout      libaprutil.dep  README.cmake aprutil.mak       configure          libaprutil.dsp  README.FREETDS apr-util.pc.in    configure.in       libaprutil.mak  redis apr-util.spec     crypto             libaprutil.rc   renames_pending apu-config.in     dbd                LICENSE         strmatch buckets           dbm                Makefile.in     test build             docs               Makefile.win    uri build.conf        encoding           memcache        xlate buildconf         export_vars.sh.in  misc            xml build-outputs.mk  hooks              NOTICE [root@lnh apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@lnh apr-util-1.6.1]# make [root@lnh apr-util-1.6.1]# make install [root@lnh ~]# ls /usr/local/ apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src [root@lnh ~]# cd httpd-2.4.54/ [root@lnh httpd-2.4.54]# ls ABOUT_APACHE     CHANGES          httpd.mak       Makefile.in       ROADMAP acinclude.m4     changes-entries  httpd.spec      Makefile.win      server Apache-apr2.dsw  CMakeLists.txt   include         modules           srclib Apache.dsw       config.layout    INSTALL         NOTICE            support apache_probes.d  configure        InstallBin.dsp  NWGNUmakefile     test ap.d             configure.in     LAYOUT          os                VERSIONING build            docs             libhttpd.dep    README BuildAll.dsp     emacs-style      libhttpd.dsp    README.CHANGES BuildBin.dsp     httpd.dep        libhttpd.mak    README.cmake buildconf        httpd.dsp        LICENSE         README.platforms [root@lnh 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.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@lnh httpd-2.4.54]# make [root@lnh httpd-2.4.54]# make install [root@lnh httpd-2.4.54]# cd [root@lnh ~]# ls anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz apr-1.7.0        apr-util-1.6.1    httpd-2.4.54 [root@lnh ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh   //配置环境变量 [root@lnh ~]# cat /etc/profile.d/httpd.sh  export PATH=/usr/local/apache/bin:$PATH [root@lnh ~]# ls /usr/local/ apache  apr-util  etc    include  lib64    sbin   src apr     bin       games  lib      libexec  share [root@lnh ~]# source /etc/profile.d/httpd.sh  [root@lnh ~]# which httpd  //查看路径 /usr/local/apache/bin/httpd [root@lnh ~]# ls /usr/local/apache/ bin    cgi-bin  error   icons    logs  manual build  conf     htdocs  include  man   modules [root@lnh ~]# ln -s /usr/local/apache/include /usr/include/apache //做一个头文件软链接 [root@lnh ~]# ll -d /usr/include/apache lrwxrwxrwx. 1 root root 25 Aug  2 22:37 /usr/include/apache -> /usr/local/apache/include [root@lnh ~]# 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@lnh ~]# cd /usr/lib/systemd/system [root@lnh system]# cp sshd.service httpd.service [root@lnh system]# vim httpd.service  [Unit] Description=httpd server daemon Documentation=man:httpd(5) After=network.target sshd-keygen.target  [Service] Type=forking ExecStart=/usr/local/apache/bin/apachectl start ExecStop=/usr/local/apache/bin/apachectl stop ExecReload=/bin/kill -HUP $MAINPID  [Install] WantedBy=multi-user.target [root@lnh system]# cd [root@lnh ~]# systemctl daemon-reload  [root@lnh ~]# systemctl enable --now httpd.service //设置开机自启 Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. [root@lnh ~]# 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@lnh ~]# systemctl status httpd.service  ● httpd.service - httpd server daemon    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: >    Active: active (running) since Tue 2022-08-02 22:49:17 CST; 30s ago      Docs: man:httpd(5)   Process: 49081 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, sta>  Main PID: 49084 (httpd)     Tasks: 6 (limit: 12221)    Memory: 5.7M    CGroup: /system.slice/httpd.service            ├─49084 /usr/local/apache/bin/httpd -k start            ├─49085 /usr/local/apache/bin/httpd -k start            ├─49086 /usr/local/apache/bin/httpd -k start            ├─49087 /usr/local/apache/bin/httpd -k start            ├─49088 /usr/local/apache/bin/httpd -k start            └─49089 /usr/local/apache/bin/httpd -k start  Aug 02 22:49:17 lnh systemd[1]: Starting httpd server daemon... Aug 02 22:49:17 lnh apachectl[49081]: AH00558: httpd: Could not reliably determine> Aug 02 22:49:17 lnh systemd[1]: Started httpd server daemon. 

3.2 安装mysql

[root@lnh ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel //安装依赖包 [root@lnh ~]# useradd -r -M -s /sbin/nologin mysql //创建用户和组 [root@lnh ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz //下载二进制格式的mysql软件包 [root@lnh ~]# ls anaconda-ks.cfg   apr-util-1.6.1.tar.gz apr-1.7.0         httpd-2.4.54 apr-1.7.0.tar.gz  httpd-2.4.54.tar.gz apr-util-1.6.1    mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [root@lnh ~]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@lnh ~]# cd /usr/local/ [root@lnh 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@lnh local]# mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql //也可以做软链接ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql [root@lnh local]# ls apache  apr-util  etc    include  lib64    mysql  share apr     bin       games  lib      libexec  sbin   src [root@lnh local]# chown -R mysql.mysql mysql  //修改目录/usr/local/mysql的属主属组 [root@lnh local]# ll total 0 drwxr-xr-x. 14 root  root  164 Aug  2 22:32 apache drwxr-xr-x.  6 root  root   58 Aug  2 22:17 apr drwxr-xr-x.  5 root  root   43 Aug  2 22:20 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 Jul 19 16:13 lib64 drwxr-xr-x.  2 root  root    6 May 19  2020 libexec drwxr-xr-x.  9 mysql mysql 129 Aug  2 23:21 mysql drwxr-xr-x.  2 root  root    6 May 19  2020 sbin drwxr-xr-x.  5 root  root   49 Jul 19 16:13 share drwxr-xr-x.  2 root  root    6 May 19  2020 src [root@lnh local]# ln -s /usr/local/mysql/include  /usr/include/mysql [root@lnh local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf [root@lnh 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@lnh local]# cd [root@lnh ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh //配置环境变量 [root@lnh ~]# source /etc/profile.d/mysql.sh  [root@lnh ~]# which mysql /usr/local/mysql/bin/mysql //查找mysql [root@lnh ~]# mkdir -p /opt/data [root@lnh ~]# chown -R mysql.mysql /opt/data/ //建立数据存放目录 [root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data //初始化数据库 2022-08-02T15:38:19.770486Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-08-02T15:38:19.958740Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-08-02T15:38:19.986757Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-08-02T15:38:19.992972Z 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: 22a4ea73-1279-11ed-a567-000c2905f428. 2022-08-02T15:38:19.995310Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-08-02T15:38:20.416458Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-08-02T15:38:20.416497Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-08-02T15:38:20.417285Z 0 [Warning] CA certificate ca.pem is self signed. 2022-08-02T15:38:20.478216Z 1 [Note] A temporary password is generated for root@localhost: iBUh*ijeb45h [root@lnh ~]# echo 'iBUh*ijeb45h' > password [root@lnh ~]# cat password  iBUh*ijeb45h //将临时密码保存到这个文件里面 [root@lnh ~]# rpm -qa |grep mariadb mariadb-connector-c-config-3.1.11-2.el8_3.noarch mariadb-connector-c-3.1.11-2.el8_3.x86_64 mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64 mariadb-devel-10.3.28-1.module_el8.3.0+757+d382997d.x86_64 //查找mariadb的数据库 [root@lnh ~]# dnf -y remove mariadb* //要卸载掉mariadb数据库不然到时候和mysql数据库发生冲突 [root@lnh ~]# rpm -qa |grep mariadb [root@lnh ~]# vim /etc/my.cnf [root@lnh ~]# 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 [root@lnh ~]# cd /usr/local/mysql/ [root@lnh mysql]# ls bin  docs  include  lib  LICENSE  man  README  share  support-files [root@lnh mysql]# cd support-files/ [root@lnh support-files]# ls magic  mysqld_multi.server  mysql-log-rotate  mysql.server [root@lnh support-files]# file mysql.server  mysql.server: POSIX shell script, ASCII text executable //是一个脚本文件 [root@lnh support-files]# cp mysql.server /etc/init.d/mysqld [root@lnh support-files]# vim /etc/init.d/mysqld  basedir=/usr/local/mysql    //数据库存放位置 datadir=/opt/data    //数据存放位置 [root@lnh support-files]# chmod +x /etc/init.d/mysqld  //赋予执行权限 [root@lnh ~]# service mysqld start   //启动服务 Starting MySQL.Logging to '/opt/data/lnh.err'.  SUCCESS!  [root@lnh ~]# 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@lnh ~]# chkconfig --add mysqld  //设置开机自启 [root@lnh ~]# 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 //在2,3,4,5下面开机自启了 [root@lnh ~]# systemctl stop firewalld.service  [root@lnh ~]# systemctl disable firewalld.service  Removed /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@lnh ~]# vim /etc/selinux/config  SELINUX=disabled [root@lnh ~]# setenforce 0 //关闭防火墙 [root@lnh ~]# cd /usr/lib/systemd/system [root@lnh system]# cp sshd.service mysqld.service [root@lnh system]# vim mysqld.service  [Unit] Description=mysqld server daemon Documentation=man:sshd(8) man:sshd_config(5) After=network.target sshd-keygen.target Wants=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@lnh system]# cd [root@lnh ~]# systemctl daemon-reload  //重新加载 [root@lnh ~]# systemctl restart mysqld.service //重启服务 [root@lnh ~]# 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@lnh ~]# cat password  iBUh*ijeb45h [root@lnh ~]# mysql -uroot -p'iBUh*ijeb45h' 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('lnh123'); //修改密码 Query OK, 0 rows affected, 1 warning (0.00 sec)  mysql> quit Bye [root@lnh ~]# mysql -uroot -p'lnh123' 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 3 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. //密码修改成功          

3.3 安装php

[root@lnh ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz //在网站php.net里面复制网址 [root@lnh ~]# ls anaconda-ks.cfg   apr-util-1.6.1.tar.gz                       password apr-1.7.0         httpd-2.4.54                                php-7.4.30.tar.xz apr-1.7.0.tar.gz  httpd-2.4.54.tar.gz apr-util-1.6.1    mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [root@lnh ~]# sha256sum php-7.4.30.tar.xz ea72a34f32c67e79ac2da7dfe96177f3c451c3eefae5810ba13312ed398ba70d  php-7.4.30.tar.xz //查看是否是要下载的包 [root@lnh ~]# dnf list |grep php|grep mysql 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] php-mysqlnd.x86_64                                                7.2.24-1.module_el8.2.0+313+b04d0a66                   @AppStream    //查看新的安装包 [root@lnh ~]# 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 //安装依赖包 [root@lnh ~]# ls anaconda-ks.cfg   apr-util-1.6.1.tar.gz                       password apr-1.7.0         httpd-2.4.54                                php-7.4.30.tar.xz apr-1.7.0.tar.gz  httpd-2.4.54.tar.gz apr-util-1.6.1    mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [root@lnh ~]# tar -xf php-7.4.30.tar.xz  //解压 [root@lnh ~]#cd php-7.4.30/ [root@lnh 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. //编译测试安装php [root@lnh php-7.4.30]# make //编译 [root@lnh php-7.4.30]# make install //安装 [root@lnh php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh //配置环境变量 [root@lnh php-7.4.30]# source /etc/profile.d/php7.sh  [root@lnh php-7.4.30]# which php    //查找php /usr/local/php7/bin/php [root@lnh php-7.4.30]# php -v     //查看版本号 PHP 7.4.30 (cli) (built: Aug  3 2022 01:17:12) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies [root@lnh php-7.4.30]# ls appveyor             configure.ac     Makefile.fragments   scripts azure                CONTRIBUTING.md  Makefile.objects     tests azure-pipelines.yml  docs             modules              travis build                ext              NEWS                 TSRM buildconf            EXTENSIONS       pear                 UPGRADING buildconf.bat        include          php.ini-development  UPGRADING.INTERNALS CODING_STANDARDS.md  libs             php.ini-production   win32 config.log           libtool          README.md            Zend config.nice          LICENSE          README.REDIST.BINS config.status        main             run-tests.php configure            Makefile         sapi [root@lnh php-7.4.30]# cp php.ini-production /etc/php.ini  cp: overwrite '/etc/php.ini'? y //配置生产环境 [root@lnh php-7.4.30]# ls appveyor             configure.ac     Makefile.fragments   scripts azure                CONTRIBUTING.md  Makefile.objects     tests azure-pipelines.yml  docs             modules              travis build                ext              NEWS                 TSRM buildconf            EXTENSIONS       pear                 UPGRADING buildconf.bat        include          php.ini-development  UPGRADING.INTERNALS CODING_STANDARDS.md  libs             php.ini-production   win32 config.log           libtool          README.md            Zend config.nice          LICENSE          README.REDIST.BINS config.status        main             run-tests.php configure            Makefile         sapi [root@lnh php-7.4.30]# cd sapi/ [root@lnh sapi]# ls apache2handler  cgi  cli  embed  fpm  litespeed  phpdbg [root@lnh sapi]# cd fpm/ [root@lnh fpm]# ls config.m4          LICENSE        php-fpm.conf        status.html.in CREDITS            Makefile.frag  php-fpm.conf.in     tests fpm                php-fpm        php-fpm.service     www.conf init.d.php-fpm     php-fpm.8      php-fpm.service.in  www.conf.in init.d.php-fpm.in  php-fpm.8.in   status.html [root@lnh fpm]# file init.d.php-fpm init.d.php-fpm: POSIX shell script, ASCII text executable [root@lnh fpm]# cp init.d.php-fpm /etc/init.d/php-fpm  //配置php-fpm [root@lnh fpm]# chmod +x /etc/init.d/php-fpm  //赋予执行权限 [root@lnh ~]# service php-fpm status  php-fpm is stopped //此时还没有正式启动 [root@lnh ~]# cd /usr/local/php7/ [root@lnh php7]# ls bin  etc  include  lib  php  sbin  var [root@lnh php7]# cd etc/ [root@lnh etc]# ls    //查看 pear.conf  php-fpm.conf.default  php-fpm.d [root@lnh etc]# cp php-fpm.conf.default php-fpm.conf [root@lnh etc]# ls   //查看复制后的文件 pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d [root@lnh etc]# cd php-fpm.d/ [root@lnh php-fpm.d]# ls www.conf.default [root@lnh php-fpm.d]# cp www.conf.default www.conf [root@lnh php-fpm.d]# ls   //查看复制后的文件 www.conf  www.conf.default [root@lnh php-fpm.d]# service php-fpm start  Starting php-fpm  done //开启服务 [root@lnh 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@lnh php-fpm.d]# cd  [root@lnh ~]# chkconfig --add php-fpm   //设置开机自启 [root@lnh ~]# 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 //可以看见2,3,4,5,是开机自启 [root@lnh ~]# ps -ef|grep php root      214276       1  0 01:53 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf) nobody    214277  214276  0 01:53 ?        00:00:00 php-fpm: pool www nobody    214278  214276  0 01:53 ?        00:00:00 php-fpm: pool www root      214325   51892  0 01:56 pts/0    00:00:00 grep --color=auto php //查看进程 

报错解决

报错1: [root@lnh ~]# mysql -uroot -p'iBUh*ijeb45h' mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory 解决: [root@lnh ~]# dnf provides libncurses.so.5 Last metadata expiration check: 0:14:32 ago on Tue 02 Aug 2022 11:53:43 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@lnh ~]# dnf -y install ncurses-compat-libs  报错2: configure: error: Package requirements (sqlite3 > 3.7.4) were not met:  Package 'sqlite3', required by 'virtual:world', not found 解决: root@lnh php-7.4.30]# dnf list |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.x86_64                                                20071018-26.el8                                        epel          libsqlite3x-devel.x86_64                                          20071018-26.el8                                        epel          preludedb-sqlite3.x86_64                                          5.2.0-1.el8                                            epel          rubygem-sqlite3.x86_64                                            1.4.2-2.el8                                            epel          rubygem-sqlite3-doc.noarch                                        1.4.2-2.el8                                            epel          soci-sqlite3.x86_64                                               4.0.0-2.el8                                            epel          soci-sqlite3-devel.x86_64                                         4.0.0-2.el8                                            epel          uwsgi-plugin-sqlite3.x86_64                                       2.0.20-1.el8                                           epel          zabbix-dbfiles-sqlite3.noarch                                     6.0.2-1.module_el8+14182+e1fc92db                      epel-modular  zabbix-proxy-sqlite3.x86_64                                       6.0.2-1.module_el8+14182+e1fc92db                      epel-modular  zabbix40-dbfiles-sqlite3.noarch                                   4.0.39-1.el8                                           epel          zabbix40-proxy-sqlite3.x86_64                                     4.0.39-1.el8                                           epel          //查找系统中的安装包,选择第二个 [root@lnh php-7.4.30]# dnf -y install libsqlite3x-devel  报错3: configure: error: Package requirements (oniguruma) were not met:  Package 'oniguruma', required by 'virtual:world', not found 解决: [root@lnh php-7.4.30]# 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.i686                                                    6.8.2-2.el8                                            AppStream     oniguruma.x86_64                                                  6.8.2-2.el8                                            AppStream     //在系统中查找的不是这个安装包 https://pkgs.org/ 在这个网站里面查找 oniguruma-devel [root@lnh php-7.4.30]# 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  报错4: configure: WARNING: unrecognized options: --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-zip 解决: [root@lnh php-7.4.30]# ./configure --help|grep gd   --with-gdbm[=DIR]       DBA: GDBM support   --enable-gd (新的)            Include GD support   --with-external-gd      Use external libgd   --with-webp             GD: Enable WEBP support (only for bundled libgd)   --with-jpeg             GD: Enable JPEG support (only for bundled libgd)   --with-xpm              GD: Enable XPM support (only for bundled libgd)                           libgd)   --enable-gd-jis-conv    GD: Enable JIS-mapped Japanese font support (only                           for bundled libgd) [root@lnh php-7.4.30]# ./configure --help|grep jpeg   --with-jpeg             GD: Enable JPEG support (only for bundled libgd) [root@lnh php-7.4.30]# ./configure --help|grep png [root@lnh php-7.4.30]#  [root@lnh php-7.4.30]# ./configure --help|grep freetype   --with-freetype         GD: Enable FreeType 2 support (only for bundled [root@lnh php-7.4.30]# ./configure --help|grep zip   --with-zip              Include Zip read/write support 报错5: configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:  Package 'libzip', required by 'virtual:world', not found Package 'libzip', required by 'virtual:world', not found Package 'libzip', required by 'virtual:world', not found 解决: [root@lnh ~]# 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@lnh ~]# dnf -y install libzip-devel