Nginx + php assembly-php Tutorial

Source: Internet
Author: User
Nginx + php Installation 1. for nginx installation, see :? Qingwei201314.iteye. comblog1729174 2. install php: Get and unzip the PHP source code: tarzxfphp-x.x.x configuration and build PHP. In this step, you can use many options to customize PHP, such as enabling some extensions. Run the. configure -- help command nginx + php for installation.

1. for nginx installation, see :? Http://qingwei201314.iteye.com/blog/1729174

II. install php:

  1. Obtain and decompress the PHP source code:

    tar zxf php-x.x.x

  2. Configure and build PHP. In this step, you can use many options to customize PHP, such as enabling some extensions. Run the./configure -- help command to obtain the complete list of available options. In this example, we only perform simple configuration that contains the PHP-FPM and MySQL support.

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

  3. Create a 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. Note that, if the file does not exist, Nginx is prevented from sending requests to the backend PHP-FPM module to avoid malicious script injection attacks.

    What are the configuration items in the php. ini file? Cgi. fix_pathinfo? Set?0?.

    Open php. ini:

    vim /usr/local/php/php.ini

    Locate?Cgi. fix_pathinfo =? And modify it as follows:

    cgi.fix_pathinfo=0

  5. Before starting the service, you need to modify the php-fpm.conf configuration file to ensure that the php-fpm module runs as the www-data user and www-data user group.

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

    Find and modify the following content:

    ; 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

    Then start the php-fpm service:

    /usr/local/bin/php-fpm

    This document does not cover further configuration of php-fpm. For more information, see the relevant documentation.

  6. Configure Nginx to support PHP applications:

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

    Modify the default location block to support the. php file:

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

    Next configure to ensure that requests to the. php file will be sent to the back-end PHP-FPM module, uncomment the default PHP configuration block, and modify it 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 thinkphp is used, configure pathinfo:
  8. Modify part of the content in step 1 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 $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;        }

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.