资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

lnmp环境安装(4)-php源码编译安装-创新互联

本人安装的lnmp环境的相关文件,可以在本人提供的百度云盘资源进行下载

链接: http://pan.baidu.com/s/1dD6QZ1B 密码: zcs8


一、概述

 php全称PHP:Hypertext Preprocessor超文本处理器,开源脚本语言!

 其与web server的接口支持三种形式,分别为cgi, module方式, fastcgi方式。而对于nginx而言,只支持cgi和fastcgi两种接口方式与php进行连接!

我们提供的服务有:网站设计、网站制作、微信公众号开发、网站优化、网站认证、山阴ssl等。为数千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的山阴网站制作公司

 本节将以源码安装php,启动php-fpm服务(fastcgi接口)与nginx进行连接。

 关于nginx的配置请看前面章节的有关介绍!

二、准备工作

 1、安装依赖开发包

 # yum install -y libxml2-devel bzip2-devel libcurl-devel libmcrypt-devel

 2、×××

 地址:http://php.net/downloads.php 下载所需版本,这里使用php-5.5.27.tar.bz2。

 也可以使用我的安装文件,已存在百度云盘->请看文章开头。

三、安装配置

 1、配置

  --prefix                 指定安装目录

  --with-mysql=MYSQL_DIR        安装mysql模块 指定其安装路径

  --with-openssl            安装openssl模块

  --enable-fpm              支持fpm,对于采用fastcgi方式,此模块必须开启

  --enable-sockets           支持socket,对于采用fastcgi方式,此模块必须开启

  --enable-sysvshm             支持System V shared memory

  --with-mysqli=MYSQL_CONFIG_PATH     安装mysqli模块

  --with-config-file=CONFIG_DIR      指定php配置文件安装路径

  --with-config-file-scan-dir=CONFIG_DIR  指定配置文件的扫描路径,就是除主配置文件php.ini的其他配置文件路径

  --with-mysqlnd=share,mysqlnd       支持mysqlnd

  --with-enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir ...

  安装php相关的一些扩展文件

  配置如下

  # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mysql=share,mysqlnd

 2、编译安装

  # make

  # make install

 3、准备配置文件

  # cp php.ini-production /etc/php.ini

 4、开机启动php-fpm

  配置sysv启动脚本,添加到服务列表

  # cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

  # chmod +x /etc/rc.d/init.d/php-fpm

  # chkconfig --add php-fpm

  # chkconfig php on

 5、添加php-fpm服务配置脚本

  # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 6、启动服务

  # service php-fpm start

  # ps -ef | grep php-fpm     // 可以看到系统已启动多个php-fpm进程,说明php-fpm服务已启动成功

四、php-fpm和nginx

 1、编辑nginx.conf

  server段配置修改如下,为nginx添加脚本解析功能

  location / {

    root  html;

    index  index.html index.htm index.php;

  }

  #error_page  404        /404.html;

  # redirect server error pages to the static page /50x.html

  #

  error_page  500 502 503 504  /50x.html;

  location = /50x.html {

    root  html;

  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80

  #

  #location ~ \.php$ {

  #   proxy_pass  http://127.0.0.1;

  #}

  # 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  /scripts$fastcgi_script_name;

    include     fastcgi_params;

  }

 2、修改/etc/nginx/fastcgi_params

  fastcgi_param  QUERY_STRING    $query_string;

  fastcgi_param  REQUEST_METHOD   $request_method;

  fastcgi_param  CONTENT_TYPE    $content_type;

  fastcgi_param  CONTENT_LENGTH   $content_length;

  fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;

  fastcgi_param  SCRIPT_NAME    $fastcgi_script_name;

  fastcgi_param  REQUEST_URI    $request_uri;

  fastcgi_param  DOCUMENT_URI    $document_uri;

  fastcgi_param  DOCUMENT_ROOT    $document_root;

  ... ...

重新定义fastcgi_param参数SCRIPT_FILENAME

 3、nginx重启

  # service nginx restart

 4、测试访问

  添加编辑/usr/local/nginx/index.php

  

   phpinfo();

  ?>

  浏览器访问 http://域名/index.php,如下图

  lnmp环境安装(4)-php源码编译安装

  综合以上,完成php的安装,启用php-fpm服务器并与nginx进行整合,测试完成!

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


标题名称:lnmp环境安装(4)-php源码编译安装-创新互联
URL地址:http://cdkjz.cn/article/disjcg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220