zoukankan      html  css  js  c++  java
  • 编译安装lamp

    整体规划图

    共三台主机;httpd,php-fpm,mariadb分别位于不同主机。

    二进制安装mariadb

    安装过程大致思路为:准备二进制包—解压到指定文件后创建mysql连接方便管理—创建数据目录和著配置文件目录—安装mysql指定数据目录—开机自启配置

    tar -zxvf  mariadb-5.5.43-linux-x86_64.tar.gz   -C /usr/local/
    ln -s /usr/local/mariadb-5.5.43-linux-x86_64/ /usr/local/mysql 
    useradd  -s /sbin/nologin  mysql
    chown  -R root.mysql /usr/local/mysql/*
    mkdir -p /mydata/data
    chown -R mysql.mysql /mydata/data
    mkdir /etc/mysql
    cp -a /usr/local/mysql/support-files/my-large.cnf  /etc/mysql/my.cnf 
    vim /etc/mysql/my.cnf
        [mysqld]###加三行,一定要配置在[mysqld]配置段否则mysql启动不起来。
        datadir =/mydata/data
        innodb_file_per_table = ON
        skip_name_resolve = ON
    vim /etc/profile.d/mysql.sh
        export PATH=/usr/local/mysql/bin/:$PATH
    source  /etc/profile.d/mysql.sh
    cd /usr/local/mysql;scripts/mysql_install_db --user=mysql --datadir=/mydata/data 
    cp -a  /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
    chkconfig  --add mysqld 
    /usr/local/mysql/bin/mysql_secure_installation

    编译安装httpd-2.4

    第一步:编译安装httpd

    mkdir /app/httpd-2.4.39/srclib/apr-util
    mkdir /app/httpd-2.4.39/srclib/apr
    cp -r /app/apr-1.7.0/* /app/httpd-2.4.39/srclib/apr
    cp -r /app/apr-util-1.6.1/* /app/httpd-2.4.39/srclib/apr-util/
    cd /app/httpd-2.4.39/
    ./configure
    --prefix=/app/httpd24
    --enable-so
    --enable-ssl
    --enable-cgi
    --enable-rewrite
    --with-zlib
    --with-pcre
    --with-included-apr
    --enable-modules=most
    --enable-mpms-shared=all
    --with-mpm=prefork

    第二步:配置httpd

    Httpd编译过程:

      /app/httpd24/build/config.nice

    自带的服务控制脚本:

      /app/httpd24/bin/apachectl

    导出环境变量

    vim /etc/profile.d/httpd24.sh
      export PATH=/app/httpd24/bin:$PATH

    自定义启动脚本

    /usr/lib/systemd/system/httpd24.service[Unit]
    Description=The Apache HTTP Server
    After=network.target remote-fs.target nss-lookup.target
    Documentation=man:httpd(8)
    Documentation=man:apachectl(8)
    
    [Service]
    Type=forking
    #Type=notify
    #EnvironmentFile=/etc/sysconfig/httpd
    ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
    #ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
    ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
    ExecStop=/bin/kill -WINCH ${MAINPID}
    # We want systemd to give httpd some time to finish gracefully, but still want
    # it to kill httpd after TimeoutStopSec if something went wrong during the
    # graceful stop. Normally, Systemd sends SIGTERM signal right after the
    # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
    # httpd time to finish.
    KillSignal=SIGCONT
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    重载配置

    systemctl daemon-reload

    启动服务

    systemctl start httpd24

    编译安装php

     第一步:安装php

    yum -y install epel-release libxml2-devel bzip2-devel libmcrypt-devel  gcc pcre-devel openssl-devel expat-devel
    tar -xvf php-7.3.5.tar.bz2 
    ./configure --prefix=/app/php 
    --enable-mysqlnd 
    --with-mysqli=mysqlnd 
    --with-pdo-mysql=mysqlnd 
    --with-openssl 
    --with-freetype-dir 
    --with-jpeg-dir 
    --with-png-dir 
    --with-zlib 
    --with-libxml-dir=/usr 
    --with-config-file-path=/etc 
    --with-config-file-scan-dir=/etc/php.d 
    --enable-mbstring 
    --enable-xml 
    --enable-sockets 
    --enable-fpm 
    --enable-maintainer-zts 
    --disable-fileinfonstall
    make && make install

    第二步配置php

    cp php.ini-production /etc/php.ini ##从php.ini-production生成php配置文件
    cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm###生成php启动文件
    chmod +x /etc/init.d/php-fpm
    chkconfig --add php-fpm ###配置开机自启
    chkconfig php-fpm on
    vim /app/php/etc/php-fpm.d
      listen = 9000 ###监听所有ip的9000段偶
    vim /var/www/html/index.php ##提供简单的测试页。

    <?php
      echo date("Y/m/d H:i:s");  ###实践测试代码
      $mysqli=new mysqli("192.168.206.30", "root", ""); ###下面时数据库测试代码
      if(mysqli_connect_errno()){
        echo "Failure";
      $mysqli=null;
      exit;
      }
      echo "OK";
      $mysqli->close();
    ?>

    第三步配置httpd支持php-fpm

    vim /app/httpd24/conf/httpd.conf
    取消下面两行的注释,开启proxy
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    修改下面行
    <IfModule dir_module>
     DirectoryIndex index.php index.html
    </IfModule>
    加下面四行
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://192.168.206.20:9000/var/www/html/$1  ##将访问*.php的请求装发到20服务器的/var/www/html/*.php
    
    

    第四步,启动服务

    service php-fpm start

    systemctl restart httpd24

    测试LAMP 

  • 相关阅读:
    Burp Suite Intruder的4种攻击类型
    JSP Response Set Status
    Mybatis中的#和$的区别
    请求转发、请求重定向
    Spring IoC Container and Spring Bean Example Tutorial
    成员变量声明时初始化和构造方法中初始化的区别
    JDK开发WebService
    Mac设置截图保存位置
    Socket通信
    DOM4J解析xml
  • 原文地址:https://www.cnblogs.com/wxxjianchi/p/13549586.html
Copyright © 2011-2022 走看看