• LAMP--实战部署步骤--httpd-2.4--mysql-5.7--php8


    环境准备:

    系统平台	IP	
    centos7		192.168.8.164	
    
    需要安装的服务:
    httpd-2.4
    mysql-5.7
    php8
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    1、安装Apache

    1、依赖包

    安装依赖包:
    yum install -y expat-devel
    yum install -y gcc gcc-c++
    yum -y install openssl-devel libtool make
    
    • 1
    • 2
    • 3
    • 4

    2、安装epel包

    yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    yum clean all    //清理缓存
    yum makecache  	 //重新建立缓存
    yum groupinstall -y "Development Tools" // 安装开发工具包
    yum groups mark install -y "Development Tools"
    
    • 1
    • 2
    • 3
    • 4
    • 5

    /3、创建配置apache用户与组,添加附属组及用户

    useradd -r -M -s /sbin/nologin apache
    
    • 1

    4、下载并解压

    1.下载
    wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.54.tar.gz
    wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz
    wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
    wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
    
    2.解压缩:
    tar -xvf httpd-2.4.54.tar.gz -C /usr/local/src/
    tar -xvf apr-1.7.0.tar.gz -C /usr/local/src/
    tar -xvf apr-util-1.6.1.tar.gz -C /usr/local/src/
    tar -xvf pcre-8.33.tar.gz -C /usr/local/src/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    5、编译安装apr,注释掉R M " RM “RM"cfgfile”,避免发生未知错误

    cd /usr/local/src/apr-1.7.0
    sed -i 's/$RM "$cfgfile"/# $RM "$cfgfile"/g' ./configure
    ./configure --prefix=/usr/local/apr
    make && make install
    
    • 1
    • 2
    • 3
    • 4

    6、编译安装apr-util

    cd /usr/local/src/apr-util-1.6.1
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
    make && make install
    
    
    • 1
    • 2
    • 3
    • 4

    7、编译安装pcre-8.33

    cd /usr/local/src/pcre-8.33/
    ./configure  --prefix=/usr/local/pcre
    make && make install
    
    
    • 1
    • 2
    • 3
    • 4

    8、编译安装httpd-2.4.54

    cd /usr/local/src/httpd-2.4.54/
    ./configure --prefix=/usr/local/apache \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre=/usr/local/pcre \
    --with-apr=/usr/local/apr/ \
    --with-apr-util=/usr/local/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork
    
    make -j 2 && make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    1.安装报错1
    报错1:apr-util-1.6.1 报错xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
    原因:缺少expat库
    解决:yum install expat-devel -y
    
    1.安装报错2
    报错2:pcre-8.33 报错configure: error: You need a C++ compiler for C++ support.
    原因:缺少c++环境
    解决:yum install -y gcc gcc-c++
    
    报错3:
    [root@szb conf]# systemctl restart httpd
    Process 23436 (httpd) of user 0 killed by SIGSEGV - dumping core
    原因:因为升级php7.4版本,配置中LoadModule php5_module modules/libphp5.so注释掉
    解决:添加LoadModule php7_module modules/libphp7.so即可
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    1. 安装后配置修改
    1.添加环境变量
    echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
    source /etc/profile.d/httpd.sh
    
    2.添加头文件默认的软连接
    ln -s /usr/local/apache/include/ /usr/include/httpd
    
    3.添加man帮助文件数据--可以使用 man 来查询该软件的在线文件
    (默认情况下man 会去搜寻 /usr/local/man (/usr/local/share/man)下面的说明文件)
    vim /etc/man_db.conf
    MANPATH_MAP     /usr/local/sbin         /usr/local/apache/man
    
    4.取消注释,使用服务器主机名
    vim /usr/local/apache/conf/httpd.conf  // 服务器用于辨识自己的主机名和端口号,主要用于创建重定向URL
    ServerName www.example.com:80
    
    5、启动apache服务及校验端口
    [root@szb include]# apachectl start
    [root@szb include]# ss -ntl
    State       Recv-Q Send-Q       Local Address:Port        Peer Address:Port
    LISTEN      0      128                  :::80             :::*
    
    6.配置开机自启动
    cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/httpd.service
    vim /usr/lib/systemd/system/httpd.service
    [Unit]
    Description=httpd server daemon
    Documentation=man:httpd(8)
    After=network.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
    
    systemctl daemon-reload
    systemctl enable --now httpd
    systemctl status httpd.service	# 校验状态
    结果:Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    2、安装Mysql

    1.安装依赖包

    yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
    
    • 1

    2.下载安装包 - - mysql-5.7.34
    MySQL官网下载地址

    wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-el7-x86_64.tar.gz
    tar -xvf mysql-5.7.34-el7-x86_64.tar.gz -C /usr/local/ && cd /usr/local/
    mv mysql-5.7.34-el7-x86_64/ mysql
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    3.创建用户和组

    useradd -r -M -s /sbin/nologin mysql
    
    • 1

    4.添加环境变量

    echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
    source /etc/profile.d/mysql.sh
    vim /etc/man_db.conf
    MANPATH_MAP     /usr/local/sbin         /usr/local/mysql/man
    ln -s /usr/local/mysql/include/ /usr/include/mysql
    
    • 1
    • 2
    • 3
    • 4
    • 5
    1. 写一个配置文件,告诉库文件lib在/usr/local/mysql下面
    vim /etc/ld.so.conf.d/mysql.conf
    /usr/local/mysql/lib
    ldconfig
    
    • 1
    • 2
    • 3

    6.创建数据存放目录

    mkdir -p /data/mysql && chown -R mysql.mysql /data/mysql
    
    • 1
    1. 初始化数据库
    /usr/local/mysql/bin/mysqld --initialize-insecure --user mysql --datadir /data/mysql
    
    • 1

    8.修改配置文件

    vim /etc/my.cnf
    [mysqld]
    datadir=/data/mysql
    socket=/data/mysql/mysql.sock
    basedir=/usr/local/mysql
    port=3306
    symbolic-links=0
    user=mysql
    skip-name-resolve   # 禁止域名解析,
    
    [mysqld_safe]
    log-error=/data/mysql/mysql.log		# 此路径必须存在,不然会报错
    pid-file=/data/mysql/mysql.pid
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    skip-name-resolve理解

    9.配置服务启动脚本

    1.修改服务配置信息
    vim /usr/local/mysql/support-files/mysql.server
    basedir=/usr/local/mysql
    datadir=/data/mysql
    
    2.开启自启动服务
    cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/mysqld.service
    vim /usr/lib/systemd/system/mysqld.service
    [Unit]
    Description=mysql server daemon
    After=network.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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    10.启动mysql服务

    systemctl daemon-reload
    systemctl enable --now mysqld
    ln -s /data/mysql/mysql.sock /tmp/mysql.sock
    初始密码为空,登录:
    	mysql -uroot -p
    
    • 1
    • 2
    • 3
    • 4
    • 5

    3、安装PHP

    1、安装依赖包

    yum -y install php-mysqlnd libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel.x86_64 libcurl-devel libpng-devel libjpeg-devel libpng-devel openldap-devel freetype-devel gmp-devel readline-devel libxslt-devel mhash-devel
    
    yum -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
    
    • 1
    • 2
    • 3

    2、下载并解压缩

    1、依赖包:oniguruma-6.9.7
    wget https://github.com/kkos/oniguruma/archive/v6.9.7.tar.gz -O oniguruma-6.9.7.tar.gz
    tar -xvf oniguruma-6.9.4.tar.gz -C /usr/local/src
    
    3、依赖包:libzip-1.2.0
    yum remove libzip -y
    wget https://libzip.org/download/libzip-1.2.0.tar.gz --no-check-certificate
    tar -zxvf libzip-1.2.0.tar.gz
    
    4、php-8.0.22主程序
    wget https://www.php.net/distributions/php-8.0.22.tar.gz
    tar -xvf php-8.0.22.tar.gz -C /usr/local/src
    
    php7.4.30版本下载类似
    wget https://www.php.net/distributions/php-7.4.30.tar.gz
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    3、编译安装

    1、编译安装oniguruma
    yum install -y autoconf automake libtool libsqlite3x-devel
    cd /usr/local/src/oniguruma-6.9.7
    ./autogen.sh && ./configure --prefix=/usr --libdir=/lib64 
    需要有“--libdir=/lib64”参数,不然ldconfig找不到,php还是报错
    
    2、编译安装libzip
    cd /usr/local/src/libzip-1.2.0
    ./configure
    make && make install
    export PKG_CONFIG_PATH="/usr/lib/pkgconfig/"
    遇到报错6添加如下操作:
    cd /etc/ld.so.conf.d/
    vim libzip.conf
    /usr/local/src/libzip-1.2.0/lib
    ldconfig
    
    3、编译安装php
    cd /usr/local/src/php-8.0.22/ext/phar
    cp phar.php phar.phar
    cd /usr/local/src/php-8.0.22
    ./configure --prefix=/usr/local/php8 \
    --with-config-file-path=/etc \
    --with-openssl \
    --with-pdo-mysql=mysqlnd \
    --with-config-file-scan-dir=/etc/php.d \
    --with-freetype \
    --with-jpeg \
    --with-zlib-dir \
    --with-curl \
    --with-zip \
    --with-mysqli=mysqlnd \
    --enable-fpm \
    --enable-mysqlnd \
    --enable-mbstring \
    --enable-sockets \
    --disable-fileinfo \
    --disable-debug \
    --disable-rpath \
    --enable-shared \
    --enable-soap \
    --enable-bcmath \
    --with-iconv \
    --with-bz2 \
    --enable-calendar \
    --enable-exif  \
    --enable-ftp \
    --enable-gd \
    --with-gettext \
    --enable-pdo \
    --with-readline \
    --enable-shmop \
    --enable-simplexml \
    --with-pear \
    --enable-pcntl \
    --enable-posix
    
    make -j 2 && make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58

    在这里插入图片描述

    官方:核心配置选项列表

    php源码安装常用配置参数和说明

    4、安装后配置

    1、设置环境变量
    echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
    source /etc/profile.d/php.sh
    
    2、校验
    which php
    php -v
    
    3、配置文件
    1)配置php.ini
    cp -f /usr/local/src/php-8.0.22/php.ini-production /etc/php.ini    # 最重要的PHP配置文件
    
    2)配置php-fpm(php管理工具)
    	1>php-fpm启动脚本
    cp /usr/local/src/php-8.0.22/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc//init.d/php-fpm 
    	2>php-fpm配置文件
    cd /usr/local/php8/etc/
    cp php-fpm.conf.default php-fpm.conf
    cp php-fpm.d/www.conf.default php-fpm.d/www.conf
    
    
    4、配置启动服务php-fpm
    cp /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/php-fpm.service
    vim /usr/lib/systemd/system/php-fpm.service
    [Unit]
    Description=php server daemon
    After=network.target
     
    [Service]
    Type=forking
    ExecStart=/etc/init.d/php-fpm start
    ExecStop=/etc/init.d/php-fpm stop
    ExecReload=/bin/kill -HUP $MAINPID
     
    [Install]
    WantedBy=multi-user.target
    
    5、 开机自启动
    systemctl daemon-reload 
    systemctl enable --now php-fpm
    ss -ntla | grep 9000
    ps aux | grep php
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    报错

    报错1:源码编译 php 遇到缺失 No package sqlite3 found 问题
    原因:缺少依赖包
    解决:yum install -y sqlite-devel.x86_64
    
    
    报错2:源码编译 php 遇到缺失 No package 'libcurl' found 问题
    原因:缺少依赖包
    解决:yum install -y libcurl-devel
    
    报错3:源码编译 php 遇到缺失 No package 'libpng' found 问题
    原因:缺少依赖包
    解决:yum install -y libpng-devel
    
    报错4:
    No package 'oniguruma' found
    Consider adjusting the PKG_CONFIG_PATH environment variable if you
    installed software in a non-standard prefix.
    Alternatively, you may set the environment variables LIBZIP_CFLAGS
    and LIBZIP_LIBS to avoid the need to call pkg-config.
    See the pkg-config man page for more details.
    原因:已经安装,但是php还是会报错,ldconfig找不到
    解决办法:./configure --prefix=/usr --libdir=/lib64 
    需要有“--libdir=/lib64”参数,不然ldconfig找不到,php还是报错
    
    报错5:
    configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
    Requested 'libzip >= 0.11' but version of libzip is 0.10.1
    原因:libzip提示版本太低,yum自带的是0.10
    解决办法:
    yum remove libzip -y
    wget https://libzip.org/download/libzip-1.2.0.tar.gz --no-check-certificate
    tar -zxvf libzip-1.2.0.tar.gz
    cd libzip-1.2.0
    ./configure
    make && make install
    vim /etc/profile
    export PKG_CONFIG_PATH="/usr/lib/pkgconfig/"
    
    或者:
    rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm 
    yum —enablerepo=remi install libzip5-devel 
    
    报错6:
    error while loading shared libraries: libzip.so.5: cannot open shared object file: N
    原因:ld提示找不到库文件,而库文件就在当前目录中,链接器ld默认的目录是/lib和/usr/lib,如果放在其他路径也可以,需要让ld知道库文件在哪里。
    解决:
    cd /etc/ld.so.conf.d/
    vim libzip.conf
    /usr/local/src/libzip-1.2.0/lib
    ldconfig		# 更新/etc/ld.so.cache文件
    
    报错7:
    chmod: cannot access ‘ext/phar/phar.phar’: No such file or directory
    make: [ext/phar/phar.phar] Error 1 (ignored)
    原因:
    解决办法:
    cd /usr/local/src/php-8.0.22/ext/phar
    cp phar.php phar.phar
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59

    PKG_CONFIG_PATH错误提示解决办法

    以上三个软件就全部编译安装成功了,真的是php安装报错贼多,也贼耗时间

    4、配置apache

    1、FastCGI(动态应用相关的模块)的实现需要加载httpd2.4的两个模块
    mod_proxy_fcgi.so (mod_proxy.so拓展)
    mod_proxy.so

    vim /usr/local/apache/conf/httpd.conf			// 取消注释
    120 LoadModule proxy_module modules/mod_proxy.so
    124 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    
    • 1
    • 2
    • 3

    2、创建虚拟主机目录并生成php测试页面

    mkdir -p /usr/local/apache/htdocs/test
    cd /usr/local/apache/htdocs/test
    vim index.php
    <?php
        phpinfo();
    ?>
    chown -R apache.apache /usr/local/apache/htdocs/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3、修改配置文件

    1、添加默认匹配的主页面
    vim /usr/local/apache/conf/httpd.conf	
    <IfModule dir_module>
        DirectoryIndex index.html index.php			# 添加index.php
    </IfModule>
    
    2、搜索AddType,添加以下内容
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .php
    
    3、在配置文件的最后加入以下内容
    <VirtualHost *:80>
         DocumentRoot "/usr/local/apache/htdocs/test"
         ServerName www.test.com
         ProxyRequests Off
         ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
         <Directory "/usr/local/apache/htdocs/test">
             Options none
             AllowOverride none
             Require all granted
         </Directory>
    </VirtualHost>
    
    4、重启服务
    systemctl restart httpd
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    4、验证:
    本地游览器输入:http://192.168.8.164/

    在这里插入图片描述

    参考指导:LAMP架构源码部署(入门级别超详细步骤)

  • 相关阅读:
    [蓝桥杯-610]分数
    UE5数字孪生制作(一) - QGIS 学习笔记
    Linux零基础入门(二)Linux基础命令
    【Unity3D】正交视图与透视视图 ( 正交视图概念 | 透视视图概念 | 观察点 | 正交视图作用 | 摄像机广角设定 | 透视畸变效果 )
    Spark: 单词计数(Word Count)的MapReduce实现(Java/Python)
    软考高级系统架构设计师系列论文十六:论软件系统测试及其应用
    基于springboot消防员招录系统
    Hbase,Phoenix,hive,Redis 内存数据库,220905,,
    LSTM情感分类问题调试
    [CF Gym101196-I] Waif Until Dark 网络最大流
  • 原文地址:https://blog.csdn.net/szb521/article/details/126495807