1. 下载并安装PHP

1.1 编译安装

1.1.1 安装前的准备

 下载并安装libmcrypt 和 libmcrypt-devel
[root@test /opt/soft]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/csbuild:/centosextra/CentOS_CentOS-6/x86_64/libmcrypt-devel-2.5.8-4.3.x86_64.rpm
[root@test /opt/soft]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/csbuild:/centosextra/CentOS_CentOS-6/x86_64/libmcrypt-2.5.8-4.3.x86_64.rpm [root@test /opt/soft]# rpm -ivh libmcrypt-*
warning: libmcrypt-2.5.-4.3.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 04b8b50a: NOKEY
Preparing... ########################################### [%]
:libmcrypt ########################################### [ %]
:libmcrypt-devel ########################################### [%]
建议:使用yum源epel来安装 libmcypt 和 libmcypt-devel,推荐使用aliyun的yum源
  [epel]
  name=epel
  mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-$releasever&arch=$basearch
  enabled=1
  gpgcheck=0

安装开发工具组和必要的编译软件包
[root@test /opt/soft]# yum groupinstall -y "Development Tools"
[root@test /opt/soft]# yum -y install autoconf automake bzip2 bzip2-devel curl curl curl-devel e2fsprogs e2fsprogs-devel freetype freetype-devel gcc gcc-c++ gd gettext glib2 glib2-devel glibc glibc-devel krb5-devel krb5-libs krb5-workstation libiconv libiconv-devel libidn libidn-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libxslt libxslt-devel libxml2 libxml2-devel libXpm libXpm-devel mhash mhash-devel ncurses ncurses-devel nss-pam-ldapd openldap openldap-clients openldap-devel openldap-servers openssl openssl-devel t1lib t1lib-devel zlib zlib-devel

1.1.2 下载PHP

[root@test /opt]# wget http://cn2.php.net/distributions/php-5.3.29.tar.gz
[root@test /opt]# tar xf php-5.3.29.tar.gz

1.1.3 编译安装

[root@test /opt/php-5.3.29]# ./configure --prefix=/usr/local/php --disable-rpath --enable-bcmath --enable-calendar --enable-dba --enable-debug --enable-embed=fpm --enable-exif --enable-fpm --enable-ftp --enable-gd-jis-conv --enable-gd-native-ttf --enable-inline-optimization --enable-intl=shared --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-pdo --enable-shmop --enable-short-tags --enable-soap --enable-sockets --enable-static --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-xml --enable-zend-multibyte --enable-zip --infodir=/usr/local/share/info --mandir=/usr/local/share/man --with-bz2 --with-config-file-path=/usr/local/php/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-imap --with-imap-ssl --with-jpeg-dir --with-kerberos --with-libxml-dir --with-mcrypt --with-mhash --with-mysql=/usr/local/mysql --with-openssl --with-pcre-regex --with-pear --with-png-dir --with-t1lib --with-xmlrpc --with-xpm-dir --with-xsl --with-zlib --with-fpm-user=nginx --with-fpm-group=nginx
这里需要注意的是--with-mysql这个参数:
  如果不指定,php默认使用php自带mysql库文件即--with-mysql=mysqldn,
  如果指定,就需要赋予mysql的base目录路径。(--with-mysqli 和 --with-pdo-mysql 后面以扩展的方式安装)

可能遇到的一些错误:

1. configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing
这个是由于编译加入了imap支持需要使用c-client库

解决方法:
[root@test /opt/php-5.3.29]# yum install -y libc-client libc-client-devel
2. configure: error: libXpm.(a|so) not found.
解决方法:
[root@test /opt/php-5.3.29]# ln -s /usr/lib64/libXpm.so* /usr/lib/ Cannot find imap library (libc-client.a).
解决方法:
[root@test /opt/php-5.3.29]# ln -s /usr/lib64/libc-client.so* /usr/lib/
3. configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
解决方法:
[root@test /opt/php-5.3.29]# yum install libicu-devel libicu
. [...]/sapi/cli/php:error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决方法:
[root@test /opt/php-5.3.29]# ln -s 【mysql的base目录】/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

[root@test /opt/php-5.3.29]# echo "【mysql的base目录】/lib/libmysqlclient.so.18" > /etc/ld.so.conf.d/mysql-x86_64.conf
[root@test /opt/php-5.3.29]# ldconfig

安装完成:

...
configure: creating ./config.status
creating main/internal_functions.c
creating 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. config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.
config.status: creating sapi/cli/php.
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.
config.status: creating ext/phar/phar.
config.status: creating ext/phar/phar.phar.
config.status: creating main/php_config.h
config.status: executing default commands

编译完成提示信息

[root@test /opt/php-5.3.29]# make install

编译时可能出现的错误:--(这种情况出现在使用mysql的二进制包,没有找到库文件libmysqlclient.so.18)
/opt/php-5.3.29/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or director
make: *** [ext/phar/phar.phar] Error 127
[root@test /opt/php-5.3.29]#
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so.18
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so.18
[root@test /usr/lib]# ldconfig
清理已经编译过文件,重新编译
[root@test /opt/php-5.3.29]# make clean;make PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
...
Installing shared extensions: /usr/local/php/lib/php/extensions/debug-zts-/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/share/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM config: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/share/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/share/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/share/man/man1/
page: phpize.
page: php-config.
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.
[PEAR] Console_Getopt - installed: 1.4.
[PEAR] Structures_Graph- installed: 1.1.
[PEAR] XML_Util - installed: 1.3.
[PEAR] PEAR - installed: 1.10.
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/opt/php-5.6./build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo

安装完成的提示信息

编译安装memcache扩展,此步骤非必须:
wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar xf memcache-2.2.7.tar.gz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install 编译安装eaccelerator扩展
wget http://ufpr.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
tar xf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpiz
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install 编译安装mysqli
cd php-5.3.29/ext/mysqli
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install 编译安装pdo_mysql
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
/usr/local/php/bin/phpiz
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr
make
make install

1.2 相关设置

设置php.ini文件,这里需要注意的是,因为在编译时,我修改了php配置文件目录路径,所以存放时要放在编译时制定的目录--with-config-file-path=/usr/local/php/etc,而不是默认目录:

查看默认目录:
[root@test /opt/php-5.3.29]# ./configure --help | grep -B php.ini
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
拷贝到制定的配置文件目录中:
[root@test /opt/php-5.3.29]# cp php.ini-production /usr/local/php/etc/php.ini

编辑Nginx配置文件,添加以下配置(蓝色部分内容):

[root@test /usr/local/nginx]# egrep -v "^$|#"  conf/nginx.conf
user nginx;
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name localhost;
location / {
root html;
index index.html index.htm;
} location ~* \.php$ {
fastcgi_pass 127.0.0.1:
;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}

error_page /50x.html;
location = /50x.html {
root html;
}
}
}

PS:  nginx的SPEC打包安装:http://www.cnblogs.com/jonsea/p/5481580.html

mysql 5.7.12安装:http://www.cnblogs.com/jonsea/p/5503267.html

2. 启动php-fm

制作服务脚本并启动php-fpm:

方法1----拷贝源文件中的制作好的脚本

[root@test /opt/php-5.3.29]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@test /opt/php-5.3.29]# chmod 755 /etc/rc.d/init.d/php-fpm

[root@test /opt/php-5.3.29]# /etc/init.d/php-fpm start
Starting php-fpm done [root@test /opt/php-5.3.29]# ps -ef | grep php-fpm
root 9410 1 0 17:53 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 9411 9410 0 17:53 ? 00:00:00 php-fpm: pool www
nobody 9412 9410 0 17:53 ? 00:00:00 php-fpm: pool www [root@test ~]# netstat -anlp | grep php-fpm
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      9533/php-fpm [root@test /opt/php-5.3.29]# /etc/init.d/php-fpm stop
Gracefully shutting down php-fpm . done
[root@test /opt/php-5.3.29]# chkconfig --add php-fpm --level 

方法2----制作启动脚本(推荐)

#!/bin/bash
# php-fpm startup script for php-fpm
#
# chconfig: -
# processname: php-fpm
#
### BEGIN INIT INFO
# Default-Start :
# Default-Sop:
# Short-Description: start and stop php-fpm
### END INIT INFO # Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm}) lockfile=/var/lock/subsys/phpfpm start() {
[ -x ${phpfpm} ] || exit
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
${phpfpm} -t
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit
esac

php-fpm脚本内容

[root@test /opt/php-5.3.29]# /etc/init.d/fpm start
Starting php-fpm: [ OK ] [root@test /opt/php-5.3.29]# ps -ef | grep php-fpm
root : ? :: php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody : ? :: php-fpm: pool www
nobody : ? :: php-fpm: pool www [root@test /opt/php-5.3.29]# /etc/init.d/fpm stop
Stopping php-fpm: [ OK ]

3. 测试web和数据库链接

web测试代码和mysql测试代码

[root@test /usr/local/nginx/html]# cat t.php
<?php
phpinfo();
?> [root@test /usr/local/nginx/html]# cat m.php
<?php
$link=mysql_connect("localhost","root","【你的mysql账户密码】");
if(!$link) echo "FAILD!连接错误,用户名密码不对";
else echo "OK!可以连接";
?>

测试通过!!!

php-fpm 的安装与LNMP测试的更多相关文章

  1. CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)

    CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: /etc/init.d/iptables stop #关闭防火墙 关闭SELINUX vi /etc/sel ...

  2. CentOS 6.5 yum安装配置lnmp服务器(Nginx+PHP+MySQL)

    以下全部转载于  http://blog.csdn.net/lane_l/article/details/20235909 本人于今晚按照该文章使用centos 6.7 64bit安装成功,做个备份, ...

  3. CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)

    准备篇 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dp ...

  4. 在ConoHa上Centos7环境下源码安装部署LNMP

    本文记录了从源码,在Centos 7上手动部署LNMP环境的过程,为了方便以后对nginx和mariadb进行升级,这里采用yum的方式进行安装. 1.建立运行网站和数据库的用户和组 groupadd ...

  5. centos7 编译安装新版LNMP环境

    centos7 编译安装新版LNMP环境 环境版本如下: 1.系统环境:Centos 7 x86_64 2.NGINX:nginx-1.11.3.tar.gz 3.数据库:mariadb-10.0.2 ...

  6. centos7源码编译安装lamp/lnmp

    centos7源码编译安装lamp/lnmp 进程:是包工头(相当于是个门,只管开门关门,不管门内的事儿) 线程:是各种工种(cpu调度的是线程) 进程 是一件事情, 线程 是 同一个时间范围内 同时 ...

  7. centos 6.5 + php5.5.31 fastcgi (fpm) 编译安装

    yum intsall zlib zlib-devel //gzip 压缩和解压 yum install openssl openssl-devel yum install libxml2 libxm ...

  8. Nginx安装部署与测试

    场景:项目需要部署在生产环境中,这些新的工具都需要在生产环境中去实践练习.有时间再部署一套ELK的日志分析系统,这样的系统才算具有一定的应用价值. 1 Nginx安装 用root用户安装,采用源代码编 ...

  9. ActiveMQ (一):安装启动及测试

    1. 预备知识 1.1 JMS JMS(Java Messaging Service)是Java平台上有关面向消息中间件(MOM)的技术规范.<百科> 1.2 JMX JMX(Java M ...

随机推荐

  1. CodeForces 450

    A - Jzzhu and Children Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & % ...

  2. 【转】Android 4.3源码的下载和编译环境的安装及编译

    原文网址:http://jingyan.baidu.com/article/c85b7a641200e0003bac95a3.html  告诉windows用户一个不好的消息,windows环境下没法 ...

  3. word 中Sentences、Paragraph等含义和用法

    word 中有Words,Characters,Sentences.Paragraph,Sections 具体含义如下表达式             含义   返回的对象 Words(index)  ...

  4. 【原】Redis学习资料推荐

    Redis学习资料推荐 网址: Redis官网http://redis.io/ Redis命令 http://redis.io/commands Redis教程 https://www.tutoria ...

  5. oracle创建临时表

    Oracle临时表可以说是提高数据库处理性能的好方法,在没有必要存储时,只存储在Oracle临时表空间中.希望本文能对大家有所帮助. 1 .前言 目前所有使用 Oracle 作为数据库支撑平台的应用, ...

  6. BZOJ1997 [Hnoi2010]Planar (2-sat)

    题意:给你一个哈密顿图,判断是不是平面图 思路:先找出哈密顿图来.哈密顿回路可以看成一个环,把边集划分成两个集合,一个在环内,一个在外.如果有两条相交边在环内,则一定不是平面图,所以默认两条相交边,转 ...

  7. leetcode—triangle

    1.题目描述 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adj ...

  8. HW2.20

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  9. HW2.4

    import java.util.Scanner; public class Solution { public static void main(String[] args) { final dou ...

  10. POJ2739 - Sum of Consecutive Prime Numbers(素数问题)

    题目大意 给定N,要求你计算用连续的素数的和能够组成N的种数 题解 先筛选出素数,然后暴力判断即可... 代码: #include<iostream> #include<cstrin ...