编程语言
首页 > 编程语言> > LNMP架构应用实战——PHP扩展及缓存插件安装

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




3、PHP的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

[root@localhosteaccelerator-0.9.6]# /application/php/bin/phpize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

编译安装

[root@localhosteaccelerator-0.9.6]# ./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

[root@localhosteaccelerator-0.9.6]# echo $?

0

[root@localhosteaccelerator-0.9.6]# 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@localhosteaccelerator-0.9.6]# 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

[root@localhostmemcache-2.2.5]# /application/php/bin/phpize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

编译安装

[root@localhostmemcache-2.2.5]# ./configure  --with-php-config=/application/php/bin/php-config

creatinglibtool

appendingconfiguration tag "CXX" to libtool

configure:creating ./config.status

config.status:creating config.h

[root@localhostmemcache-2.2.5]# 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@localhostmemcache-2.2.5]# 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

[root@localhostimagick-2.3.0]# /application/php/bin/phpize

Configuringfor:

PHP ApiVersion:         20090626

Zend ModuleApi No:      20090626

ZendExtension Api No:   220090626

[root@localhostimagick-2.3.0]# ./configure

--with-php-config=/application/php/bin/php-config

creatinglibtool

appendingconfiguration tag "CXX" to libtool

configure:creating ./config.status

config.status:creating config.h

[root@localhostimagick-2.3.0]# 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@localhostimagick-2.3.0]# 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            -

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

已经有缓存文件生成


标签:插件,php,--,LNMP,application,net,PHP,root,eaccelerator
来源: https://blog.51cto.com/15127557/2670195