86756 发表于 2014-10-10 10:44:30

LAMP的安装及Xcache的配置

LAMP是Linux+Apache+MySQL+PHP的简称,意指以Linux作为服务器的操作系统,以Apache的HTTPD作为Web服务器,以PHP作为动态网页的解释器,以MySQL作为后端数据库管理系统,由此而搭建起来的一套Web服务器系统。为方便起见,本文的假定CentOS6.5已经在服务器上安装完成。主要介绍手动编译安装httpd、MySQL和PHP的过程。
本文以目前比较新的版本组合进行手动安装:
httpd-2.4.10.tar.bz2 (源码)
mysql-5.5.40-linux2.6-x86_64.tar.gz
php-5.6.1.tar.bz2    (源码)

1.准备编译环境
a) 添加EPEL的yum仓库源。 EPEL仓库提供了比较多而且新的rpm包,建议添加该仓库源。具体如何添加可以去EPEL的官方站点了解。
b) 安装编译必须的2个包组
    # yum groupinstall "development tools"
    # yum groupinstall "desktop platform development"
c) 其它还有一些rpm包的安装在具体编译服务器软件时再事前介绍,以便了解其相关性。
2.编译安装HTTPD
a) 安装依赖开发包。httpd-2.4.10需要比较新的apr和apr-util。本文下载了比较新的源码包apr-1.5.1.tar.bz2和apr-util-1.5.4.tar.bz2进行编译安装。
    # tar xf apr-1.5.1.tar.bz2
    # cd apr-1.5.1
    # ./configure --prefix=/usr/local/apr
    # make && make install
    #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
b) 安装依赖包openssl-devel, pcre-devel
    # yum install openssl-devel
    # yum install pcre-devel
c) 编译安装httpd-2.4.10
    # tar xf httpd-2.4.10.tar.bz2
    # cd httpd-2.4.10
    # ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd--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
d) 提供SYSV服务脚本/etc/rc.d/init.d/httpd,篇幅原因,内容略去。

3.安装MySQL
a) 准备专门的磁盘空间作为mysql的数据区。假定该磁盘分区挂载为/mysql
    # mkdir /mysql/data
b) 创建mysql运行使用的用户
    # groupadd -r mysql
    # useradd -r -g mysql -s /sbin/nologin -M -d /mysql/data mysql
    # chown -R mysql.mysql /mysql/data
c) 安装通用二进制版本并初始化数据库
    # tar xf mysql-5.5.40-linux2.6-x86_64.tar.gz -C /usr/local
    # cd /usr/local
    # ln -s mysql-5.5.40-linux2.6-x86_64 mysql
    # cd mysql
    # chown -R root.mysql .
    # scripts/mysql_install_db --user=mysql --datadir=/mysql/data
d) 为mysql提供主配置文件
    # cd /usr/local/mysql
    # cp support-files/my-large.cnf/etc/my.cnf
    添加如下行在段中,指定mysql数据文件的存放位置:
      datadir = /mydata/data
    修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
      thread_concurrency = 2
e) 为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
f) 安装配置完毕,启动服务测试。

    为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,还需要进行如下步骤:
g) 输出mysql的man手册至man命令的查找路径
    编辑/etc/man.config,添加如下行:
      MANPATH/usr/local/mysql/man
h) 输出mysql的头文件至系统头文件路径
    # ln -s /usr/local/mysql/include/usr/include/mysql
i) 输出mysql的库文件给系统库查找路径
    # echo "/usr/local/mysql/lib" > /ect/ld.so.conf.d/mysql.conf
j) 修改PATH环境变量,让系统可以直接使用mysql的相关命令
    在/etc/profile.d/目录下创建文件mysql.sh,其内容如下:
      export PATH=/usr/local/mysql/bin:$PATH

4.编译安装PHP
a) 安装依赖包
    # yum -y install bzip2-devel
    # yum -y install libmcrypt-devel
b) 编译安装php-5.6.1.tar.bz2
    # tar xf php-5.6.1.tar.bz2
    # cd php-5.6.1
    # ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-openssl --with-mcrypt --enable-mbstring --enable-xml --enable-sockets --enable-maintainer-zts --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config
    # make && make install

说明:
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

c) 为php提供配置文件
    # cp php.ini-production /etc/php.ini
d) 编辑apache配置文件httpd.conf,以apache支持php
    # vim /etc/httpd/httpd.conf
    在相应的位置添加如下行
      AddType application/x-httpd-php.php
      AddType application/x-httpd-php-source.phps
    修改DirectoryIndex 的定义为:
      DirectoryIndexindex.phpindex.html
e) 安装配置完毕,重启httpd服务进行测试。php测试页代码如下:
    <?php
      phpinfo();
    ?>

5.编译安装Xcache
为了提高PHP解释器的性能,可以为php安装Xcache缓存插件。具体安装配置如下。
a) 编译安装xcache-3.2.0.tar.bz2
    # tar xf xcache-3.2.0.tar.bz2
    # 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
b) 编辑php.ini,整合php和xcache
    # mkdir /etc/php.d
    # cp xcache.ini /etc/php.d
    注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

   本文介绍的php的安装是作为模块的方式加载到httpd的进程中工作的。下一篇博文专门介绍php和httpd以fastCGI的方式整合的安装方法。

页: [1]
查看完整版本: LAMP的安装及Xcache的配置