Home  >  Article  >  Backend Development  >  nginx+php装配

nginx+php装配

WBOY
WBOYOriginal
2016-06-13 12:19:571015browse

nginx+php安装

一、.安装nginx请参考:?http://qingwei201314.iteye.com/blog/1729174

二、安装php:

  1. 获取并解压 PHP 源代码:

    tar zxf php-x.x.x
  2. 配置并构建 PHP。在此步骤您可以使用很多选项自定义 PHP,例如启用某些扩展等。 运行 ./configure --help 命令来获得完整的可用选项清单。 在本示例中,我们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。

    cd ../php-x.x.x./configure --enable-fpm --with-mysqlmakesudo make install
  3. 创建配置文件,并将其复制到正确的位置。

    cp php.ini-development /usr/local/php/php.inicp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.confcp sapi/fpm/php-fpm /usr/local/bin
  4. 需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击。

    将 php.ini 文件中的配置项?cgi.fix_pathinfo?设置为?0?。

    打开 php.ini:

    vim /usr/local/php/php.ini

    定位到?cgi.fix_pathinfo=?并将其修改为如下所示:

    cgi.fix_pathinfo=0
  5. 在启动服务之前,需要修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。

    vim /usr/local/etc/php-fpm.conf

    找到以下内容并修改:

    ; Unix user/group of processes; Note: The user is mandatory. If the group is not set, the default user's group;       will be used.user = www-datagroup = www-data

    然后启动 php-fpm 服务:

    /usr/local/bin/php-fpm

    本文档未涵盖对 php-fpm 进行进一步配置的信息,如果您需要更多信息,请查阅相关文档。

  6. 配置 Nginx 使其支持 PHP 应用:

    vim /usr/local/nginx/conf/nginx.conf

    修改默认的 location 块,使其支持 .php 文件:

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

    下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:

    location ~* \.php$ {    fastcgi_index   index.php;    fastcgi_pass    127.0.0.1:9000;    include         fastcgi_params;    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;}

    重启 Nginx。

  7. 如果使用thinkphp,配置pathinfo:
  8. 修改第6步中的部分内容如下:
  9. location ~ \.php {            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            set $path_info "";            set $real_script_name $fastcgi_script_name;            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {                set $real_script_name $1;                set $path_info $2;            }            fastcgi_param  SCRIPT_FILENAME  $document_root$real_script_name;            fastcgi_param  SCRIPT_NAME      $real_script_name;            fastcgi_param PATH_INFO $path_info;            include        fastcgi_params;        }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:请问这种添加‘热门标签’的插件是什么?如下图所示Next article:怎么获取手机型号

Related articles

See more