lishenghan 发表于 2018-12-22 08:26:03

Httpd2.4.10+Mysql5.6.21+Php5.61编译安装(PHP集成为HTTPD的模块)

  一、编译安装Httpd2.4.10
  1、解决依赖关系
  httpd-2.4.10需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行,在Apache官方网站下载apr 与apr-util码源包。
  1)编译安装apr
  # tar xf apr-1.5.1.tar.bz2
  # cd apr-1.5.1
  # ./configure --prefix=/usr/local/apr
  # make && make install
  2) 编译安装apr-util
  # tar xf apr-util-1.5.4.tar.bz2
  # cd apr-util-1.5.4
  # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  # make && make install
  3) httpd-2.4.10编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,找到并用yum安装即可,也要装上Server Platform Development组包与"Development tools"
  2、编译安装Httpd2.4.10
  首先下载httpd-2.4.4到本地,而后执行如下命令进行编译安装过程:
  # tar xf httpd-2.4.10.tar.bz2
  # cd httpd-2.4.10
  # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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/httpd 配置文件路径
  --enable-so 允许运行时加载DSO模块
  --enable-ssl 如果不加载将无法使用使用https
  --enable-cgi 允许使用cgi脚本
  --enable-rewrite 支持URL重写机制
  --with-zlib 支持网络通用压缩库
  --with-pcre 支持pcre
  --with-apr=/usr/local/apr 指定apr的安装路径
  --with-apr-util=/usr/local/apr-util/ 指定apr-util的安装路径
  --enable-modules=most 启用大多数常用的模块
  --enable-mpms-shared=all 启用MPM所有支持的模式
  --with-mpm=event 默认使用enevt模式
  补充:
  (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。
  1)导出头文件;以目录链接的形式来实现
  ln -sv /usr/local/apache/include/ /usr/include/httpd
  2)输出二进制程序
  # vim /etc/profile.d/httpd.sh
  export PATH=/usr/local/apache/bin:$PATH
  # . /etc/profile.d/httpd.sh
  # httpd -V    显示httpd版本信息
  3)导出man文件
  # vim /etc/man.config
  MANPATH /usr/local/apache/man
  3、修改httpd的主配置文件,设置其Pid文件的路径
  编辑/etc/httpd/httpd.conf,添加如下行即可:
  PidFile "/var/run/httpd.pid"
  4、提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下:
  #!/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
  而后为此脚本赋予执行权限:
  # chmod +x /etc/rc.d/init.d/httpd
  加入服务列表:
  # chkconfig --add httpd
  接下来就可以启动服务进行测试了
  Service httpd start
  ss -tunl | grep 80
  tcp    LISTEN    0      128                  :::80                  :::*
  然后访问服务器IP地址,页面显示It works!证明正常
  提示:如果不能停止httpd是因为Pidfile文件路径没有写正确。
  二、安装mysql-5.6.21
  1、准备数据存放的文件系统(由于数据库会不断的加大,所以选择放置在一个逻辑卷上)
  新建一个逻辑卷,并将其挂载至特定目录即可。这里不再给出过程。
  这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。
  2、新建用户以安全方式运行进程:
  # groupadd -r mysql
  # useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
  # chown -R mysql:mysql /mydata/data
  3、安装并初始化mysql-5.6.21
  # tar xf mysql-5.6.21-linux-glibc2.5-i686 -C /usr/local
  # cd /usr/local/
  # ln -sv mysql-5.5.28-linux2.6-i686 mysql
  # cd mysql
  # chown -R mysql:mysql .
  # scripts/mysql_install_db --user=mysql --datadir=/mydata/data
  # chown -R root .
  4、为mysql提供主配置文件:
  # cd /usr/local/mysql
  # cp support-files/my-large.cnf /etc/my.cnf
  并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
  thread_concurrency = 2
  另外还需要添加如下行指定mysql数据文件的存放位置:
  datadir = /mydata/data
  5、为mysql提供sysv服务脚本:
  # cd /usr/local/mysql
  # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
  # chmod +x /etc/rc.d/init.d/mysqld
  添加至服务列表:
  # chkconfig --add mysqld
  # chkconfig mysqld on
  而后就可以启动服务测试使用了。
  6、输出mysql的man手册至man命令的查找路径:
  编辑/etc/man.config,添加如下行即可:
  MANPATH /usr/local/mysql/man
  7、输出mysql的头文件至系统头文件路径/usr/include:
  这可以通过简单的创建链接实现:
  # ln -sv /usr/local/mysql/include /usr/include/mysql
  8、输出mysql的库文件给系统库查找路径:
  # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
  而后让系统重新载入系统库:
  # ldconfig
  9、修改PATH环境变量,让系统可以直接使用mysql的相关命令
  Vim /etc/profile.d/mysqld.sh
  Export PATH=/usr/local/mysql/bin:$PATH
  . /etc/profile.d/mysqld.sh
  三、编译安装php-5.4.13
  1、解决依赖关系:
  请配置好yum源(可以是本地系统光盘)后执行如下命令:
  # yum -y groupinstall " Desktop Platform Development"
  如果想让编译的php支持mcrypt扩展,在http://rpm.pbone.net下载
  并安装之:
  libmcrypt-2.5.7-5.el5.i386.rpm
  libmcrypt-devel-2.5.7-5.el5.i386.rpm
  2、编译安装php-5.6.1
  首先下载源码包至本地目录
  # tar xf php-5.6.1.tar.xz
  # cd php-5.6.1
  # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-
  mysqli=/usr/local/mysql/bin/mysql_config --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
  说明:
  1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
  2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL
  或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定
  形成依赖),但从PHP 5.4开始它就是默认设置了。
  # ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
  apxs2=/usr/local/apache/bin/apxs是将PHP编译为httpd的模块来运行
  如果在编译过程中缺少什么rpm包,可以在rpm.pbone.net下载
  # make
  # make test
  # make intall
  #切换到PHP源码包拷贝
  为php提供配置文件:
  # cp php.ini-production /etc/php.ini
  3、 编辑apache配置文件httpd.conf,以apache支持php
  # vim /etc/httpd/httpd.conf
  1、添加如下二行
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps
  2、定位至DirectoryIndex index.html
  修改为:
  DirectoryIndex index.php index.html
  而后重新启动httpd,或者重新载入配置文件即可测试,修改/usr/local/apache/htdocs/下的index.php为
  
  四、安装xcache,为php加速:
  1、 安装xcache
  下载xcache,地址为:http://xcache.lighttpd.net/
  # tar xf xcache-3.2.0.tar.gz
  # cd xcache-3.2.0
  # /usr/local/php/bin/phpize
  # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
  # make && make install
  安装结束时,会出现类似如下行:
  Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
  2、编辑php.ini,整合php和xcache:
  首先将xcache提供的样例配置导入php.ini
  # mkdir /etc/php.d
  # cp xcache.ini /etc/php.d
  说明:xcache.ini文件在xcache的源码目录中。
  接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
  zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
  注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。



页: [1]
查看完整版本: Httpd2.4.10+Mysql5.6.21+Php5.61编译安装(PHP集成为HTTPD的模块)