hyperv 发表于 2018-12-18 13:47:07

LAMP服务器环境之编译(部分)安装

  安装环境

  redhat5.8(2.6.18-194.el5.i386,_)
  Apache-httpd 2.2.29
  MysQl mysql-5.5.44二进制通用包
  PHP php-5.4.43
  pcre依赖包
  xcache 2.0.1
  安装顺序
  apr-->apr-util-->httpd-->MySQl-->php-->xcache
  1,编译安装httpd
  安装httpd依赖环境:apr和par-util,首选需要安装
  1.1安装apr
  解压apr源码包,编译安装并指定安装路径
  ./configure --prefix=/usr/local/apr
  make &&make install
  1.2安装apr-util,安装时需指定apr安装路径
  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  make&& make install
  1.3安装httpd服务(首先需要解决pcre依赖)
  1.3.1安装httpd,需指定apr和par-util安装路径
  安装选项说明:

  --enable-ssl 启用https支持
  --enable-so 启用动态共享库支持
  --enable-deflate 压缩传输支持
  --enable-proxy-scgifastcgi支持
  --with-mpm=MPM默认MPM类型
  --enable-mpms-shared=all 编译mpm模块(all表示编译所有)
  --sysconfdir=/etc/httpd 配置文件路径
  ...(详见,.configure --help)
  ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
  make &&make install
  1.3.2 添加httpd可执行文件到环境变量,及其他相关
  修改pid文件路径,编译安装后默认在编译目录./logs下

  vi /etc/httpd/httpd.conf
  在任意位置添加PidFile "/var/run/httpd.pid"
  

  提供SysV服务脚本
  vi /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
  
  修改环境变量
  vi /etc/profile.d/httpd.sh
  添加如下内容,不需要给予该文件其他权限
  export PATH=$PATH:/usr/local/apache/bin
  测试httpd服务(需关闭iptables和SELinux)
  启动httpd服务
  service httpd start

http://s3.运维网.com/wyfs02/M02/6F/E1/wKioL1Wso3zzmZNrAABmPmaVN-o847.jpg
  1.4 安装mysqld服务,mysql的服务使用通用二进制格式安装,需要解压到/usr/local目录下

  创建mysql用户和组,使用-r选项不允许登录,且系统服务使用500以下UID和GID
  groupadd -g 306 -r myql
  useradd -g 306 -r -u 306 mysql
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif添加目录软连接
  ln -s mysql-5.5.44-linux2.6-i686 mysql
  修改mysql解压目录权限
  chown-R mysql:mysql mysql/*
  创建数据目录并修改相应权限
  chmod 750 /data/
  初始化mysql
  scripts/mysql_install_db --user=mysql --datadir=/data
  复制配置文件到/etc目录

  cp support-files/my-large.cnf /etc/my.cnf
  在配置文件尾部添加数据目录路径
  datadir = /data
  拷贝SysV服务脚本,并修改
  cp support-files/mysql.server /etc/init.d/mysqld
  编辑
  basedir=/usr/local/mysql
  datadir=/data
  chkconfig --add mysqld
  为mysqld添加环境变量

  vi /etc/profile.d/mysql.sh
  export PATH=$PATH:/usr/local/mysql/bin
  添加man环境变量
  vi /etc/man.config
  MANPATH /usr/local/mysql/man
  共享库文件

  vi /etc/ld.so.conf.d/mysql.conf
  /usr/local/mysql/lib
  使用ldconfig -v 使共享立即生效,-v显示过程
  启动mysql 并修改root密码
  service mysqld start
  mysqladmin -uroot password 'password'
  1.4 编译安装php模块

  此处将php编译为httpd的一个模块
  编译选项说明

  php53-mbstring 多语言支持
  --with-opensslopenssl支持
  --with-freetype-dir 字体库支持,实现引用特定字体
  --with-zlib 压缩库支持
  --with-apxs2=/usr/local/apache/bin/apxs让php编译成apache的模块
  --with-mcrypt 支持额外的加密库
  --enable-maintainer-zts 使用prefork模型使用该设置.使用线程模块时需要
  安装 mcrypt.h支持,需要的安装包如下:
  mhash-0.9.2-6.el5.i386.rpm
  mhash-devel-0.9.2-6.el5.i386.rpm
  libmcrypt-2.5.7-5.el5.i386.rpm
  libmcrypt-devel-2.5.7-5.el5.i386.rpm
  ./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
  make &&make install
  检查httpd.conf配置文件如下行是否存在,若不存在,则加入
  LoadModule php5_modulemodules/libphp5.so
  提供配置文件,在编译目录下复制下列文件中的一个到/etc/php.ini
  php.ini-development 开发环境
  php.ini-production 生产环境
  结合php和apache
  测试LAMP环境
  1.测试httpt和php的结合
  编译安装的httpd默认文档位置为/usr/local/apache/htdocs
  编辑如下文件
  vi index.php
  It works!
  
http://s3.运维网.com/wyfs02/M01/6F/E2/wKioL1Wstx6jh-p1AAIYVy3ddYk674.jpg2.测试httpd-php-mysql结合
  vi index.php
  It works!
  
  
  

  
http://s3.运维网.com/wyfs02/M02/6F/E3/wKioL1WsuJbjS3PJAAC-S3QcV1g555.jpg
  为php增加xcache拓展
  运行/usrlocalphp/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-20100525/,后面需要
  复制配置文件(没有php.d目录可手动创建)

  cp xcache.ini /etc/php.d/
  vi /etc/php.d/xcache.ini把上面安装xcache完成后的那个路径添加到该位置
  zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
  重启httpd服务
http://s3.运维网.com/wyfs02/M01/6F/E3/wKioL1WsvkySmemAAAFCoE9MRjQ480.jpg
  

  

  

  




页: [1]
查看完整版本: LAMP服务器环境之编译(部分)安装