linix下的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的时候带 �Cenable-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


yum install libXpm-devel


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

安装后内容放在/usr/local/php目录下

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

cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/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文件,输入如下内容

<?php
    echo phpinfo();
?>

五、启动服务

启动php-fpm和nginx


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


/usr/local/nginx/nginx


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


附:

php gd库的安装与配置。

完整步骤如下,大家参考下。

1,安装zlib,一般Centos系统自带已经安装好,可以用以下命令去查看:
 

代码示例:

[root@xxx ~]# rpm -qa | grep zlib
zlib-1.2.1.2-1.2
zlib-devel-1.2.1.2-1.2
You have new mail in /var/spool/mail/root

不存在的话,请手动下载编译:http://ishare.iask.sina.com.cn/f/15275772.html
 

代码示例:

tar zxvf zlib-1.2.2.tar.gz
  cd zlib-1.2.2
  ./configure
  make
  make install

2,安装libpng http://sourceforge.net/projects/libpng/
 

代码示例:

tar zxvf libpng-1.4.2.tar.tar
  cd libpng-1.4.2
./configure
  make
  make install

3.安装freetype http://sourceforge.net/projects/freetype/
 

代码示例:

tar zxvf freetype-2.3.12.tar.gz
  cd freetype-2.3.12

  ./configure
  make
  make install

4,安装Jpeg http://www.ijg.org/
 

代码示例:

tar zxvf jpegsrc.v8b.tar.gz
  cd jpeg-8b/

  ./configure --enable-shared
  make
  make test
  make install
 

注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库。

5,安装GD https://bitbucket.org/pierrejoye/gd-libgd/downloads
 

代码示例:

tar zxvf gd-2.0.33.tar.gz
  cd gd-2.0.33
  ./configure --with-png --with-freetype --with-jpeg

make
make install

6,安装PHP php-5.2.11.tar.gz
 

代码示例:

tar zxvf php-5.2.11.tar.gz
cd php-5.2.11
./configure选项见下方

make
make install

注:
 

代码示例:

/usr/local/include/freetype2/freetype
freetype

/usr/local/include/include
t1lig

/usr/local/include/libpng14/
png

/usr/local/include
jpeg

[root@xxx php-5.2.11]# ./configure --help | grep t1lib
  --with-t1lib[=DIR]        GD: Include T1lib support. T1lib version >= 5.0.0 required
[root@xxx php-5.2.11]# ./configure --help | grep png
  --with-png-dir[=DIR]      GD: Set the path to libpng install prefix
[root@xxx php-5.2.11]# ./configure --help | grep jpeg
  --with-jpeg-dir[=DIR]     GD: Set the path to libjpeg install prefix
[root@xxx php-5.2.11]# ./configure --help | grep freetype
  --with-freetype-dir[=DIR] GD: Set the path to FreeType 2 install prefix
[root@xxx php-5.2.11]#


./configure --prefix=/opt/php5 --with-apxs2=/opt/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/opt/php5/lib --with-gd --with-zlib --with-png-dir=/usr/local/include/libpng14/  --with-jpeg-dir=/usr/local/include  --with-freetype-dir=/usr/local/include/freetype2/freetype (--with-t1lib  --with-t1lib-dir=/usr/local/include/include)


./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt --enable-mbstring --with-pdo-mysql --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 --enable-opcache=no --enable-zip=no --with-gd=/usr/local/include/ --with-png-dir=/usr/local/include/libpng16/ --with-freetype-dir=/usr/local/include/freetype2/ --with-jpeg-dir=/usr/local/include/ --with-xpm-dir=/usr/lib64


./configure  --prefix=/usr/local/php --enable-fpm --with-mcrypt --enable-mbstring --with-pdo-mysql --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 --enable-opcache=no --enable-zip=no --with-gd=/usr/local/include/ --with-png-dir=/usr/local/include/libpng16/ --with-freetype-dir=/usr/local/include/freetype2/ --with-jpeg-dir=/usr/local/include/ --with-xpm-dir=/usr/lib64 --with-openssl


最后只有T1Lib Support没有启用。

GD库支持最终如下:
 

gd
GD Support  enabled 
GD Version  bundled (2.0.34 compatible) 
FreeType Support  enabled 
FreeType Linkage  with freetype 
FreeType Version  2.3.12 
GIF Read Support  enabled 
GIF Create Support  enabled 
JPG Support  enabled 
PNG Support  enabled 
WBMP Support  enabled 
XBM Support  enabled

在apache配置文件中添加:
 

代码示例:

Listen 81
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module        modules/libphp5.so

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#

<IfModule !mpm_netware_module>

在htdocs目录中创建测试文件info.php:
 

代码示例:

[root@xxx apache]# cat htdocs/info.php
<?php
 echo phpinfo();
?>
 

然后,在浏览器中访问该文件,可查询GD库支持的情况。

你可能感兴趣的:(php-fpm)