Ubuntu11.10 源码编译安装PHP5.3.8

 

1、 准备php

   环境:64位 Ubuntu 11.10html

   服务器: Nginx 1.1.13mysql

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

  

2、 安装git

# 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


出现得错误以下:github

错误一:sql

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

而我已经安装过了libxml2,可是仍是有这个提示:vim

解决办法:api

# 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

3、 配置

   php-fpm是一个php fastCGI得管理器,在PHP5.3.X已经集成了这个东西,因此咱们能够省去本身装这个得麻烦了,只要配置一下就能够。

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

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

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

      三、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

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

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

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

   三、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

 

4、虚拟机配置

    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;
    }
}

 

而后绑定p9.xxx到hosts中便可。一份可用的虚拟机配置也许是这样的http://wiki.nginx.org/NginxVirtualHostExample

相关文章
相关标签/搜索