源代码编译方式为Nginx安装PHP 5.6


:Mr.zhou  阅读: 1,659 次

  Nginx 已编译安装成功,接下来安装PHP。源代码编译方式安装Nginxlogo.php

  当前环境:

[root@nginx ~]# uname -r&&ifconfig eth0|awk -F "[ :]*" 'NR==2{print $4}'&&nginx -V
2.6.32-504.el6.x86_64
172.16.1.140
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.8.0 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
[root@nginx ~]# 

  安装依赖:

  配置 EPEL 源 安装 libcrypt mhash mcrypt:

[root@nginx ~]# wget -q -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@nginx ~]# echo $?
0
[root@nginx ~]# 
[root@nginx ~]# yum -q -y install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
[root@nginx ~]# echo $?
0
[root@nginx ~]# 
[root@nginx ~]# yum -q -y install zlib zlib-devel libjpeg libjpeg-devel freetype freetype-devel gd gd-devel curl curl-devel libxml2 libxml2-devel libxslt libxslt-devel
[root@nginx ~]# echo $?
0
[root@nginx ~]# 

  源码方式安装 libiconv:

[root@nginx src]# cd /usr/local/src/
[root@nginx src]# wget -q http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@nginx src]# tar xf libiconv-1.14.tar.gz 
[root@nginx src]# cd libiconv-1.14
[root@nginx libiconv-1.14]# ./configure -q --prefix=/usr/local/libiconv
config.status: creating po/POTFILES
config.status: creating po/Makefile
[root@nginx libiconv-1.14]# echo $?
0
[root@nginx libiconv-1.14]# 
[root@nginx libiconv-1.14]# make&&make install
[root@nginx libiconv-1.14]# echo $?
0
[root@nginx libiconv-1.14]# 

  下载PHP源码包:

[root@nginx src]# cd /usr/local/src/ 

[root@nginx src]# wget -q http://cn2.php.net/distributions/php-5.6.11.tar.gz

  解压,配置编译选项:

[root@nginx src]# tar xf php-5.6.11.tar.gz 
[root@nginx src]# cd php-5.6.11
[root@nginx php-5.6.11]# 
[root@nginx php-5.6.11]# ./configure \
--prefix=/usr/local/php-5.6.11 \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--with-curl \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-static \
--with-xsl \
--enable-ftp
...
[root@nginx php-5.6.11]# echo $?
0
[root@nginx php-5.6.11]# 

  编译 安装

[root@nginx php-5.6.11]# make&&make install
...
[root@nginx php-5.6.11]# echo $?
0
[root@nginx php-5.6.11]# 

  做软链接、复制配置文件、将相应的目录加入系统环境变量:

[root@nginx php-5.6.11]# ln -s /usr/local/php-5.6.11/ /usr/local/php
[root@nginx php-5.6.11]# 
[root@nginx php-5.6.11]# pwd
/usr/local/src/php-5.6.11
[root@nginx php-5.6.11]# cp php.ini-production /usr/local/php/lib/php.ini
[root@nginx php-5.6.11]#
[root@nginx php-5.6.11]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@nginx php-5.6.11]# 
[root@nginx php-5.6.11]# ls /usr/local/php/sbin/
php-fpm
[root@nginx php-5.6.11]# echo -e 'PATH=/usr/local/php/sbin/:$PATH\nexport PATH'>>/etc/profile
[root@nginx php-5.6.11]# tail -2 /etc/profile
PATH=/usr/local/php/sbin/:$PATH
export PATH
[root@nginx php-5.6.11]# source /etc/profile
[root@nginx php-5.6.11]# 

  启动PHP-FPM:

[root@nginx ~]# php-fpm 
[root@nginx ~]# lsof -i :9000
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 50777 root    7u  IPv4 148614      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 50778  www    0u  IPv4 148614      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 50779  www    0u  IPv4 148614      0t0  TCP localhost:cslistener (LISTEN)
[root@nginx ~]# 

  配置 Nginx 输出显示 PHP 信息:

[root@nginx ~]# cat /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi.conf;
        }
    }
}
[root@nginx ~]#
[root@nginx ~]# echo ''>/usr/local/nginx/html/index.php
[root@nginx ~]# 

  测试:

[root@nginx ~]# curl -I 172.16.1.140
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Sun, 12 Jul 2015 00:06:01 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.11

[root@nginx ~]# 

  使用Windows浏览器,输入 ip 地址查看详细信息:

phpinfo


转载请注明原文链接:http://www.z-dig.com/source-code-is-compiled-to-install-nginx-php-5-6.html



正文部分到此结束