Ubuntu installs php-fpm and solves common problems

 

 

Summary:

   Install PHP5.3.8 from source under 64-bit Ubuntu, and configure Nginx as the web server. There are a lot of articles about compiling and installing PHP from source code on the Internet, and there is a lot of google, but why do I still write it like this? First, it is because of work needs. The more important thing to reinstall the system is to configure the environment. I used to use it all the time. The installation method of sudo apt-get has been adjusted through the process, so take this opportunity to try the source code installation and experience the process. Second, because this is the first source code installation, it is hereby commemorated.

 

1. Preparation

   Environment: 64-bit Ubuntu 11.10

   Server:  Nginx 1.1.13

   Download the PHP source code: This article uses version 5.3.8

  

2. Installation

copy code
# 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
copy code

 

The error is as follows:

Error one:

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脚本:这块只要将注释”#”去掉就好。

copy code
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;

   }
copy code

    注意: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

 

四、虚拟机配置

    The virtual machine configuration of nginx is actually quite simple. Open nginx.conf and add  include /usr/local/nginx/conf/virtual_sites.conf to http{}; (it can also be a file in a folder such as sites/*.conf)

Then configure the required virtual machine in virtual_sites.conf:

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326820315&siteId=291194637