centos 如何安装 php-fpm

藏色散人
Freigeben: 2023-03-07 15:54:02
Original
2975 人浏览过

centos安装php-fpm的方法:首先通过命令“tar zvxf php-5.4.7.tar.gz”下载安装php-fpm;然后编译安装nginx;最后修改nginx配置文件以支持php-fpm即可。

centos 如何安装 php-fpm

推荐:《PHP视频教程

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-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-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-curl --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex --with-mysql

make all install

旧版手动打补丁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 --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-curl --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex --with-mysql

make all install

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

\

cd /usr/local/php

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

修改

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

user = www-data
group = www-data

二、编译安装nginx

然后按照http://www.nginx.cn/install 安装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文件,输入如下内容

五、启动服务

启动php-fpm和nginx

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

sudo /usr/local/nginx/nginx

六、浏览器访问

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

\

七、cp /root/php-5.3.21/php.ini-development /opt/php/lib

放入PHP配置文件

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

1.phpconfigure时出错

configure: error: XML configuration could not be found
apt-get install libxml2 libxml2-dev  (ubuntu下)
yum -y install libxml2 libxml2-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
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-de

以上是centos 如何安装 php-fpm的详细内容。更多信息请关注PHP中文网其他相关文章!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!