鄂破机看 发表于 2018-12-22 09:12:25

源码安装LAMP,以Module方式使用PHP并使用xcache 2.0.0加速PHP


[*]  介绍LAMP
  LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。
  首先,安装顺序为apache--->mysql--->php
  环境:RHEL5.8 I386
  Development Libraries
         Development Tools
  

  软件包:    httpd: 2.4.4
                  php: 5.4.13
                  MySQL: 5.6.10 通用二进制包
  

  准备:
  确保你的系统没有安装lamp环境,如mysql,httpd,php
  


[*]  安装


[*]  apache2.4的安装
  由于apache2.4需要apr,apr-utils较新版本,这里我们使用源码包编译安装
  apr-1.4.6.tar.gz
  apr-util-1.4.1.tar.gz
  tar xf apr-util-1.4.1.tar.gz &&tar xf apr-1.4.6.tar.gz
  cd apr-1.4.6
  ./configure --prefix=/usr/local/apr
  make &&make install
  cd ../apr-util-1.4.1
  ./cofigure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr
  make &&make install
  

  tar xf httpd-2.4.4.tar.bz2
    cd httpd-2.4.4
    ./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-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
    make &&make install
  为了方便以后使用,制做sysV风格服务启动脚本:
  一般情况,如果是手动编译的话,apache是没有启动脚本的,也就是说用户不能通过简单的/etc/init.d/httpd(start|stop|restart)来启动/关闭/重新启动。其实在源码里已经有启动的脚本,我们要修改下即可,把Apache加入系统SysV服务中来。
  在源码httpd-2.x.x/build/rpm中存在httpd.init拷贝命令如下:   
  cp httpd.init/etc/init.d/httpd
  拷贝之后,注意其中有三处主要的地方需要修改下的:
httpd=${HTTPD-/usr/local/apache/bin/httpd}
  
pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}
  
CONFFILE=/usr/local/apache/conf/httpd.conf
  
请根据自己的实际情况更改相应的路径!
  
然后运行如下命令:
  
chmod +x/etc/init.d/httpd
  
chkconfig--add httpd
  
chkconfig --level2345 httpd on
  
这样一来,启动、停止、重启Apache就可以用以下方式了:
  
/etc/init.d/httpdstart
  
/etc/init.d/httpdstop
  
/etc/init.d/httpdrestart
输出PATH变量
      vim /etc/profile.d/httpd.sh
            export PATH=$PATH:/usr/local/apache/bin





[*]安装mysql
  
  tar xvf mysql-5.5.28-linux2.6-i686.tar.gz
  mv mysql-5.5.28-linux2.6-i686 /usr/local
  ln -s mysql-5.5.28-linux2.6-i686 /usr/local/mysql
  注:以上是官方要求的
  useradd -r mysql
  cp support-files/my-large.cnf /etc/my.cnf
  chown -R mysql:mysql .
  scripts/mysql_install_db --user=mysql
  注:如果你的data不打算放在默认的文件系统上,也可以加上--datadir=/data/db
  如果你修改了默认目录,需要修改/etc/my.cnf文件
  在【mysqld】 项下增加
  datadir = /data/db
  chown -R root:mysql .
  chown -R mysql:mysql /data/db
  chmod -R 750 .
  cp support-files/mysql.server /etc/init.d/mysqld
  mysql命令工具
  vim /etc/profile.d/mysqld.sh
  export PATH=$PATH:/usr/local/mysql/bin
  

  man手册设置
  vim /etc/man.config
  新增一行:
  MANPATH /usr/local/mysql/man
  lib库文件设置
  vim /etc/ld.so.conf.d/mysql.conf
  新增一行:
  /usr/local/mysql/lib
  重新加载系统库文件
  lddconfig -v
  include头文件设置
  ln -s /usr/local/mysql/include /usr/include/mysql
  


[*]  安装php
  tar xvf php-5.4.13.tar.bz2
  cd php-5.4.13
  ./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-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
  此处安装会报错:
configure: error: mcrypt.h not found.Please reinstall libmcrypt.
  
  我们需要安装加密库需要的软件包:
  rpm -ivh mhash-devel-0.9.2-6.el5.i386.rpm mhash-0.9.2-6.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm libmcrypt-2.5.7-5.el5.i386.rpm
    make &&make install
  此时,php安装完毕
  


[*]  整合
  

  要使得apache与php能工作,还需要为httpd做相应设置
  vim /etc/httpd/httpd.conf
  LoadModule php5_module      modules/libphp5.so
  AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
  DirectoryIndex index.html index.php
  重启或启动httpd服务
  测试服务是否都正常
  vim /usr/local/apache/htdocs/index.php
  

  
      
  

  安装xcache2.0.0
  tar xvf xcache-3.0.4.tar.gz
    cd xcache-3.0.4
    ls
    cat INSTALL
    /usr/local/php/bin/phpize
    ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
    make &&make install
    mkdir /etc/php.d
    cp xcache.ini /etc/php.d/
    vim /etc/php.d/xcache.ini
  zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
  ;zend_extension_ts = c:/php/extensions/php_xcache.dll
  

  上面路径是在安装完php后的最后一条提示
  

  回到主页,可以看到xcache己加载进来了
  

  


[*]  其它解说:
  

  对于源码安装的apache如果我们需要使用虚拟主机,需要修改/etc/httpd/httpd.conf
  启用Include /etc/httpd/extra/httpd-vhosts.conf,然后在/etc/httpd/extra/httpd-vhosts.conf中设置虚拟主机
  在设置ACL时,需与apache2.2区别开来,它们的区别比较多
  如果需要启用ssl,也要启用相应的模块
  。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  在这里我们需要弄清LAMP工作机制:
  在apache需要解析PHP脚本时才会用到PHP解析器,PHP与apahe有多种工作机制
  1、Modules方式,也就是本文的配置过程
  2、fastCGI(在PHP中也称FPM)
  3、还有Apache的CGI
  这里就不讲这些机制的具体配置,以后有时间再编了,但是大多数生产环境用到的都是三层结构,也就是使用的是fastCGI模式。
  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  




页: [1]
查看完整版本: 源码安装LAMP,以Module方式使用PHP并使用xcache 2.0.0加速PHP