LAMP的源码编译安装

## LAMP源码编译安装

实验环境

lamp server:Centos7 192.168.10.121

client:Windows10 192.168.10.1

环境配置

  • 关闭防火墙

    image-20191104110926016

  • 关闭selinux

    image-20191104111004414

    image-20191104111021788

  • 源码包下载
    Mariadb-10.2

    Apache(HTTPD-2.4.33) download

    PHP-7.2.5 download

    wget http://archive.apache.org/dist/apr/apr-1.5.1.tar.gz
    wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
    wget http://archive.apache.org/dist/httpd/httpd-2.4.33.tar.gz
    wget http://mirrors.neusoft.edu.cn/mariadb/mariadb-10.2.14/source/mariadb-10.2.14.tar.gz
    wget http://us1.php.net/distributions/php-7.2.5.tar.bz2
    
  • 依赖包安装(需要连外网与配置yum环境)

    image-20191104112203359

    image-20191104112848333

    image-20191104112917774

    image-20191104141318476

    image-20191104141343468

    image-20191104163651808

    image-20191104163739331

    yum groups mark convert(groupinstall失败时执行该命令)
    yum groupinstall "Development Tools" -y #安装开发环境
    #中文的为:
    yum groupinstall 开发工具
    yum install cmake -y #mariadb所需依赖
    yum install ncurses-devel.x86_64 -y #mariadb所需依赖
    yum install pcre-devel #httpd所需依赖
    yum install openssl-devel #httpd所需依赖
    yum install libxml2-devel #php所需依赖
    yum install bzip2-devel #php所需依赖
    
  • 安装apr、apr-tuil

    image-20191104135507652

    image-20191104201509206

    image-20191104135733487

    image-20191104142058812

     tar xvf apr-1.5.1.tar.gz 
     cd ./apr-1.5.1/
     ./configure --prefix=/usr/local/apr && make && make install
    
     tar xvf apr-util-1.5.4.tar.gz 
     cd apr-util-1.5.4/
     ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
    #--prefix=
    

HTTPD安装

  • 解压并编译安装

    image-20191104141650444

    image-20191104141707586

    image-20191104142519614

    image-20191104142638963

    cd httpd-2.4.33/
    ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --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=event
    make && make install
        #--prefix=/usr/local/apache 指明编译安装的路径
        #--sysconfdir=/etc/httpd24 指明配置文件的路径
        #--enable-so 支持动态装载卸载模块
        #--enable-ssl 支持https通信
        #--enable-cgi 支持cgi协议
        #--enable-rewrite 支持url重写
        #--with-zlib 支持数据压缩
        #--with-pcre 兼容正则表达式
        #--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util 指明apr和apr-util路径
        #--enable-modules=most 支持大多数模块
        #--enable-mpms-shared=all 支持全部的工作模型
        #--with-mpm=event 默认工作模式为event(prefork)
    
    
    
  • 设置服务名并启用httpd的dflate和rewrite

    image-20191104151742934

    image-20191104151656059

    image-20191104151856423

    image-20191104151930321

  • 修改环境变量添加httpd路径

    image-20191104152205177

    image-20191104152141279

    image-20191104152255054

  • 启动服务并测试

    image-20191104152322383

  • 更改httpd运行用户

    image-20191104152449789

Mariadb安装

  • 解压并使用cmake编译安装

    image-20191104152658100

    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DPLUGIN_TOKUDB=NO
    make && make install 
    # 注: 
        #-DCMAKE_INSTALL_PREFIX=/usr/local/mysql mysql主程序安装目录 
        #-DSYSCONFDIR=/etc 配置文件目录 
        # -DDEFAULT_CHARSET=utf8 默认字符集为utf8 
        #-DDEFAULT_COLLATION=utf8_general_ci 默认的字符集效对规则 
        #-DWITH_EXTRA_CHARSETS=all  安装所有字符集
    
    
  • 添加mariadb运行用户

    image-20191104155819700

  • 使用提供的模板配置文件设置mariadb配置并进行配置

    image-20191104160003348

    image-20191104160457544

    datadir = /mydata #指定数据库路径
    innodb_file_per_table = on #设置后当创建数据库的表的时候表文件都会分离开,方便复制表
    skip_name_resolve = on #跳过名称反解
    
    
  • 复制启动脚本并进行设置

    image-20191104160142926

  • 将Mariadb加入环境变量

    image-20191104160727691

    image-20191104160711747

  • 初始化数据库

    image-20191104161438104

  • 启动数据库

    image-20191104161748788

    注:未给启动脚本赋予执行权限,所以无法执行

    image-20191104161838096

  • 安全初始化

    image-20191104162200226

    image-20191104162519219

  • 配置mysql

    image-20191104165403274

    image-20191104165556931

  • 重启mariadb服务

    image-20191104165646916

编译安装PHP

  • 解压并编译安装

    image-20191104163838696

    image-20191104164023530

    image-20191104164047350

    cd php-7.2.5/
    ./configure --prefix=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
    make && make install
    
    
  • 使用模板设置配置文件

    image-20191104164847011

  • 修改httpd配置文件关联php

    image-20191104165049409

    image-20191104165030787

    image-20191104165144646

  • 重启httpd服务

    image-20191104165300023

测试

  • 编写测试网页

    image-20191104171016524

    image-20191104170711843

    image-20191104171247182

    <?php
        phpinfo();
    ?>
    
    <?php
        $link = mysqli_connect('192.168.10.121','root','12345');
        if ($link)
            echo "Success...";
        else
             echo "Failure...";
        mysql_close();
    ?>
    
    
    
  • 重启httpd服务

    image-20191104170128528

  • 客户机访问测试

    image-20191104171043040

    image-20191104171310294

Discuz部署

  • 下载
    官方论坛
    下载地址
    注:下载时注意版本(部分版本不支持php7.0及以上)

  • 上传服务器并解压

    image-20191104184255985

    image-20191104185024045

  • 为discuz创建数据库并设置用户密码

    image-20191104190104847

    mysql -uroot -p
    create database discuzdb;
    grant all on discuzdb.* to 'disuser'@'%' identified by '12345';
    flush privileges;
    quit
    
    
    
  • 更改权限并重启

    image-20191104185658567

    image-20191104185603548

  • 安装

    image-20191104185353250

    image-20191104190311195

    image-20191104190347629

    image-20191104190414582

GD库安装

  • 解压并安装依赖包

    image-20191104194115845

    image-20191104193549593

    image-20191104194059947

    image-20191104193902227

    image-20191104194038732

    image-20191104194252980

    tar xvf freetype-2.4.8.tar.bz2
    cd freetype-2.4.8/
    ./configure --prefix=/usr/local/freetype && make && make install
    
    tar xvf jpegsrc.v9.tar.gz
    cd jpeg-9/
    CFLAGS="-O3 -fPIC"
    ./configure --prefix=/usr/local/jpeg && make && make install
    
    tar xvf libpng-1.2.56.tar.gz
    CFLAGS="-O3 -fPIC" 
    ./configure --prefix=/usr/local/libpng && make && make install
    
    
  • 进入php源码包路径下添加编译gd模块

    image-20191104194512184

    image-20191104194750796

    image-20191104194818252

    cd /root/php-7.2.5/ext/gd
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config  --with-jpeg-dir=/usr/local/jpeg  --with-png-dir=/usr/local/libpng  --with-freetype-dir=/usr/local/freetype
    make && make install
    
    
    
  • 编辑php主配置文件,添加gd模块

    image-20191104195008085

    image-20191104195458815

  • 检查php是否加载gd模块

    image-20191104195711619

  • 重启httpd服务

    image-20191104195740750

  • 客户端测试
    image-20191104195845984

总结

  • 源码安装时应当为软件指定安装目录
  • systemctl无法对源码安装的服务进行管理,需要使用服务的脚本管理方式进行管理,通过配置可以实现service等服务管理
  • 部分服务的配置文件需要添加响应的权限
  • 添加服务运行的用户,并设置响应权限
  • 修改PATH环境变量,便于执行命令
posted @ 2019-11-05 20:12  MirL  阅读(232)  评论(0编辑  收藏  举报