编译安装LAMP之php(fpm模块)
一,准备工作
实验平台为CentOS6.6,先下载所需的安装包,我使用的是php-5.4.26.tar.gz,下载地址 http://mirrors.sohu.com/php/
编译安装的目录:/usr/local/
二,编译及配置php-5.4.26
1,编译安装php-5.4.26
[root@localhost ~]# tar xf php-5.4.26.tar.gz[root@localhost ~]# cd php-5.4.26/[root@localhost 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=/usr/local/zlib/ --with-libxml-dir=/usr/local/libxml2/ --enable-xml --enable-sockets --with-mcrypt=/usr/local/libmcrypt/ --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm选项解释:--prefix=/usr/local/php指定 php 安装目录--with-apxs2=/usr/local/apache/bin/apxs整合 apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块--with-config-file-path=/usr/local/php/etc指定php.ini位置--with-MySQL=/usr/local/mysqlmysql安装目录,对mysql的支持--with-mysqli=/usr/local/mysql/bin/mysql_configmysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。--enable-safe-mode 打开安全模式--enable-ftp 打开ftp的支持--enable-zip 打开对zip的支持--with-bz2 打开对bz2文件的支持--with-jpeg-dir 打开对jpeg图片的支持--with-png-dir 打开对png图片的支持--with-freetype-dir 打开对freetype字体库的支持--without-iconv 关闭iconv函数,种字符集间的转换--with-libXML-dir 打开libxml2库的支持--with-XMLrpc 打开xml-rpc的c语言--with-zlib-dir 打开zlib库的支持--with-gd 打开gd库的支持--enable-gd-native-ttf 支持TrueType字符串函数库--with-curl 打开curl浏览工具的支持--with-curlwrappers 运用curl工具打开url流--with-ttf 打开freetype1.*的支持,可以不加了--with-xsl 打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件--with-gettext 打开gnu 的gettext 支持,编码库用到--with-pear 打开pear命令的支持,PHP扩展用的--enable-calendar 打开日历扩展功能--enable-mbstring 多字节,字符串的支持--enable-bcmath 打开图片大小调整,用到zabbix监控的时候用到了这个模块--enable-sockets 打开 sockets 支持--enable-exif 图片的元数据支持--enable-magic-quotes 魔术引用的支持--disable-rpath 关闭额外的运行库文件--disable-debug 关闭调试模式--with-mime-magic=/usr/share/file/magic.mime 魔术头文件位置CGI方式安装才用的参数--enable-fpm打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序--enable-fastCGI支持fastcgi方式启动PHP--enable-force-CGI-redirect重定向方式启动PHP--with-ncurses支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库--enable-pcntl freeTDS需要用到的,可能是链接mssql 才用到mhash和mcrypt算法的扩展--with-mcrypt 算法--with-mhash 算法
出现错误:
configure: error: xml2-config not found. Please check your libxml2 installation.
解决方法:
去官网 http://xmlsoft.org/sources/下载源码。我用的版本是libxml2-2.9.0.tar.gz, 执行命令:
[root@localhost ~]# tar -zxvf libxml2-2.9.0.tar.gz[root@localhost ~]# cd libxml2-2.9.0/[root@localhost ~]# ./configure --prefix=/usr/local/libxml2/[root@localhost ~]# make && make install
重新编译,编译时修改选项为–with-libxml-dir=/usr/local/libxml2,
[root@localhost 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=/usr/local/zlib/ --with-libxml-dir=/usr/local/libxml2/ --enable-xml --enable-sockets --with-mcrypt=/usr/local/libmcrypt/ --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm
出现错误:
configure: error: Cannot find libz
解决方法:
去网址 http://www.zlib.net/下载zlib源码,我下的是zlib-1.2.8.tar.gz,执行命令:
[root@localhost ~]# tar -zxvf zlib-1.2.8.tar.gz[root@localhost ~]# cd zlib-1.2.8/[root@localhost ~]# ./configure --prefix=/usr/local/zlib[root@localhost ~]# mak && make install
重新编译,编译时修改选项为–with-zlib-dir=/usr/local/zlib
[root@localhost 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=/usr/local/zlib/ --with-libxml-dir=/usr/local/libxml2/ --enable-xml --enable-sockets --with-mcrypt=/usr/local/libmcrypt/ --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm
出现错误:
configure: error: Please reinstall the BZip2 distribution
解决方法:
去网站 http://www.bzip.org/downloads.html下载源码,我用的是bzip2-1.0.6.tar.gz ,执行命令:
[root@localhost ~]# tar -zxvf bzip2-1.0.6.tar.gz[root@localhost ~]# cd bzip2-1.0.6/[root@localhost ~]# make && make install ---->没有configure文件,此处不用执行./configure ,
重新编译,不用修改选项:
[root@localhost 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=/usr/local/zlib/ --with-libxml-dir=/usr/local/libxml2/ --enable-xml --enable-sockets --with-mcrypt=/usr/local/libmcrypt/ --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm
出现错误:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:
去网站 http://mcrypt.hellug.gr/lib/index.html的下载源码,我下的是libmcrypt-2.5.8.tar.bz2 ;执行命令:
[root@localhost ~]# tar -zxvf libmcrypt-2.5.8.tar.bz2[root@localhost ~]# cd libmcrypt-2.5.8/[root@localhost ~]# ./configure prefix=/usr/local/libmcrypt/[root@localhost ~]# make && make install
重新编译,修改参数为–with-mcrypt=/usr/local/libmcrypt
[root@localhost 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=/usr/local/zlib/ --with-libxml-dir=/usr/local/libxml2/ --enable-xml --enable-sockets --with-mcrypt=/usr/local/libmcrypt/ --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm。。。。。。。。。。。。。。。。Generating filesconfigure: creating ./config.statuscreating main/internal_functions.ccreating main/internal_functions_cli.c+--------------------------------------------------------------------+| License: || This software is subject to the PHP License, available in this || distribution in the file LICENSE. By continuing this installation || process, you are bound by the terms of this license agreement. || If you do not agree with the terms of this license, you must abort || the installation process at this point. |+--------------------------------------------------------------------+Thank you for using PHP.
这次编译就不会再出问题了,出现以上界面就是成功了。然后执行:
[root@localhost php-5.4.26]# make && make install
为php提供配置文件,php源码解压后的目录里有两个文件php.ini-development 和php.ini-production ,一个开发环境下使用的,一个为生产环境下使用的,我们需要的是php.ini-production:
[root@localhost php-5.4.26]# cp php.ini-production /etc/php.ini
2,配置php-fpm
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
[root@localhost php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm[root@localhost php-5.4.26]# chmod +x /etc/init.d/php-fpm[root@localhost php-5.4.26]# chkconfig --add php-fpm[root@localhost php-5.4.26]# chkconfig php-fpm on
为php-fpm提供配置文件:
[root@localhost php-5.4.26]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件,配置fpm的相关选项为你所需要的值,并启用pid文件:
[root@localhost php-5.4.26]# vim /usr/local/php/etc/php-fpm.conf25 pid = run/php-fpm.pid #定义pid文件,在/usr/local/php/var/run/,启用即可,不需修改,要修改必须和/etc/rc.d/init.d/php-fpm中的定义一块修改。225 pm.max_children = 100 #最多有多少个子进程230 pm.start_servers = 10 #刚开始启动多少个空闲进程235 pm.min_spare_servers = 5240 pm.max_spare_servers = 20
接下来就可以启动php-fpm了:
[root@localhost conf]# service php-fpm startStarting php-fpm done
其监听在127.0.0.1:9000,会启动n个空闲进程
[root@localhost feiyu.com]# netstat -tlnup |grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16325/php-fpm
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
[root@localhost feiyu.com]# ps aux |grep php-fpm |wc -l12
3、 编辑apache配置文件httpd.conf,使apache支持php
[root@localhost ~]# vim /etc/httpd/httpd.conf #添加如下二行381 AddType application/x-httpd-php .php #支持.php结尾的文件382 AddType application/x-httpd-php-source .phps #支持源码文件
定位至DirectoryIndex index.html ,修改为:
251 DirectoryIndex index.php index.html
未配置此项则会显示源码,如下图:

而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
四、安装xcache,为php加速,(注:2.0以后的版本对于php5.0以后的支持)
1、安装,本次使用的是xcache-3.2.0.tar.gz
[root@localhost ~]# tar xf xcache-3.2.0.tar.gz[root@localhost ~]# cd xcache-3.2.0[root@localhost xcache-3.2.0]# /usr/local/php/bin/phpize #php有很多扩展功能,用phpize给PHP动态添加扩展Configuring for:PHP Api Version: 20100412Zend Module Api No: 20100525Zend Extension Api No: 220100525如果出现下面的情况,此时需要安装m4和autoconf这两个包![root@localhost xcache-3.2.0]# /usr/local/php/bin/phpizeConfiguring for:PHP Api Version: 20100412Zend Module Api No: 20100525Zend Extension Api No: 220100525Cannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then, rerun this script.[root@localhost xcache-3.2.0]# yum install autoconf m4 -y[root@localhost xcache-3.2.0]# /usr/local/php/bin/phpize #重新执行此步骤[root@localhost xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config[root@localhost xcache-3.2.0]# make[root@www xcache-3.2.0]# make install。。。。。Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/ ------>最后一行会出现
2、编辑php.ini,整合php和xcache:使php支持xcache的功能
首先将xcache提供的样例配置导入php.ini
[root@localhost xcache-3.2.0] # mkdir /etc/php.d[root@localhost xcache-3.2.0] # cp xcache.ini /etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so ----->复制make install 后出现的代码
注意:如果php.ini文件中有多条extension指令行,要确保此新增的行排在第一位。
然后重启php-fpm生效
(注:xcache-3.2.0已将zend_extension改为extension,也不用编辑此行了,它能自动找到并生效)。
五,测试
1,首先测试php是否成功连接到数据库
首先启动数据库,设置数据库密码为123:
[root@localhost html]# service mysqld start[root@localhost html]# mysqladmin -uroot password '123'[root@localhost html]# cd /var/www/html/
[root@localhost html]# vim index.php
<?php
$link = mysql_connect(“192.168.0.147″,”root”,”123456″);
if(!$link)
echo “success”;
else
echo “failer”;
?>
刷新浏览器,出现success则成功:

2,再测试php是否成功启用
[root@localhost html]# vim index.php
<?php
phpinfo();
?>
然后打开网页,输入本机IP,出现以下画面则成功。

3,测试xcache
重新启动php-fpm,
[root@localhost ~]# service php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm done
刷新网页找xcache模块,

[root@localhost ~]# netstat -tlnupActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1848/sshdtcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1723/cupsdtcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2062/mastertcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16897/php-fpmtcp 0 0 :::22 :::* LISTEN 1848/sshdtcp 0 0 ::1:631 :::* LISTEN 1723/cupsdtcp 0 0 ::1:25 :::* LISTEN 2062/mastertcp 0 0 :::3306 :::* LISTEN 24509/mysqldtcp 0 0 :::80 :::* LISTEN 16368/httpdudp 0 0 0.0.0.0:68 0.0.0.0:* 24809/dhclientudp 0 0 0.0.0.0:631 0.0.0.0:* 1723/cupsd
到此,LAMP全部编译完成,当然还没有编译Linux,后续会继续更新。
在测试php中会可能出现以下问题:
[root@sta wordpress]# tail /var/log/nginx/error.log2015/09/07 15:54:31 [error] 2155#0: *1194 FastCGI sent in stderr: "Access to the script '/usr/html/wordpress/wp-admin/js/language-chooser.min.js' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 222.24.51.74, server: www.xiyousta.com, request: "GET /wordpress/wp-admin/js/language-chooser.min.js?ver=4.3 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "222.24.51.147", referrer: "http://222.24.51.147/wordpress/wp-admin/install.php"
经过查找资料发现 从5.3.9开始,php官方加入了一个配置”security.limit_extensions”,默认状态下只允许执行扩展名为”.php”的文件,造成了其他类型的文件不支持的问题。
所以更改策略如下:
修改/usr/local/php/etc/php-fpm.conf,找到security.limit_extensions把他修改为:
security.limit_extensions=.php .html .js .css .jpg .jpeg .gif .png .htm#(常用的文件扩展名)
然后问题就解决啦!
编译安装LAMP之php(fpm模块)的更多相关文章
- CentOS 6编译安装lamp,并分别安装event模块方式和FPM方式的PHP
任务目标: 编译安装LAMP 要求(1) 安装一个模块化的PHP 要求(2) 安装一个FPM的PHP 注意PHP需要最后一个安装,因为需要前两者的支持. 所以这里的安装次序为 1.httpd 2.Ma ...
- FastCGI模式编译安装LAMP+Xcache
PHP的工作模式:php在lamp环境下共有三种工作模式:CGI模式.apache模块.FastCGI模式.CGI模式下运行PHP,性能不是很好.(已淘汰)FastCGI的方式和apache模块的不同 ...
- 二、编译安装LAMP之httpd-2.4.4
回顾 PHP:脚本编程语言,php解释器 Webapp:面向对象的特性 Zend: 第一段:词法分析.句法分析.编译为Opcode: opcode放置于内存中 第二段:执行opcode: opcode ...
- ubuntu10.04编译安装LAMP
ubuntu10.04编译安装LAMP以及简单wordpress的使用 : http://linuxme.blog.51cto.com/1850814/971631 一.源码安装LAMP 网上有一堆关 ...
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25
所需源码包: /usr/local/src/Apache-2.2.25/httpd-2.2.25.tar.gz 编译安装 Apache2.2.25 #切换到源码目录 cd /usr/local/src ...
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.4.6
Apache官方说: 与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量.更好地支持云计算.利用更少的内存处理更多的并发等.除此之外,还包括性能提升.内 ...
- CentOS6.3 编译安装LAMP(4):编译安装 PHP5.2.17
所需源码包: /usr/local/src/PHP-5.2.17/libmcrypt-2.5.8.tar.gz /usr/local/src/PHP-5.2.17/mhash-0.9.9.9.tar. ...
- CentOS6.3 编译安装LAMP(4):编译安装 PHP5.3.27
所需源码包: /usr/local/src/PHP-5.3.27/libmcrypt-2.5.8.tar.gz /usr/local/src/PHP-5.3.27/mhash-0.9.9.9.tar. ...
- (2)编译安装lamp三部曲之mysql-技术流ken
简介 采用yum安装lamp简单,快捷,在工作中也得到了普遍应用.但是如果我们需要某些特定模块功能,以及制定安装位置等,就需要用到编译安装了,接下来将编译安装lamp之mysql. mysql的简介网 ...
- (1)编译安装lamp三部曲之apache-技术流ken
简介 采用yum安装lamp简单,快捷,在工作中也得到了普遍应用.但是如果我们需要某些特定模块功能,以及制定安装位置等,就需要用到编译安装了,接下来将编译安装lamp之apache. 系统环境及服务版 ...
随机推荐
- CodeForces985F:Isomorphic Strings (字符串&hash)
题意:取出字符串Str里的两个串S,T,问对应位置的的字符在否有一一映射关系. hash:对于每个字符s=‘a’-‘z’,我们任意找一个i,满足Si==s,(代码里用lower_bound在区间找到最 ...
- rtmplib rtmp协议过程分析
转自:http://chenzhenianqing.cn/articles/1009.html 写的很好,收藏如下,向作者致敬! 没事碰到了librtmp库,这个库是ffmpeg的依赖库,用来接收,发 ...
- js 将json字符串转换为json对象的方法解析-转
例如: JSON字符串:var str1 = '{ "name": "cxh", "sex": "man" }'; JS ...
- web服务端的架构演变
此文已由作者肖凡授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 最近Lofter项目碰到很多性能上的问题,特别是数据库相关的,每次推送后,告警就会第一时间到来.这些问题随着产 ...
- iOS View
创建: 2018/04/19 完成: 2018/04/20 View的创建 创建 storyboard上操作 与代码连接 ● 目的: 通过代码控制view ● 按住option拖动 View的坐 ...
- CF1059D Nature Reserve(二分)
简洁翻译: 有N个点,求与y=0相切的,包含这N个点的最小圆的半径 题解 二分半径右端点开小了结果交了二十几次都没A……mmp…… 考虑一下,显然这个半径是可以二分的 再考虑一下,如果所有点都在y轴同 ...
- ASI框架的使用
iOS开发网络篇—简单介绍ASI框架的使用 说明:本文主要介绍网络编程中常用框架ASI的简单使用. 一.ASI简单介绍 ASI:全称是ASIHTTPRequest,外号“HTTP终结者”,功能十分强大 ...
- poj 2412 The Balance 【exgcd】By cellur925
题目传送门 一遇到数学就卡住,我这是怎么肥4...(或许到图论会愉悦吧,逃) Description * 给出两种重量为的 A, B 的砝码,给出一种使用最少的砝码的方式,称出重量 C. 我们可以比较 ...
- USACO Training 3.3 商店购物 By cellur925
题目传送门 这道题有着浓浓的背包气氛.所以我们可以这样想:可以把每个优惠方案都当做一个物品,每个单买所需要花的钱也当做一个物品.(也就是代码中的p结构体数组)而且基于此题的环境,这题是一个完全背包.另 ...
- 桌面应用也可以提供HTTP文件下载
以往,我们肯定知道,在搞Web应用的时候,我们都可能会遇到提供文件下载的功能需求,比如我以前做的一个客户许可证管理系统,客户购买ERP系统后,通常我们会根据客户的机器的机器码生成一个许可文件,而这个许 ...