nginx+php Assembly

Source: Internet
Author: User
Tags php source code
nginx+php Installation

I.. installation Nginx Please refer to:? http://qingwei201314.iteye.com/blog/1729174

Second, install PHP:

  1. Get and unzip the PHP source code:

    Tar zxf php-x.x.x

  2. Configure and build PHP. In this step you can customize PHP with a number of options, such as enabling certain extensions. Run the./configure--help command to get a complete list of available options. In this example, we only have a simple configuration that includes PHP-FPM and MySQL support.

    Cd.. /php-x.x.x./configure--enable-fpm--with-mysqlmakesudo make install

  3. Create the configuration file and copy it to the correct location.

    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. You need to be reminded that if the file does not exist, it prevents Nginx from sending the request to the back-end PHP-FPM module. To avoid attacks that are injected by malicious scripts.

    php.ini the configuration items in the file? cgi.fix_pathinfo? 0 ?.

    open php.ini:

    vim/usr/local/php/php.ini 

    navigate to " cgi.fix_pathinfo= ? and modify it to resemble the following:

    cgi.fix_pathinfo=0 

  5. before starting the service, you need to modify the php-fpm.conf configuration file to make sure the PHP-FPM module uses Www-data The user and the Www-data user group are running.

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

    find the following and modify:

     

    then start PHP-FPM service:

    Pre class= "Brush:php;toolbar:false" >/usr/local/bin/php-fpm

    This document does not cover further configuration of PHP-FPM, and if you need more information, please consult the relevant documentation.

  6. configure Nginx to support PHP applications:

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

    Modify the default location block, Enable it to support. php Files:

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

    next configuration to ensure that requests for. php files will be routed to the backend PHP-FPM module, uncomment the default PHP configuration block, and modify to the following:

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

    restart Nginx.

  7. If you use thinkphp, configure PathInfo:
  8. Modify part of the 6th step as follows:
  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 $;                Set $path _info;            }            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;        }

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.