编译安装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. 系统环境及服务版 ...
随机推荐
- easyUI-右键菜单,关闭选项卡
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Lucene 的四大索引查询 ——bool 域搜索 通配符 范围搜索
Lucene 的四大索引查询 清单1:使用布尔操作符 Java代码 //Test boolean operator blic void testOperator(String indexD ...
- 推箱子 hdu1254
推箱子 1 http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 2 http://acm.hzau.edu.cn/problem.php?id=1 ...
- iOS 开发图片资源选择png格式还是jpg格式
对于iOS本地应用程序来说最简单的答案就是始终使用PNG,除非你有非常非常好的理由不用它. 当iOS应用构建的时候,Xcode会通过一种方式优化.png文件而不会优化其它文件格式.它优化得相当的好 他 ...
- CreateRemoteThread注入DLL
DLL注入的常用方式之一远程线程注入,实现代码如下 // CreateRemoteThread.cpp : Defines the entry point for the application.// ...
- 【旧文章搬运】CsrssWalker学习笔记
原文发表于百度空间及看雪论坛,2009-05-13 看雪论坛地址:https://bbs.pediy.com/thread-89708.htm============================= ...
- POJ 1737 经典DP
问题:求含有n个点的连通图的个数. 解: 考虑DP,$f(n)$表示n个点,每个点都和点1相连,且n个点互相连通的图的个数. (蓝字非常重要,这个条件有效地避免了重复计算) $g(n)$表示n个点,每 ...
- ccflow_002.表单引擎与流程引擎的关系
本节主要内容 表单.数据.流程引擎的关系 图形展示三者之间的关系 流程编号和节点编号命名规则 这里的206就是这个流程的编号 2601:01就是当前节点的编号 流程编号206转换为int类型之后加上0 ...
- 斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时26&&27
课时26 图像分割与注意力模型(上) 语义分割:我们有输入图像和固定的几个图像分类,任务是我们想要输入一个图像,然后我们要标记每个像素所属的标签为固定数据类中的一个 使用卷积神经,网络为每个小区块进行 ...
- 利用ASP .NET Core的静态文件原理实现远程访问Nlog日志内容及解决遇到的坑
最近项目上试运行发现,很多时候网站出了问题或者某个功能不正常,常常需要运维人员去服务器里面查看一下日志,看看日志里面会产生什么异常,这样导致每次都要去远程服务器很不方便,有时服务器是客户保管的不能让我 ...