CentOS6.4 install and configure nginx + pcre + php

Source: Internet
Author: User
Tags sendfile

1. Install pcre-devel

Yum-y install gcc-c ++ rpm-build mysql * php * automake autoconf libtool make -- skip-broken

Pcre is the pcre-devel library required by Nginx. The pcre Library is installed to enable Nginx to support the HTTPRewrite module.

PC: http://down.51cto.com/data/904014

[Root @ vb01 src] # unzip pcre-8.33.zip

[Root @ vb01 src] # cd pcre-8.33
[Root @ vb01 pcre-8.33] #./configure

[Root @ vb01 pcre-8.33] # make

[Root @ vb01 pcre-8.33] # make install

2. Install nginx

: Http://nginx.org/here is the nginx-1.4.2 stable version downloaded

[Root @ vb01 src] # tar zxvf nginx-1.4.2.tar.gz

[Root @ vb01 src] # cd nginx-1.4.2

[Root @ vb01 nginx-1.4.2] #./configure -- help # view available modules, such:

-- Prefix = PATH set installation prefix # set the installation directory to PATH

-- With-http_stub_status_module enable ngx_http_stub_status_module # is used to enable the NginxStatus function to monitor the current state of Nginx.

-- With-google_perftools_module enable ngx_google_perftools_module # enable Nginx to support the google-perftools module and use TCMALLOC to optimize Nginx performance.

[Root @ vb01 nginx-1.4.2] #./configure -- with-http_stub_status_module -- prefix =/usr/local/nginx

[Root @ vb01 nginx-1.4.2] # make

[Root @ vb01 nginx-1.4.2] # make install

3. global configuration of Nginx

The configuration file of Nginx is organized as a block. Each block is generally represented by a braces ({}). The block can be divided into several layers, in the configuration file, the main command is located at the highest level. The main layer can have Events, HTTP, and other levels. The HTTP layer also contains the server layer, that is, the server block, server block can be divided into location layers, and a server block can contain multiple location blocks.

[Root @ vb01 conf] # vi/usr/local/nginx/conf/nginx. conf

User nobody; # Set the Nginx Worker process to run. The default value is nobody.

Worker_processes 1; # specify the number of processes enabled by Nginx. The default number is enough.

# Error_log logs/error. log;

Error_log logs/error. log notice; # define the output file and level of the error log File

# Error_log logs/error. log info;


Pid logs/nginx. pid; # location where the Nginx process ID is stored

Google_perftools_profiles/tmp/tcmalloc;


Events {

Worker_connections 1024; # specify the maximum number of connections

}

4. http module configuration

Http {

Include mime. types; # configuration file inclusion File Settings, especially when setting multiple virtual hosts, can reduce the complexity of the master configuration file.

Default_type application/octet-stream; # Set the default type to binary stream. This type is used when the file type is not defined. For example, Nginx will not be parsed when the PHP environment is not configured, the download window appears when you access the PHO file in a browser.

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

# The above Code sets the log format. The default value is enough.

Access_log logs/access. log main;

Sendfile on;

Keepalive_timeout 65;

Server {

Listen 80;

Server_name localhost;

# Location: Used to match the webpage location

Location /{

Root html; # Set the webpage root directory

Index index.html index.htm; # index sets the default Homepage Address

}

Error_page 500 502 503 x.html;

Location =/50x.html {

Root html;

}

}

Default_type application/octet-stream;

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';


Access_log logs/access. log main;

Sendfile on;

Keepalive_timeout 65;

5. Add a server virtual host www.galean.com. The root directory is/var/www/galean.

Server {

Listen 80;

Server_name www.galean.com;

Access_log logs/galean. access. log main;

Location /{

Index index.html;

Root/var/www/galean;

}

}

6. Start Nginx

/Usr/local/nginx/sbin/nginx-t # check the accuracy of the configuration file. If the configuration file is not the default directory, use "-c" to specify the location of the configuration file.

/Usr/local/nginx/sbin/nginx-t-c/usr/local/nginx/conf/nginx. conf

/Usr/local/nginx/sbin/nginx-v # view version information

Nginx version: nginx/1.4.2

Start Nginx

/Usr/local/nginx/sbin/nginx

Check whether Nginx is started

[Root @ vb01 conf] # ps-ef | grep nginx

Nobody 13254 13253 0? 00:00:00 php-fpm: pool nginx

Nobody 13255 13253 0? 00:00:00 php-fpm: pool nginx

Nobody 13256 13253 0? 00:00:00 php-fpm: pool nginx

Nobody 13257 13253 0? 00:00:00 php-fpm: pool nginx

Nobody 13258 13253 0? 00:00:00 php-fpm: pool nginx

Root 21621 1 0 14: 47? 00:00:00 nginx: master process/opt/nginx/sbin/nginx

Nobody 21622 21621 0? 00:00:00 nginx: worker process

Enter the IP address in the browser. The following information is displayed, indicating that the server is successfully started.

Nginx closure:

Disable Nginx: kill-QUIT pid

Smooth restart of Nginx: kill-HUP pid

QUIT: indicates that the process is closed after the current request is processed.

HUP: Indicates re-loading the configuration, that is, disabling the original process and enabling a new working process. This operation will not interrupt user access requests.

USER1: used for Nginx log switching, that is, re-opening a log file.

USER2: Used to smoothly upgrade executable programs.

WINCH: Close the Working Process with ease.

7. install PHP and PHP-FPM

I use yum to install PHP by default. "-- enable-fastcgi" must be added to the/configure compilation option to enable PHP's support for FastCGI. "-- enable-fpm" is used to activate fpm support for FastCGI mode.

Yum-y install php *

The PHP global configuration file is:/etc/php. ini

The configuration file for the PHP-FPM engine is:/etc/php-fpm.conf

Here we will first look at how to start php-fpm:

1. Find the executable Startup File Location of php-fpm under sbin. My default value is/usr/sbin/php-fpm.

[Root @ vb01 src] # locate php-fpm

/Etc/php-fpm.conf # configuration file

/Usr/sbin/php-fpm # Startup File

2. view the options:

[Root @ vb01 src] #/usr/sbin/php-fpm-h

Usage: php-fpm [-n] [-e] [-h] [-I] [-m] [-v] [-t] [-p <prefix>] [- g <pid>] [-c <file>] [-d foo [= bar] [-y <file>] [-D] [-F]

-C <path> | <file> Look for php. ini file in this directory

-N No php. ini file will be used

-D foo [= bar] Define INI entry foo with value 'bar'

-E Generate extended information for debugger/profiler

-H This help

-I PHP information

-M Show compiled in modules

-V Version number

-P, -- prefix <dir>

Specify alternative prefix path to FastCGI process manager (default:/usr ).

-G, -- pid <file>

Specify the PID file location.

-Y, -- fpm-config <file>

Specify alternative path to FastCGI process manager config file.

-T, -- test FPM configuration and exit

-D, -- daemonize force to run in background, and ignore daemonize option from config file

-F, -- nodaemonize

Force to stay in foreground, and ignore daemonize option from config file

-R, -- allow-to-run-as-root

Allow pool to run as root (disabled by default)


Start the service for the background according to the "-D" prompt above

[Root @ vb01 src] #/usr/sbin/php-fpm-D

Check whether the instance is successfully started. By default, php-fpm starts listening to port 9000:

[Root @ vb01 src] # netstat-tnlpu | grep 9000

Tcp 0 0 127.0.0.1: 9000 0.0.0.0: * LISTEN 5841/php-fpm

How can I disable php-fpm? You can use the following command to disable it:

Kill-QUIT 'cat/var/run/php-fpm/php-fpm.pid'

8. Configure Nginx to support php

The following is a virtual host configuration instance that supports PHP parsing in Nginx:

Server {

Listen 80;

Server_name www.galean1.com;

Location /{

Index index.html index. php;

Root/var/www/galean1;

}

Location ~ \. Php $ {

Root/var/www/galean1;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

Include fastcgi_params;

}

}

Note:

All files with the PHP suffix specified by location are handed over to 127.0.0.1: 9000. The IP address and port here are the IP address and port of the FastCGI process listener.

Fastcgi_param specifies the main directory of the PHP dynamic program. Here I am $ document_root, that is,/var/www/galean1.

Next, restart Nginx

Test Nginx's PHP Parsing

[Root @ vb01 conf] # echo '<? Php phpinfo ();?> '>/Var/www/galean1/phpinfo. php

Then enter the http://www.galean1.com/phpinfo.php in the browser to see if the correct resolution, PHP installation configuration and function list statistics will appear.

This article is from the "galei" blog, please be sure to keep this source http://galean.blog.51cto.com/7702012/1268352


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.