Centos6.9编译安装LAMP+xcache

Centos 6.9 编译安装 LAMP apache 2.4 + MySQL 5.7 + php5.6.34 + Fast-cgi + xcache

德化网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。成都创新互联公司自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

实验环境:VMware Workstation Pro 14(试用版)
系统平台:
CentOS release 6.9 (Final)             内核  2.6.32-696.el6.x86_64
Apache/2.4.29 (Unix)
PHP 5.6.34 (cli)
xcache 3.2.0

1. 编译安装apache 2.4

参考Centos 6.9 apahce 2.4.29编译安装

2. 二进制安装Mysql 5.7

参考CentOS 6.9 自定义单实例 二进制方式 安装mysql5.7.21

3. PHP官网下载Stable版本

http://php.net/downloads.php

# wget http://hk1.php.net/distributions/php-5.6.34.tar.bz2

4.安装依赖包

有个别包需要EPEL源,可提前配置好Aliyun的Yum源

注意:以下依赖包仅仅限于下面演示的编译参数,实际按需。
#yum install bzip2-devel libxml2-devel libmcrypt-devel libmcrypt curl-devel gd-devel
如果需要后期动态添加模块,还需要安装autoconf

注意:php-7.0以上版本使用--enable-mysqlnd --withmysqli=mysqlnd ,原--with-mysql不再支持

5.编译安装

编译参数

对于mysql的api方法,先了解一下:

PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包。
mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖)。
从PHP 5.4开始,对于未明确指定--with-mysql的情形,mysql本地驱动将会被安装。
可以参考如下配置:
比如:

--with-mysql       > 相当于该参数值为mysqlnd
--with-mysqli      > 相当于该参数值为mysqlnd
--with-pdo-mysql   > 相当于该参数值为mysqlnd
因为,--with-mysqli=/usr/local/mysql/bin/mysql_config  这种才是明确指定的表示方法

Centos 6.9 编译安装 LAMP + xcache

# tar xvf php-5.6.34.tar.bz2
# cd php-5.6.34

./configure --prefix=/usr/local/php-5.6.34 \
--with-openssl \
--enable-mysqlnd \
--with-mysql=/usr/local/mysql \
--with-mysqli \
--with-pdo-mysql \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-iconv \
--with-gd \
--with-curl \
--disable-debug \
--enable-calendar

编译与安装

# make -j 8
出现Build complete. 那么,恭喜编译成功

# make install

以下这些提示,按需。
Wrote PEAR system config file at: /usr/local/php-5.6.34/etc/pear.conf
You may want to add: /usr/local/php-5.6.34/lib/php to your php.ini include_path
/app/httpd/php-5.6.34/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.6.34/bin
ln -s -f phar.phar /usr/local/php-5.6.34/bin/phar
Installing PDO headers:           /usr/local/php-5.6.34/include/php/ext/pdo/

创建一个软链接,方便管理版本

#cd /usr/local/
#ln -s php-5.6.34/ php

6.复制php配置文件

注意,这些文件是在源码目录里
# cp php.ini-production /etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm

创建一个存放其他扩展配置的目录
# mkdir /etc/php.d

7.修改php-fpm启动脚本

# vim /etc/rc.d/init.d/php-fpm   > 这一步不修改也行,只不过这里是为了后续切换不同版本时方便

prefix=/usr/local/php   > 把这行修改为指定的编译路径

8.生成php-fpm配置文件

# sed -ri.bak s#php-5.6.34#php#g /usr/local/php/etc/php-fpm.conf.default
# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf    > 不用

9.添加php-fpm为启动服务

# chkconfig --add php-fpm
# chkconfig php-fpm on

10.配置httpd支持php

# vim /etc/httpd2.4/httpd.conf
确保以下2条取消注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

# 如果使用的是虚拟主机形式,把下面4行添加到主机标签中
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/www/virtualhost/$1

其中/app/www/virtualhost指的是站点文件目录

例子:


    DocumentRoot "/app/www/virtualhost"
    ServerName www.hunk.tech
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/www/virtualhost/$1

        
                DirectoryIndex index.php index.html
        

        
                AllowOverride None
                Options None
                Require all granted
        



# service httpd restart
# service php-fpm start

10.测试php

#ss -nlt
fcgi正在监听端口
State      Recv-Q Send-Q                                           Local Address:Port 
LISTEN     0      128                                                  127.0.0.1:9000 

编辑一个php的测试文件
#vim /app/www/virtualhost/index.php

Centos 6.9 编译安装 LAMP + xcache

11.连接数据库测试

在mysql中创建一个用于连接的账户

mysql> create user test@'192.168.5.102' identified by 'password';

mysql5.7数据库下已经没有password这个字段了,password字段改成了authentication_string
并且密码策略控制着密码相关

以下为修改默认的密码策略,0=LOW,至少8个字符
mysql> set global validate_password_policy=0

测试代码如下:

# vim /app/www/virtualhost/check.php

connect_errno) {
    echo "连接失败";
    exit();
}
echo "连接成功";

/* close connection */
$mysqli->close();
?>

# curl www.hunk.tech/check.php
连接成功

以下代码为判断mysql和mysqli扩展是否安装

The mysql extension is installed.

"; } else { echo "

The mysql extension is not installed..

"; } if (mysqliinstalled()){ echo "

The mysqli extension is installed.

"; } else { echo "

The mysqli extension is not installed..

"; } ?>

12.测试未启用加速器前的性能

#ab -c 1000 -n 5000 192.168.5.102/check.php

Server Software:        Apache/2.4.29
Server Hostname:        192.168.5.102
Server Port:            80

Document Path:          /check.php
Document Length:        12 bytes

Concurrency Level:      1000
Time taken for tests:   6.751 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      915000 bytes
HTML transferred:       60000 bytes
Requests per second:    740.59 [#/sec] (mean)
Time per request:       1350.282 [ms] (mean)
Time per request:       1.350 [ms] (mean, across all concurrent requests)
Transfer rate:          132.35 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  210 625.4      1    3019
Processing:     1  436 954.0    190    6676
Waiting:        1  435 954.0    189    6675
Total:         63  645 1295.6    194    6734

Percentage of the requests served within a certain time (ms)
  50%    194
  66%    215
  75%    335
  80%    405
  90%   1341
  95%   3439
  98%   6299
  99%   6697
 100%   6734 (longest request)

13.编译安装 xcache

去官网下载源码包

http://xcache.lighttpd.net

http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

安装phpize需要的依赖包

#yum install m4 autoconf

解压缩xcache-3.2.0.tar.bz2

#tar xvf xcache-3.2.0.tar.gz

生成xcanche编译文件

# cd xcache-3.2.0
#/usr/local/php/bin/phpize  > 注意,这里指向的是php目录

Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

编译安装xcache

# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
注意,--sysconfdir指向的是Php存放配置文件的目录

# make && make install

Installing shared extensions:     /usr/local/php-5.6.34/lib/php/extensions/no-debug-non-zts-20131226/

复制xcache配置文件

#cp xcache.ini /etc/php.d/

重启php服务并验证

# service php-fpm restart

# /usr/local/php/bin/php -m|grep -i xcache
XCache
XCache Cacher

通过phpinfo也可以看到

Centos 6.9 编译安装 LAMP + xcache

14.测试启用加速器后的性能

#vim /etc/php.d/xcache.ini
xcache.optimizer =           On
xcache.size  =               1024M

#ab -c 1000 -n 5000 192.168.5.102/check.php

Server Software:        Apache/2.4.29
Server Hostname:        192.168.5.102
Server Port:            80

Document Path:          /check.php
Document Length:        12 bytes

Concurrency Level:      1000
Time taken for tests:   6.541 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      915000 bytes
HTML transferred:       60000 bytes
Requests per second:    764.46 [#/sec] (mean)
Time per request:       1308.116 [ms] (mean)
Time per request:       1.308 [ms] (mean, across all concurrent requests)
Transfer rate:          136.62 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  277 612.3      2    3017
Processing:     1  425 835.1    156    4186
Waiting:        1  424 835.1    155    4185
Total:         61  702 1187.2    167    5262

Percentage of the requests served within a certain time (ms)
  50%    167
  66%    235
  75%    436
  80%   1021
  90%   2137
  95%   3817
  98%   5138
  99%   5197
 100%   5262 (longest request)

貌似简单的测试并没有发现什么优势呢


名称栏目:Centos6.9编译安装LAMP+xcache
转载注明:http://ybzwz.com/article/peooip.html