`
jwfdp
  • 浏览: 44983 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Ubuntu安装php-fpm以及常见问题解决

 
阅读更多

 

 

摘要:

   在64位Ubuntu下源码安装PHP5.3.8,并且配置Nginx为Web服务器。网上对于源码编译安装PHP的文章已经很多了,google下一大摞,但是为啥我还这么写上呢, 一来是因为工作需要,重装了系统比较重要的就是配置环境,以前是一直用sudo apt-get的调过过程的安装方式,所以趁着这个机会能自己尝试下源码方式安装,体验下过程。二来是因为这个是第一次源码安装,特此纪念下。

 

一、 准备

   环境:64位 Ubuntu 11.10

   服务器: Nginx 1.1.13

   下载PHP源码:本文使用5.3.8版本

  

二、 安装

复制代码
# tar zxvf php5.3.8.tar.gz
# cd php5.3.8
# ./configure        --prefix=/usr/local/php5
        --with-config-file-path=/usr/local/php5/etc
        --with-curl
        --with-pear
        --with-gd
        --with-jpeg-dir
        --with-png-dir
        --with-zlib
        --with-xpm-dir
        --with-freetype-dir
        --with-t1lib
        --with-mcrypt
        --with-mhash
        --with-mysql
        --with-mysqli
        --with-pdo-mysql
        --with-openssl
        --with-xmlrpc
        --with-xsl
        --with-bz2
        --with-gettext
        --with-fpm-user=xiaoxiao
        --with-fpm-group
        --enable-fpm
        --enable-exif
        --enable-wddx
        --enable-zip
        --enable-bcmath
        --enable-calendar
        --enable-ftp
        --enable-mbstring
        --enable-soap
        --enable-sockets
        --enable-sqlite-utf8
        --enable-shmop
        --enable-dba
        --enable-sysvmsg
        --enable-sysvsem
        --enable-sysvshm
复制代码

 

出现得错误如下:

错误一:

configure: error: xml2-config not found. Please check your libxml2 installation.

而我已经安装过了libxml2,但是还是有这个提示:

解决办法:

# sudo apt-get install libxml2-dev

 

错误二:

configure: error: Please reinstall the BZip2 distribution

而我也已经安装了bzip2,网上找到得解决方案都是需要安装bzip2-dev,可是11.10里面没有这个库。

解决办法:在网上找到bzip2-1.0.5.tar.gz,解压,直接make ,sudo make install.(我使用的该源来自于http://ishare.iask.sina.com.cn/f/9769001.html)

 

错误三:

configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/

解决办法:

# sudo apt-get install libcurl4-gnutls-dev

 

错误四:

configure: error: jpeglib.h not found.

解决办法:

# sudo apt-get install libjpeg-dev

 

错误五:

configure: error: png.h not found.

解决办法:

# sudo apt-get install libpng-dev

 

错误六:

configure: error: libXpm.(a|so) not found.

解决办法:

# sudo apt-get install libxpm-dev

 

错误七:

configure: error: freetype.h not found.

解决办法:

# sudo apt-get install libfreetype6-dev

 

错误八:

configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.

解决办法:

# sudo apt-get install libt1-dev 

 

错误九:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决办法:

# sudo apt-get install libmcrypt-dev

 

错误十:

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

Note that the MySQL client library is not bundled anymore!

解决办法:

# sudo apt-get install libmysql++-dev

 

错误十一:

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

解决办法:

# sudo apt-get install libxslt1-dev

可见PHP源码安装之前需要先安装这些依赖,详细可见http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=231159

如上错误都解决之后,再次./config....没有错误之后,

# make
# sudo make install

三、 配置

   php-fpm是一个php fastCGI得管理器,在PHP5.3.X已经集成了这个东西,所以我们可以省去自己装这个得麻烦了,只要配置一下就可以。

   先将相关得配置文件都拷贝到php5/etc目录下(该目录是我得配置文件存放目录),主要涉及有:

      1、php-fpm配置文件:php源目录/sapi/fpm/php-fpm.conf.in

      2、php-fpm启动文件:php源目录/sapi/fpm/init.d.php-fpm.in

      3、php本身配置文件:php源目录/php.ini-development  php源目录/php.ini-production

      如果需要保存一份原始得文件,那么就将以上文件另外cp一份出来,如果是不保存的,那么以上文件cp到etc下就直接更名为自己需要的。我是保留了一份在etc目录下。

     现在php5/etc目录下有如下格式配置文件:

     php-fpm.conf   init.d.php-fpm   php.ini    pear.conf(安装完成之后就有该文件)

    

    首先:配置php-fpm.conf文件:

    1、pid配置

    ;pid=run/php-fpm.pid

   将前面得;号去掉,可以后面得路径可以根据自己得需求配置一个路径。

    2、log配置

   ;error-log=log/php-fpm.log

   log的配置可以根据自己的需求是否开启及存放位置

   3、listen 配置

   listen=127.0.0.1:9000

   这个配置主要注意端口不要冲突,我在配置这个的时候采用的是网上说的socket方式,配置如下:

   listen=/usr/local/php5/var/run/php-fpm.socket

   然后在/usr/local/php5/var/run/该目录下建立该文件,注意权限需要

   其他项的配置可以根据自己的需求更改,配置项的说明在这可以看到:http://www.php.net/manual/en/install.fpm.configuration.php。同时在github上有一份比较完整可用的配置:https://github.com/vladgh/VladGh.com/blob/master/php-fpm.conf   可以作为参考。

 

    其次:配置init.d.php-fpm

   改文件作为启动文件,需要配置的就是在开头位置的几个变量值,包括:

   1、php_fpm_BIN:指向安装好的php目录/sbin/php-fpm

   2、php_fpm_CONF:指向安装好的php目录/etc/php-fpm.conf  {如果该配置文件你不是叫这个名字,跟这里应该为你真是得配置名}

   3、php_fpm_PID:这里指向php-fpm的pid存放路径。

   完成之后,将该文件拷贝到/etc/init.d目录下,本文是采用建立软链接的方式:

# sudo ln -s /usr/local/php5/etc/init.d.php-fpm /etc/init.d/php-fpm
# sudo update-rc.d -f php-fpm defaults

 

     然后:配置php

     我是拿的php.ini- development,几乎不用配置

 

    最后:配置nginx.conf

     完成上面之后,需要配置nginx可运行php,如下配置:

    Server{}下:

     1、root html: 该项配置指明脚本程序的目录,本文是设置为root  /home/www

     2、识别.php文件:

location / {
            index  index.html index.htm index.php;
        }

     3、解析php脚本:这块只要将注释”#”去掉就好。

复制代码
location ~ \.php$ {
       fastcgi_pass  unix:/usr/local/php5/var/run/php-fpm.socket; #127.0.0.1:9000;       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include  fastcgi_params;

   }
复制代码

    注意:fastcgi_pass 这里,后面跟php-fpm.conf中配置得listen一致,在listen中我是配置了socket方式,所以这里也这样配。

    启动服务:

# sudo /etc/init.d/nginx restart
# sudo /etc/init.d/php-fpm start

在网页中输入localhost,就可以看到啦:

 如果有需要,可以添加为系统路径中:

# sudo vim /etc/bash.bashrc
//在最后添加如下if [ -d "/usr/local/php5/bin" ] && [ -d "/usr/local/php5/sbin" ]; then
        PATH="$PATH:/usr/local/php5/bin:/usr/local/php5/sbin"

fi

 

四、虚拟机配置

    nginx的虚拟机配置其实挺简单的,打开nginx.conf  在http{}中加入 include /usr/local/nginx/conf/virtual_sites.conf;(也可以是文件夹下的文件如sites/*.conf)

然后在virtual_sites.conf中配置需要得虚拟机:

复制代码
server {
    listen       80;
    server_name  p9.xxx;
    root         /home/www/p9/www;

    location / {
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/usr/local/php5/var/run/php-fpm.socket;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_index  index.php;
        include        fastcgi_params;
    }
}
复制代码
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics