php-fpm安装包_nginx php-fpm安装配置

本文详细介绍了如何在CentOS系统中安装PHP-FPM,包括新版和旧版的安装方法,以及如何配置php-fpm运行用户。接着讲解了编译安装Nginx,并修改配置文件以支持php-fpm。最后,创建测试PHP文件并启动服务,通过浏览器验证PHP-FPM和Nginx的集成。在安装过程中,还提到了可能遇到的错误及其解决方案。
摘要由CSDN通过智能技术生成

nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。

nginx一般是把请求发fastcgi管理进程处理,fascgi管理进程选择cgi子进程处理结果并返回被nginx

本文以php-fpm为例介绍如何使nginx支持PHP

一、编译安装php-fpm

什么是PHP-FPM

PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,可以在 http://php-fpm.org/download下载得到.

PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

新版PHP已经集成php-fpm了,不再是第三方的包了,推荐使用。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM,其它参数都是配置php的,具体选项含义可以查看这里。

安装前准备

centos下执行

yum -y install gcc automake autoconf libtool make

yum -y install gcc gcc-c++ glibc

yum -y install libmcrypt-devel mhash-devel libxslt-devel

libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel

zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel

ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel

krb5 krb5-devel libidn libidn-devel openssl openssl-devel

1

2

3

4

5

6

7

8

9yum-yinstallgccautomakeautoconflibtoolmake

yum-yinstallgccgcc-c++glibc

yum-yinstalllibmcrypt-develmhash-devellibxslt-devel

libjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-devel

zlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-devel

ncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-devel

krb5krb5-devellibidnlibidn-developensslopenssl-devel

新版php-fpm安装(推荐安装方式)

wget http://cn2.php.net/distributions/php-5.4.7.tar.gz

tar zvxf php-5.4.7.tar.gz

cd php-5.4.7

./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt

--enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath

--enable-inline-optimization --with-bz2 --with-zlib --enable-sockets

--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex

--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli

--with-gd --with-jpeg-dir

make all install

1

2

3

4

5

6

7

8

9

10

11wgethttp://cn2.php.net/distributions/php-5.4.7.tar.gz

tarzvxfphp-5.4.7.tar.gz

cdphp-5.4.7

./configure--prefix=/usr/local/php--enable-fpm--with-mcrypt

--enable-mbstring--disable-pdo--with-curl--disable-debug--disable-rpath

--enable-inline-optimization--with-bz2--with-zlib--enable-sockets

--enable-sysvsem--enable-sysvshm--enable-pcntl--enable-mbregex

--with-mhash--enable-zip--with-pcre-regex--with-mysql--with-mysqli

--with-gd--with-jpeg-dir

makeallinstall

旧版手动打补丁php-fpm安装(旧版程序已经没有了,大家新版的吧,这里做个展示)

wget http://cn2.php.net/get/php-5.2.17.tar.gz

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

tar zvxf php-5.2.17.tar.gz

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

cd php-5.2.17

./configure --prefix=/usr/local/php -with-config-file-path=/usr/local/php/etc

-with-mysql=/usr/local/mysql

-with-mysqli=/usr/local/mysql/bin/mysql_config -with-openssl -enable-fpm -enable-mbstring

-with-freetype-dir -with-jpeg-dir -with-png-dir -with-zlib-dir -with-libxml-dir=/usr -enable-xml

-with-mhash -with-mcrypt -enable-pcntl -enable-sockets  -with-bz2 -with-curl -with-curlwrappers

-enable-mbregex -with-gd -enable-gd-native-ttf -enable-zip -enable-soap -with-iconv -enable-bcmath

-enable-shmop -enable-sysvsem -enable-inline-optimization -with-ldap -with-ldap-sasl -enable-pdo

-with-pdo-mysql

make all install

以上两种方式都可以安装php-fpm,安装后内容放在/usr/local/php目录下

以上就完成了php-fpm的安装。

下面是对php-fpm运行用户进行设置

cd /usr/local/php

cp etc/php-fpm.conf.default etc/php-fpm.conf

vi etc/php-fpm.conf

1

2

3cd/usr/local/php

cpetc/php-fpm.conf.defaultetc/php-fpm.conf

vietc/php-fpm.conf

修改

user = www-data

group = www-data

如果www-data用户不存在,那么先添加www-data用户

groupadd www-data

useradd -g www-data www-data

二、编译安装nginx

三、修改nginx配置文件以支持php-fpm

nginx安装完成后,修改nginx配置文件为,nginx.conf

其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ .php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

四、创建测试php文件

创建php文件

在/usr/local/nginx/html下创建index.php文件,输入如下内容

echo phpinfo();

?>

1

2

3<?php

echophpinfo();

?>

五、启动服务

启动php-fpm和nginx

/usr/local/php/sbin/php-fpm

#手动打补丁的启动方式/usr/local/php/sbin/php-fpm start

sudo /usr/local/nginx/nginx

1

2

3

4/usr/local/php/sbin/php-fpm

#手动打补丁的启动方式/usr/local/php/sbin/php-fpm start

sudo/usr/local/nginx/nginx

php-fpm关闭重启见文章结尾

六、浏览器访问

访问http://你的服务器ip/index.php,皆可以见到php信息了。

安装php-fpm时可能遇到的错误:

1.php configure时出错

configure: error: XML configuration could not be found

apt-get install libxml2 libxml2-dev  (ubuntu下)

yum -y install libxml2 libxml2-devel(centos下)

1

2apt-getinstalllibxml2libxml2-dev (ubuntu下)

yum-yinstalllibxml2libxml2-devel(centos下)

2.Please reinstall the BZip2 distribution

wget http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz

tar -zxvf bzip2-1.0.5.tar.gz

cd bzip2-1.0.5

make

make install

1

2

3

4

5wgethttp://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz

tar-zxvfbzip2-1.0.5.tar.gz

cdbzip2-1.0.5

make

makeinstall

3. php的配置文件中有一行--with-mysql=/usr。

安装的时候提示:

configure: error: Cannot find MySQL header files under yes.

Note that the MySQL client library is not bundled anymore.

这是由于安装mysql时没有安装mysql头文件,或者是路径指定不正确,php找不到mysql的头文件引起的错误提示。

解决方法。

(1.) 查看你的系统有没有安装mysql header

find / -name mysql.h

如果有。请指定--with-mysql=/跟你的正常路径。

如果没有。请看下一步。

(2.)redhat安装

rpm -ivh MySQL-devel-4.1.12-1.i386.rpm

(3.)ubuntu安装

apt-get install libmysqlclient15-dev

(4.)最后一步php的配置选项添加--with-mysql=/usr即可!

4.No input file specified.

location ~ .php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

5. 如果php configure时缺库,可以先安装库(ubuntu下)

sudo apt-get install make bison flex gcc patch autoconf subversion locate

sudo apt-get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-dev

6. mcrypt.h not found. Please reinstall libmcrypt

apt-get install libmcrypt-dev

或者

cd /usr/local/src

wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz

tar -zxvf libmcrypt-2.5.8.tar.gz

cd /usr/local/src/libmcrypt-2.5.8

./configure --prefix=/usr/local

make

make install

7. php-fpm 5.4.7 如何关闭 重启?

php 5.4.7 下的php-fpm 不再支持 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,需要使用信号控制:

master进程可以理解以下信号

INT, TERM 立刻终止 QUIT 平滑终止 USR1 重新打开日志文件 USR2 平滑重载所有worker进程并重新载入配置和二进制模块

示例:

php-fpm 关闭:

kill -INT cat /usr/local/php/var/run/php-fpm.pid

php-fpm 重启:

kill -USR2 cat /usr/local/php/var/run/php-fpm.pid

查看php-fpm进程数:

ps aux | grep -c php-fpm

8.命令行下执行php,提示找不到命令

-bash: /usr/bin/php: No such file or directory

vi /etc/profile

在文件底部增加一行配置

export PATH=/usr/local/php/bin:$PATH

保存退出

source /etc/profile

VMware NSX-T Reference Design Guide Table of Contents 1 Introduction 4 1.1 How to Use This Document 4 1.2 Networking and Security Today 5 1.3 NSX-T Architecture Value and Scope 5 2 NSX-T Architecture Components 11 2.1 Management Plane 11 2.2 Control Plane 12 2.3 Data Plane 12 3 NSX-T Logical Switching 13 3.1 The N-VDS 13 3.1.1 Uplink vs. pNIC 13 3.1.2 Teaming Policy 14 3.1.3 Uplink Profile 14 3.1.4 Transport Zones, Host Switch Name 16 3.2 Logical Switching 17 3.2.1 Overlay Backed Logical Switches 17 3.2.2 Flooded Traffic 18 3.2.2.1 Head-End Replication Mode 19 3.2.2.2 Two-tier Hierarchical Mode 19 3.2.3 Unicast Traffic 21 3.2.4 Data Plane Learning 22 3.2.5 Tables Maintained by the NSX-T Controller 23 3.2.5.1 MAC Address to TEP Tables 23 3.2.5.2 ARP Tables 23 3.2.6 Overlay Encapsulation 25 4 NSX-T Logical Routing 26 4.1 Logical Router Components 27 4.1.1 Distributed Router (DR) 27 4.1.2 Services Router 32 4.2 Two-Tier Routing 36 VMware NSX-T Reference Design Guide 2 4.2.1 Interface Types on Tier-1 and Tier-0 Logical Routers 37 4.2.2 Route Types on Tier-1 and Tier-0 Logical Routers 38 4.2.3 Fully Distributed Two Tier Routing 39 4.3 Edge Node 41 4.3.1 Bare Metal Edge 42 4.3.2 VM Form Factor 46 4.3.3 Edge Cluster 48 4.4 Routing Capabilities 49 4.4.1 Static Routing 49 4.4.2 Dynamic Routing 50 4.5 Services High Availability 53 4.5.1 Active/Active 53 4.5.2 Active/Standby 54 4.6 Other Network Services 56 4.6.1 Network Address Translation 56 4.6.2 DHCP Services 56 4.6.3 Metadata Proxy Service 57 4.6.4 Edge Firewall Service 57 4.7 Topology Consideration 57 4.7.1 Supported Topologies 57 4.7.2 Unsupported Topologies 59 5 NSX-T Security 60 5.1 NSX-T Security Use Cases 60 5.2 NSX-T DFW Architecture and Components 62 5.2.1 Management Plane 62 5.2.2 Control Plane 62 5.2.3 Data Plane 63 5.3 NSX-T Data Plane Implementation - ESXi vs. KVM Hosts 63 5.3.1 ESXi Hosts- Data Plane Components 64 5.3.2 KVM Hosts- Data Plane Components 64 5.3.3 NSX-T DFW Policy Lookup and Pa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值