实现php加速的原理,LAMP平台实现之PHP加速,xcache

1、安装mysql-5.5.33-linux2.6-x86_64#tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz –C /usr/local/

# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql

# cd mysql

#mkdir /mydata

# cat INSTALL-BINARY | less

shell> groupadd mysql

shell> useradd -r -g mysql mysql

shell> cd /usr/local

shell> cd mysql

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> scripts/mysql_install_db --user=mysql --datadir=/mydata

shell> chown -R root .

shell> chown -R mysql /mydata

# Next command is optional

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> bin/mysqld_safe --user=mysql &

# Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server

8116ab2c31f206df4c1f3e496e76b9e2.png

a99128edf0b673c49dff71fa9cb5c5aa.png

31329d2639c3db5e621fdf081dd1b2f3.png

ac94795610e723f4d5ad4ccc9f7f8a36.png

1eb3a08aabf81adaafccca4f94a2c4c2.png

e51677a1b7bb21baeb0b9c492854e7fc.png

d242dd9b627fdcefff665d5ebcefd549.png

修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:# thread_concurrency = 2

另外还需要添加如下行指定mysql数据文件的存放位置:

datadir = /mydata

84fe6739a1f11cf3f86be7f57cf9dce7.png

为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

# vim /etc/profile.d/mysql.sh

# export PATH=/usr/local/mysql/bin:$PATH

# . /etc/profile.d/mysql.sh

# echo $PATH

518e5824d81c3ad1d90bf1869582c0a2.png

输出mysql的头文件至系统头文件路径/usr/include,并且输出库文件

# ln -sv /usr/local/mysql/include  /usr/include/mysql

# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

# ldconfig

60b37beb21e806e87dd8e52a1c9ee31d.png

2、编译安装php-5.4.26

说明:

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# yum -y groupinstall "Desktop Platform Development"

# yum -y install bzip2-devel libmcrypt-devel

# tar xf php-5.4.26.tar.bz2

# cd php-5.4.26

# ./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 intall

# cp php.ini-production /etc/php.ini

# vim /etc/httpd/httpd.conf

# AddType application/x-httpd-php .php

# AddType application/x-httpd-php-source .phps

# DirectoryIndex index.php index.html

a420a2026053adfc3dcd50c00c6ce210.png

如上图所示:为php提供配置文件:# cp php.ini-production /etc/php.ini

21c06a000b1220447bbb98ca00df91c7.png

4b087d167fc4510967710372869b951c.png

2567e0a8a2f61d92daa4239be81fb392.png

b14954cd0b2c73bae68f97af6d129450.png

f0e6c92f73b6ad3341ba7f247b061db5.png

ad81d3c2957bb28c7bdd49425370eaa3.png

3、安装xcache,为php加速

安装# tar xf xcache-3.0.1.tar.gz

# cd xcache-3.0.1

# /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-20100525/

2、编辑php.ini,整合php和xcache:

首先将xcache提供的样例配置导入php.ini

# mkdir /etc/php.d

# cp xcache.ini /etc/php.d

接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:

zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

13363a07784d60fcac15edac52430bec.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值