The integration of Nginx and PHP

Source: Internet
Author: User
Tags apache php php website

"Nginx and PHP Integration" and "Apache and PHP Integration" is different, Apache is the PHP as a module to start, and Nginx is the HTTP request variables (such as GET,USR_ Agent, etc.) and the request of the upper and lower bits of the original mode is forwarded to the PHP process, that is, PHP is a separate process, while maintaining the communication with nginx, this way of working is called fastcgi. The port of the PHP process is 9000.


So, Apache PHP cannot be used for nginx.


Preparatory work

1. First, please download PHP from the official PHP website. Note As of this article, please download version 5.6.21, do not 7.0.6 version, 7.0. Version 6 There seems to be something wrong with MySQL. )

2. Install MySQL and mysql-devel,mysql will not say much;

3.#yum Install TTF, TTF is the software for fonts;

4.#yum Install GD Gd-devel, GD is the software of drawing;

5.#yum Install FreeType, this is also the font-related software;


Once these are ready for download, you can compile them.


Compilation process

PHP's compilation process is slightly disgusting, this thing can not be copied online, copy the words will appear compile unsuccessful case, take MySQL as an example.

First through the #tar-zxvf php-5.6.21.tar.gz will download the package unpacked, will be the same as before to get configure files, but because it is to the PHP with Nginx\mysql\gd\tty and other software integration, so you can not. Configure after the Shang, but to configure in the time to specify the address of the Mysql\gd\tty.


Let's start with #./configure-help|grep MySQL to see what MySQL needs.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/C9/wKioL1cssozCxoS6AAB-Zq-_-u0882.png "title=" 1.png " alt= "Wkiol1cssozcxos6aab-zq-_-u0882.png"/>

The meaning of each line is followed by comments, take the English dictionary to check, here we use--with-mysql=dir, but here do not use DIR with Mysqlnd,mysqlnd is PHP new driver, specifically for MySQL.


And so on,#./configure-help|grep GD and so on, one by one to the requirements of the relevant documents to check.


Then #./configure--prefix=/usr/local/php--with-pdo-mysql=mysqlnd--enable-mysqlnd--WITH-GD-- Enable-gd-native-ttf--enable-gd-jis-conv --enable-fpm, after the carriage return will be large article scrolling subtitles, then prompts thanks and installs the file.


The next step is to #make && make install, the whole process is longer.


If in make this step, "Make: [sapi/cli/php] Error 1" prompt appears, #make zend_extra_libs= '-liconv ', after the end #make test, finally #make Install.


After compilation

After the entire make process, came to the PHP folder LS, found inside should be bin etc include Lib Php sbin var these folders, and then sbin there is a php-fpm, start this is to start the PHP process manager.


After starting the PHP process Manager, return to the Nginx nginx.conf file and edit the following in the server:

Location ~ \.php$ {Fastcgi_pass 127.0.0.1:9000;           Fastcgi_index index.php;           Fastcgi_param script_filename/usr/local/nginx/html/$fastcgi _script_name;        Include Fastcgi_params; }

This code means that matching to all of the. php files is given to fastcgi processing, the default home page is Index.php,fastcgi_param is very important, the mismatch will be 502, this is pointing to the path, For example, the user wants to request is abc.php, then the nginx will turn it to/usr/local/nginx/html/abc.php.


After saving the exit, create a file called test.php under/usr/local/nginx/html/, the content is:

<?php

Phpinfo ();

After saving the exit, enter the address in the browser: localhost/test.php, you will see the homepage of PHP. Inside success with GD and MySQL hooked up:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/CB/wKiom1cswNSBmMNBAAAyWXZqMIY919.png "title=" 1.png " alt= "Wkiom1cswnsbmmnbaaaywxzqmiy919.png"/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/C9/wKioL1cswcezr5_KAABCWMI81UY572.png "title=" 1.png " alt= "Wkiol1cswcezr5_kaabcwmi81uy572.png"/>

This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1770922

The integration of Nginx and PHP

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.