The most perfect Centos nginx+php Install ever.

Source: Internet
Author: User
Tags php website

Zhou clan, finishing technical documents, for the next generation to stay a little tutorial ...

Nginx function is not much to say, do not understand the direct Baidu, Nginx + PHP installation is more responsible, often error, online is also everyone said the same, no more perfect practice

Here is my own study of one of the most simplistic installation, record, in case you forget.

First of all, this is installed with Yum, but they are public yum, not like which people, to the machine's repo modification, and then to Yum, I this yum is all machines, do not need to modify any Yum source on the line, that is, public resources yum, but nginx, must use the source code, Source to the official website to obtain


1, install nginx+php before, need to install PHP, I have a command to take care of, we look at


[[Email protected]_server ~]# yum-y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcur L-devel PHP php-devel php-fpm

Do not learn the source code to do, a mess, but also PHP, is php-fpm, very bad, direct Yum fix, and stable, unless you need to modify the source code of PHP, then, you start the PHP-FPM source code of the egg pain!


2, check whether PHP installation success, it is obvious, directly to see if php-fpm up

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/52/wKioL1PTBEOjMVwlAAEzhpkN9oA677.jpg "title=" Qq20140726091305.png "alt=" Wkiol1ptbeojmvwlaaezhpkn9oa677.jpg "/>

It's best to set him up as boot, auto-start, this you know, so simple things


3, the following start installation Nginx, before installation, first install the environment, Yum can

[Email protected]_server ~]# yum-y install pcre* openssl* zlib*


4, upload the Nginx file to the specified directory,/usr/tmp below

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/52/wKiom1PTBIPjnHqLAAC9a72GpTQ520.jpg "title=" Qq20140726091945.png "alt=" Wkiom1ptbipjnhqlaac9a72gptq520.jpg "/>


5. Start the installation

[Email protected]_server ~]# CD nginx-1.6.0

[Email protected]_server nginx-1.6.0]#/configure--prefix=/usr/local/nginx--user=apache--group=apache-- With-http_ssl_module--with-http_gzip_static_module--with-http_spdy_module--with-http_stub_status_module-- With-pcre

[[Email Protected]_server nginx-1.6.0]# make && make install

Note, here configure, because PHP using Yum installation, then the default PHP website users and group users are Apache, so we have to ensure that nginx user is also Apache, so in the compile time, it is necessary to designate--user=apache-- Group=apache


6. Start Nginx

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/52/wKiom1PTBdTCMoyiAAFHngkqd5Q132.jpg "title=" Qq20140726092521.png "alt=" Wkiom1ptbdtcmoyiaafhngkqd5q132.jpg "/>

Web page Open Test see

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/41/52/wKioL1PTBzigBRwmAAF78dOqzd0223.jpg "title=" Qq20140726092634.png "alt=" Wkiol1ptbzigbrwmaaf78doqzd0223.jpg "/>


7, test PHP, according to Apache normal thinking, we upload a php file directly to the Nginx directory, should be able to open

[Email protected]_server ~]# cd/usr/local/nginx/html/

[[Email protected]_server html]# Touch test.php

[Email protected]_server html]# VI test.php

<?php

Phpinfo ();

?>

Now open the page to see if there is any problem

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/41/52/wKioL1PTCHOxno30AAGrkOO6Po0249.jpg "title=" Qq20140726093146.png "alt=" Wkiol1ptchoxno30aagrkoo6po0249.jpg "/>


Unexpectedly, Prompt me to download? That is to say, PHP it has not resolved to, if can parse, or support, it is directly execute PHP internal code, so, have to change. Because Nginx is only parsing HTML by default, which is why this article title nginx+php


8, modify the configuration, complete Php+nginx

[Email protected]_server html]# vi/usr/local/nginx/conf/nginx.conf


User nobody; Change to user Apache Apache;

Worker_processes 2; How many you have on your server CPU, the more the better.


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

#}


Remove all their front # numbers and change them to the following

Location ~ \.php$ {

root HTML;

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_index index.php;

Fastcgi_param script_filename $document _root$fastcgi_script_name;

Include Fastcgi_params;

}

As for why this change, you can test it yourself, I do not speak here

See the previous configuration, I think we should now be more clear thinking,


9. Reload the Nginx configuration

[Email protected]_server html]#/usr/local/nginx/sbin/nginx-s Reload


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/52/wKiom1PTC6qATbbZAALBX-cMbXI509.jpg "title=" Qq20140726094952.png "alt=" Wkiom1ptc6qatbbzaalbx-cmbxi509.jpg "/>


10. Fix

This article from the "Zhou Clan" blog, declined to reprint!

The most perfect Centos nginx+php Install ever.

Related Article

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.