Build nginx + php (LNMP) in 5 minutes

Source: Internet
Author: User
5 minutes to build nginx + php (LNMP) for new users here we must first declare that php installation for Nginx is different from php installation for apache, because php in Nginx is combined with nginx in fastcgi mode, it can be understood that nginx acts as a proxy for php fastcgi, while apache calls php as its own module.

  • Let's compile and install php and php-fpm first. see the http://heilinux.blog.51cto.com/6123663/1575582.

  • Modify configuration file

    1

    Cd php-5.6.2

    Cp php. ini-production/usr/local/php/etc/php. inicp/usr/local/php/etc/php-fpm.conf.default.conf php-fpm.conf

    After saving the configuration file, check whether the configuration is correct:

    /Usr/local/php/sbin/php-fpm-t

    If "test is successful" is displayed, the configuration is correct.

    Start php-fpm

    Cp/usr/local/src/php-5.3.27/sapi/fpm/init. d. php-fpm/etc/init. d/php-fpmchmod 755/etc/init. d/php-fpmservice php-fpm start

    If you want it to start up, execute:

    Chkconfig php-fpm on

    Check whether startup is enabled:

    Ps aux | grep php-fpm
    Netstat-ant | grep 9000

    Check if there are many processes (about 20 or more) and your port 9000 is enabled ?.

    《《《《《《《《《《《《《《《《《《《

    Install nginx

    Start nginx installation

    1

    2

    Wget

    Http: // nginx. org/download/nginx-1. 6.2. tar. gz // latest stable version


    Decompress nginx

    Tar zxvf nginx-1.6.2.tar.gz

    Configure compilation parameters

    Cd nginx-1.6.2./configure \ -- prefix =/usr/local/nginx \ -- with-http_realip_module \ -- with-http_sub_module \ -- with-http_gzip_static_module \ -- with-pcre

    Compile nginx

    Make

    Install nginx

    Make install

    Because nginx is relatively small, it will soon be installed, and there will be no errors. If an error occurs, yum will install pcre-devel (Hey, this is the problem, ask du Niang another question .)

    《《《《《《《《《《《《《《《《《《《《《

    Add a symbolic link to the nginx main program

    1

    2

    Ln-sf/usr/local/nginx/sbin/nginx/usr/sbin

    1

    Test nginx-t. If it succeeds, isn't it a sense of accomplishment? don't worry. let's continue!

    Change nginx configuration

    First, clear the original configuration file:

    >/Usr/local/nginx/conf/nginx. conf

    The ">" symbol is previously introduced by James. to redirect, use it separately to quickly clear a text document.

    Vim/usr/local/nginx/conf/nginx. conf

    Write the following content:

    User nobody; worker_processes 2; error_log/usr/local/nginx/logs/nginx_error.log crit; pid/usr/local/nginx/logs/nginx. pid; worker_rlimit_nofile 51200; events {use epoll; worker_connections 6000;} http {include mime. types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$ remote_addr $ http_x_forwarded_for [$ time _ Local] ''$ host" $ request_uri "$ status'' "$ http_referer" "$ http_user_agent" '; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3 m; client_body_timeout 3 m; send_timeout 3 m; connection_pool_size 256; limit 1 k; limit 8 4 k; request_pool_size 4 k; output_buffers 4 32 k; postpone_output 1460; limit 10 m; limit 256 k; restart/usr/local/nginx/restart; proxy_temp_path/usr/local/nginx/proxy_temp; fastcgi_temp_path/usr/local/nginx/fastcgi_temp; restart on; tcp_nodelay on; gzip on; gzip_min_length 1 k; gzip_buffers 4 8 k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; server {listen 80; server _ Name localhost; index index.html index.htm index. php; root/usr/local/nginx/html; location ~ \. Php $ {include fastcgi_params; fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME/usr/local/nginx/html $ fastcgi_script_name ;}}}

    You believe it, you have fixed LNMP 《《《《《《《《《《《《《《

    Test whether to parse the php file

    Create a test file:

    Vim/usr/local/nginx/html/2.php

    The content is as follows:

     

    Test:

    Curl localhost/2.php

    What do you see .. Do not doubt your eyes, do not tears. You have succeeded.

    Welcome to my personal website

    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.