微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

LNMP架构应用实战——PHP扩展及缓存插件安装

LNMP架构应用实战——PHP扩展及缓存插件安装





1、LNMP环境查看

linux系统版本

[root@localhost~]# cat /etc/redhat-release

CentOSrelease 6.5 (Final)

[root@localhost~]# uname -r

2.6.32-431.el6.x86_64

Nginx版本

[root@localhost~]# /application/Nginx/sbin/Nginx -v

Nginxversion: Nginx/1.10.1

MysqL版本

[root@localhost~]# MysqLadmin -uroot -p'MysqL123' version

MysqLadmin  Ver 8.42 distrib 5.1.72, forunkNown-linux-gnu on x86_64

copyright(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is aregistered Trademark of Oracle Corporation and/or its

affiliates.Other names may be Trademarks of their respective

owners.

Serverversion          5.1.72

Protocol version        10

Connection            Localhost via UNIX socket

UNIXsocket           /application/MysqL-5.1.72/tmp/MysqL.sock

Uptime:         8 hours 13 min 37 sec

Threads: 1 Questions:2646 Slow queries: 0 Opens: 382  Flushtables: 1 Open tables: 4 Queries per second avg: 0.89

PHP版本

[root@localhost~]# /application/PHP/bin/PHP -v

PHP 5.3.27(cli) (built: Sep 27 2016 15:15:29)

copyright(c) 1997-2013 The PHP Group

Zend Enginev2.3.0, copyright (c) 1998-2013 Zend Technologies




2、perl编译问题解决

[root@localhost~]# echo 'export LC_ALL=C'>>/etc/profile

[root@localhost~]# tail -1 /etc/profile

exportLC_ALL=C

[root@localhost~]# . /etc/profile     

[root@localhost~]# echo $LC_ALL

C




3PHP的eaccelerator缓存加速模块安装

下载软件

[root@localhosttools]#wget https://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6/eaccelerator-0.9.6.tar.bz2/download

Location:http://jaist.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6/eaccelerator-0.9.6.tar.bz2[following]

--2016-09-2814:35:53-- http://jaist.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6/eaccelerator-0.9.6.tar.bz2

Resolvingjaist.dl.sourceforge.net... 150.65.7.130, 2001:df0:2ed:Feed::Feed

Connectingto jaist.dl.sourceforge.net|150.65.7.130|:80... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:105833 (103K) [application/octet-stream]

Saving to:`eaccelerator-0.9.6.tar.bz2'

100%[===============>]105,833      376K/s   in 0.3s   

2016-09-2814:35:59 (376 KB/s) - `eaccelerator-0.9.6.tar.bz2' saved [105833/105833]

解压软件

[root@localhosttools]# tar jxf eaccelerator-0.9.6.tar.bz2

[root@localhosttools]# cd eaccelerator-0.9.6

[[email protected]]# /application/PHP/bin/PHPize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

编译安装

[[email protected]]# ./configure

--enable-eaccelerator=shared

--with-PHP-config=/application/PHP/bin/PHP-config

creatinglibtool

appendingconfiguration tag "CXX" to libtool

configure:creating ./config.status

config.status:creating config.h

[[email protected]]# echo $?

0

[[email protected]]# make && make install

----------------------------------------------------------------------

Buildcomplete.

Don'tforget to run 'make test'.

Installingshared extensions: /application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

[[email protected]]# ll/application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

total 408

-rwxr-xr-x.1 root root 416805 Sep 28 14:42 eaccelerator.so

安装完成




4、PHP的memcache缓存扩展模块安装


      memcache分:客户端(memcache)与服务端(memcached)


下载软件

[root@localhosttools]# wget http://pecl.PHP.net/get/memcache-2.2.5.tgz

--2016-09-2814:53:05-- http://pecl.PHP.net/get/memcache-2.2.5.tgz

Resolvingpecl.PHP.net... 104.236.228.160

Connectingto pecl.PHP.net|104.236.228.160|:80... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:35981 (35K) [application/octet-stream]

Saving to:`memcache-2.2.5.tgz'

100%[============>]35,981      34.5K/s   in 1.0s   

2016-09-2814:53:12 (34.5 KB/s) - `memcache-2.2.5.tgz' saved [35981/35981]

[root@localhosttools]# tar zxf memcache-2.2.5.tgz

[root@localhosttools]# cd memcache-2.2.5

[[email protected]]# /application/PHP/bin/PHPize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

编译安装

[[email protected]]# ./configure  --with-PHP-config=/application/PHP/bin/PHP-config

creatinglibtool

appendingconfiguration tag "CXX" to libtool

configure:creating ./config.status

config.status:creating config.h

[[email protected]]# make && make install

Buildcomplete.

Don'tforget to run 'make test'.

Installingshared extensions:    /application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

[[email protected]]# ll/application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

total 652

-rwxr-xr-x.1 root root 416805 Sep 28 14:42 eaccelerator.so

-rwxr-xr-x.1 root root 246688 Sep 28 16:14 memcache.so




5、PDO_MysqL安装

下载软件

[root@localhosttools]# wget http://pecl.PHP.net/get/PDO_MysqL-1.0.2.tgz

--2016-09-2816:17:16-- http://pecl.PHP.net/get/PDO_MysqL-1.0.2.tgz

Resolvingpecl.PHP.net... 104.236.228.160

Connectingto pecl.PHP.net|104.236.228.160|:80... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:14778 (14K) [application/octet-stream]

Saving to:`PDO_MysqL-1.0.2.tgz'

100%[===========>]14,778      54.5K/s   in 0.3s   

2016-09-2816:17:27 (54.5 KB/s) - `PDO_MysqL-1.0.2.tgz' saved [14778/14778]

解压软件

[root@localhosttools]# tar zxf PDO_MysqL-1.0.2.tgz

[root@localhosttools]# cd PDO_MysqL-1.0.2

[root@localhostPDO_MysqL-1.0.2]# /application/PHP/bin/PHPize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

config.m4:104:warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicIoUs cache-id, must contain_cv_ to be cached

../../lib/autoconf/general.m4:1974:AC_CACHE_VAL is expanded from...

../../lib/autoconf/general.m4:1994:AC_CACHE_CHECK is expanded from...

aclocal.m4:2754:PHP_CHECK_PDO_INCLUDES is expanded from...

config.m4:104:the top level

config.m4:104:warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicIoUs cache-id, must contain_cv_ to be cached

../../lib/autoconf/general.m4:1974:AC_CACHE_VAL is expanded from...

../../lib/autoconf/general.m4:1994:AC_CACHE_CHECK is expanded from...

aclocal.m4:2754:PHP_CHECK_PDO_INCLUDES is expanded from...

config.m4:104:the top level

编译安装

[root@localhostPDO_MysqL-1.0.2]# ./configure --with-PHP-config=/application/PHP/bin/PHP-config

--with-pdo-MysqL=/application/MysqL/

creatinglibtool

appendingconfiguration tag "CXX" to libtool

configure:creating ./config.status

config.status:creating config.h

[root@localhostPDO_MysqL-1.0.2]# make && make install

----------------------------------------------------------------------

Buildcomplete.

Don'tforget to run 'make test'.

Installingshared extensions:    /application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

[root@localhostPDO_MysqL-1.0.2]# ll/application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

total 808

-rwxr-xr-x.1 root root 416805 Sep 28 14:42 eaccelerator.so

-rwxr-xr-x.1 root root 246688 Sep 28 16:14 memcache.so

-rwxr-xr-x.1 root root 157356 Sep 28 16:21 pdo_MysqL.so




6、图像处理程序及imagick扩展模块安装


     imagick扩展模块依赖于ImageMagick这个软件,因此需要下载两个软件,先安装ImageMagick这个软件,后装imagick扩展模块


下载软件

[root@localhosttools]# wget --no-check-certificatehttps://sourceforge.net/projects/imagemagick/files/old-sources/6.x/6.5/ImageMagick-6.5.1-10.tar.gz/download

--2016-09-2817:06:08-- http://jaist.dl.sourceforge.net/project/imagemagick/old-sources/6.x/6.5/ImageMagick-6.5.1-10.tar.gz

Resolvingjaist.dl.sourceforge.net... 150.65.7.130, 2001:df0:2ed:Feed::Feed

Connectingto jaist.dl.sourceforge.net|150.65.7.130|:80... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:11139020 (11M) [application/x-gzip]

Saving to:`ImageMagick-6.5.1-10.tar.gz'

100%[=========================>]11,139,020   127K/s   in 86s    

2016-09-2817:07:41 (126 KB/s) - `ImageMagick-6.5.1-10.tar.gz' saved [11139020/11139020]

解压编译安装

[root@localhosttools]# tar zxf ImageMagick-6.5.1-10.tar.gz

[root@localhosttools]# cd ImageMagick-6.5.1-10

[root@localhostimageMagick-6.5.1-10]# ./configure

  PCFLAGS       = -fopenmp

  DEFS         = -DHAVE_CONfig_H

  LDFLAGS         = -lfreetype

  MAGICK_LDFLAGS  = -L/usr/local/lib -lfreetype

  LIBS            = -lMagickCore -lfreetype -ljpeg-lfontconfig -lX11 -lz -lm -lgomp -lpthread

  CXX             = g++

  CXXFLAGS        = -g -O2 -Wall -W -pthread

[root@localhostimageMagick-6.5.1-10]# make && make install

下载软件

[root@localhosttools]# wget http://pecl.PHP.net/get/imagick-2.3.0.tgz

--2016-09-2816:50:50-- http://pecl.PHP.net/get/imagick-2.3.0.tgz

Resolvingpecl.PHP.net... 104.236.228.160

Connectingto pecl.PHP.net|104.236.228.160|:80... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:86976 (85K) [application/octet-stream]

Saving to:`imagick-2.3.0.tgz'

100%[======================>]86,976      77.9K/s   in 1.1s   

2016-09-2816:50:57 (77.9 KB/s) - `imagick-2.3.0.tgz' saved [86976/86976]

解压编译安装

[root@localhosttools]# tar zxf imagick-2.3.0.tgz

[root@localhosttools]# cd imagick-2.3.0

[[email protected]]# /application/PHP/bin/PHPize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

[[email protected]]# ./configure

--with-PHP-config=/application/PHP/bin/PHP-config

creatinglibtool

appendingconfiguration tag "CXX" to libtool

configure:creating ./config.status

config.status:creating config.h

[[email protected]]# make && make install

----------------------------------------------------------------------

Buildcomplete.

Don'tforget to run 'make test'.

Installingshared extensions:    /application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

[[email protected]]# ll /application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/

total 1856

-rwxr-xr-x.1 root root  416805 Sep 28 14:42eaccelerator.so

-rwxr-xr-x.1 root root 1071009 Sep 28 17:22 imagick.so

-rwxr-xr-x.1 root root  246688 Sep 28 16:14memcache.so

-rwxr-xr-x.1 root root  157356 Sep 28 16:21pdo_MysqL.so




7、配置PHP的扩展插件

[root@localhost~]# cd /application/PHP/lib/       

操作前备份

[root@localhostlib]# cp PHP.ini PHP.ini.bak.0929

[root@localhostlib]# ls

PHP  PHP.ini PHP.ini.bak.0929

[root@localhost lib]#vi PHP.ini

; Thedirectory under which PHP opens the script using /~username used only

; ifnonempty.

;http://PHP.net/user-dir

user_dir =

; Directoryin which the loadable extensions (modules) reside.

;http://PHP.net/extension-dir

;extension_dir= "./"  

修改目录路径

extension_dir ="/application/PHP-5.3.27/lib/PHP/extensions/no-debug-non-zts-20090626/"

; Onwindows:

;extension_dir = "ext"

然后到文件内容的结尾增加如下配置

;PHP cacheconfig start

extension =memcache.so

 extension = pdo_MysqL.so

 extension = imagick.so

;PHP cacheconfig end by root 2016-09-29

注意,PHP配置文件中注释是用;而不是#号 


配置缓存插件eaccelerator

创建临时缓存目录

[root@localhostlib]# mkdir -p /tmp/eaccelerator

[root@localhostlib]# chown -R Nginx.Nginx /tmp/eaccelerator/


   生产环境当中可以将此文件放在内存文件系统(tmpfs)中存储,提高并发时的速度,也可以存放在固态硬盘中


[root@localhostlib]# cat >> /application/PHP/lib/PHP.ini<<EOF

>[eaccelerator]

>extension=eaccelerator.so

>eaccelerator.shm_size="64"

>eaccelerator.cache_dir="/tmp/eaccelerator"

>eaccelerator.enable="1"

>eaccelerator.optimizer="1"

>eaccelerator.check_mtime="1"

>eaccelerator.debug="0"

>eaccelerator.filter=""

>eaccelerator.shm_max="0"

>eaccelerator.shm_ttl="3600"

>eaccelerator.shm_prune_period="3600"

>eaccelerator.shm_only="0"

>eaccelerator.compress="1"

>eaccelerator.compress_level="9"

> EOF

检查配置

[root@localhostlib]# tail -25 /application/PHP/lib/PHP.ini

; LocalVariables:

;tab-width: 4

; End:

;PHP cacheconfig start

extension =memcache.so

 extension = pdo_MysqL.so

 extension = imagick.so

;PHP cacheconfig end by root 2016-09-29

[eaccelerator]

extension=eaccelerator.so

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"




8、测试缓存加速

查看eaccelerator

[root@localhostlib]# /application/PHP/bin/PHP -v

PHP 5.3.27(cli) (built: Sep 27 2016 15:15:29)

copyright(c) 1997-2013 The PHP Group

Zend Enginev2.3.0, copyright (c) 1998-2013 Zend Technologies

    with eAccelerator v0.9.6, copyright (c)2004-2010 eAccelerator, by eAccelerator

[root@localhostlib]# tree /tmp/eaccelerator/

/tmp/eaccelerator/

|-- 0

|   |-- 0

|   |-- 1

|   |-- b

|   |-- c

|   |-- d

|   |-- e

|   `-- f

|-- 5          

--------------------------->中间部分内容省略

检查语法

[root@localhostlib]# /application/PHP/sbin/PHP-fpm -t

[29-Sep-201606:47:18] NOTICE: configuration file /application/PHP-5.3.27/etc/PHP-fpm.conftest is successful

重启服务

[root@localhostlib]# pkill PHP-fpm

[root@localhostlib]# /application/PHP/sbin/PHP-fpm  

访问PHP站点

[root@localhostlib]# tree /tmp/eaccelerator/                                       

/tmp/eaccelerator/

|-- 4

|   |  |-- eaccelerator-86746.052265

|   |  |-- eaccelerator-86746.242265

|   |  |-- eaccelerator-86746.252265

|   |  |-- eaccelerator-86746.352265

|   |  |-- eaccelerator-86746.442265

|   |  |-- eaccelerator-86746.452265

|   |  |-- eaccelerator-86746.542265

|   |  |-- eaccelerator-86746.552265

|   |  |-- eaccelerator-86746.642265

|   |   `--eaccelerator-86746.742265

|   |-- 5

|   |  |-- eaccelerator-86746.115265

|   |  |-- eaccelerator-86746.205265

|   |  |-- eaccelerator-86746.305265

|   |  |-- eaccelerator-86746.705265

|   |  |-- eaccelerator-86746.805265

|   |  `-- eaccelerator-86746.905265

|   |-- 7            -

----------------------------->部分内容省略

已经有缓存文件生成


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐