3dwqe 发表于 2014-8-14 17:36:58

编译安装LAMP+phpMyAdmin

一、准备工作
    关闭防火墙、selinux,配置yum源,并移出系统已安装的httpd,mysql,php

   

二、安装httpd-2.4.10
    ttpd-2.4.10需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里使用源码编译演示。
    1、安装apr   

            # tar xf apr-1.5.1.tar.bz2 -C /usr/src/
            # cd /usr/src/apr-1.5.1/
            # ./configure --prefix=/usr/local/apr
            # make && make install
    2、安装apr-util


            # tar xf apr-util-1.5.3.tar.bz2 -C /usr/src/
            # cd /usr/src/apr-util-1.5.3/
            # ./configure --prefix=/usr/local/apr-util
                                       --with-apr=/usr/local/apr/
            # make && make install
    3、安装httpd


            # tar xf httpd-2.4.10.tar.bz2-C /usr/src/
            # cd /usr/src/httpd-2.4.10/
            # ./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/apache24#→指定其安装位置
    --sysconfdir=/etc/httpd24#→指定配置文件安装位置
    --enable-so   #→启用基于DSO的方式动态加载模块
    --enable-ssl   #→启用基于https协议的功能
    --enable-cgi   #→启用基于cgi协议的功能
    --enable-rewrite#→启用支持URL重写的功能
    --with-zlib   #→指定支持在互联网上发送数据报文时,通用的压缩库的API
    --with-pcre#→指定支持poll的cgi
    --with-apr=/usr/local/apr    #→指定par的安装路径
    --with-apr-util=/usr/local/apr-util/   #→指定par-util的安装路径
    --enable-modules=most   #→启用大多数常用的模块
    --enable-mpms-shared=all   #→启用加载所有的mpm模块
    --with-mpm=event   #→指定接下来httpd的工作模式是even
补充:

(1)构建MPM为静态模块
      在全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本 时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 ./httpd -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。

(2)构建 MPM 为动态模块

      在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用--enable-mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令内容可以选择不同的MPM。

4、修改httpd的主配置文件,设置其Pid文件路径

      # vim /etc/httpd24/httpd.conf
   

提供服务脚本

      # vim /etc/rc.d/init.d/httpd24
      #!/bin/bash
      #
      # httpd      Startup script for the Apache HTTP Server
      #
      # chkconfig: - 85 15
      # description: Apache is a World Wide Web server.It is used to serve
      #      HTML files and CGI.
      # processname: httpd
      # config: /etc/httpd/conf/httpd.conf
      # config: /etc/sysconfig/httpd
      # pidfile: /var/run/httpd.pid

      # Source function library.
      . /etc/rc.d/init.d/functions

      if [ -f /etc/sysconfig/httpd ]; then
                . /etc/sysconfig/httpd
      fi

      # Start httpd in the C locale by default.
      HTTPD_LANG=${HTTPD_LANG-"C"}

      # This will prevent initlog from swallowing up a pass-phrase prompt if
      # mod_ssl needs a pass-phrase from the user.
      INITLOG_ARGS=""

      # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
      # with the thread-based "worker" MPM; BE WARNED that some modules may not
      # work correctly with a thread-based MPM; notably PHP will refuse to start.

      # Path to the apachectl script, server binary, and short-form for messages.
      apachectl=/usr/local/apache/bin/apachectl
      httpd=${HTTPD-/usr/local/apache/bin/httpd}
      prog=httpd
      pidfile=${PIDFILE-/var/run/httpd.pid}
      lockfile=${LOCKFILE-/var/lock/subsys/httpd}
      RETVAL=0

      start() {
                echo -n $"Starting $prog: "
                LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
                RETVAL=$?
                echo
                [ $RETVAL = 0 ] && touch ${lockfile}
                return $RETVAL
      }

      stop() {
          echo -n $"Stopping $prog: "
          killproc -p ${pidfile} -d 10 $httpd
          RETVAL=$?
          echo
          [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
      }
      reload() {
            echo -n $"Reloading $prog: "
            if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
                RETVAL=$?
                echo $"not reloading due to configuration syntax error"
                failure $"not reloading $httpd due to configuration syntax error"
            else
                killproc -p ${pidfile} $httpd -HUP
                RETVAL=$?
            fi
            echo
      }

      # See how we were called.
      case "$1" in
          start)
          start
          ;;
          stop)
          stop
          ;;
          status)
                status -p ${pidfile} $httpd
          RETVAL=$?
          ;;
          restart)
          stop
          start
          ;;
          condrestart)
          if [ -f ${pidfile} ] ; then
            stop
            start
          fi
          ;;
          reload)
                reload
          ;;
          graceful|help|configtest|fullstatus)
          $apachectl $@
          RETVAL=$?
          ;;
          *)
          echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
          exit 1
      esac

      exit $RETVAL
赋权并开启服务测试
   
            


三、在centos7上安装mariadb-5.5.36

   1、为数据库建一个文件存放目录
      # mkdir /mymariadb
      # fdisk /dev/sdb
      # kpartx -a /dev/sdb
      # pvcreate /dev/sdb1

      # vgcreate myvg /dev/sdb1
      # lvcreate -L 11G -n mymariadb myvg
      # mke2fs -t ext4 -b 4096 -m 3 /dev/myvg/mymariadb
      # vim /etc/fstab

                        dev/myvg/mymariadb   /mymariadbext4    defaults   0 0
      # mount -a
      # mkdir -p /mymariadb/mysql

    2、新建用户以安全方式运行myql
      # mkdir -p /mymariadb/mysql
      # groupadd -r mysql
      # useradd -g mysql -r mysql -s /sbin/nologin
      # chown -R mysql:mysql /mymariadb/mysql/

    3、为数据库提供主配置文件
      # tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local/
      # cd /usr/local/
      # ln -sv mariadb-5.5.36-linux-x86_64/ mysql
      # cd mysql/
      # chown -R root:mysql ./*
      # mkdir /etc/mysql

      # cp support-files/my-large.cnf /etc/my.cnf
      # vim /etc/my.cnf
                            datadir = /mymariadb/mysql
                            (必须在 下添加)


   4、初始化数据库,并提供服务脚本
      # scripts/mysql_install_db --user=mysql
                            --datadir=/mymariadb/mysql/   


      # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
      # chmod +x /etc/rc.d/init.d/mysqld
      # chkconfig --add mysqld
      # chkconfig --list mysqld
      # vim /etc/profile.d/mysqld.sh
                           export PATH=/usr/local/mysql/bin:$PATH
      # source /etc/profile.d/mysqld.sh
      # ln -sv /usr/local/mysql/include/ /usr/include/mysql
      # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
      # ldconfig(重新加载库)
      # service mysqld restart
         Shutting down MySQL. SUCCESS!
         Starting MySQL.. SUCCESS!
      # ss -tnl
      State    Recv-Q Send-Q       Local Address:Port         Peer Address:Port

      LISTEN      0      50            *:3306                   *:*
   


四、安装php-5.3.5
    1、解决依赖关系,这里利用yum安装,自己配置好源

    epel源 http://mirrors.sohu.com/fedora-epel/6/x86_64/
      # yum -y groupinstall Desktop Platform Development
      # yum -y install bzip2-devel libmcrypt-devel
      #tar xf libmcrypt-2.5.7.tar.gz
      #cd libmcrypt-2.5.7
      #./configure
      #make && make install

2、编译安装php-5.3.5
      # tar xf php-5.3.5.tar.bz2 -C /usr/local/

      # cd /usr/local/php-5.3.5/
      #./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --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-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2--enable-maintainer-zts
      # make && make install
编译参数介绍      

-prefix=/usr/local/PHP         php 安装目录    --with-apxs2=/usr/local/apache/bin/apxs--with-config-file-path=/usr/local/PHP/etc   指定php.ini位置--with-mysql=/usr/local/mysql   mysql安装目录,对mysql的支持--with-mysqli=/usr/local/mysql/bin/mysql_config    mysql高级访问接口--with-openssl ;可以支持ssl--enable-mbstring ;启动多字节字符支持--with-freetype-dir ;这是让PHP支持GD库的配置选项--with-jpeg-dir--with-png-dir--with-zlib;支持zlib的压缩库--with-libxml-dir=/usr--enable-xml ;支持xml格式--enable-sockets;支持socket方式通信--with-apxs2=/usr/local/apache/bin/apxs;php针对此接口来编译进apache--with-mcrypt;支持加密工具--with-config-file-path=/etc;配置文件文件--with-config-file-scan-dir=/etc/php.d;找/etc/php.d/下一.ini结尾的文件作为配置文件--with-bz2--enable-maintainer-zts;如果MPM为event和worker模型,编译时此处须启用,如果为prefork,它是以mod_php的方式安装的。
说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
#--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd

    3、为php提供配置文件

      # cp php.ini-production /etc/php.ini
    4、编辑apache配置文件httpd.conf,以apache支持php
                # vim /etc/httpd24/httpd.conf
            #定位至AddType
            #添加以下俩行

            AddType application/x-httpd-php.php
                     AddType application/x-httpd-php-source.phps
               #定位至DirectoryIndex index.html
               #修改为:
               DirectoryIndexindex.phpindex.html








页: [1]
查看完整版本: 编译安装LAMP+phpMyAdmin