Build nginx + php in 5 minutes and nginxphp in 5 minutes

Source: Internet
Author: User

Build nginx + php in 5 minutes and nginxphp in 5 minutes

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 the 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 cdphp-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

12 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-http_stub_status_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

12   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 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 3m;    client_body_timeout 3m;    send_timeout 3m;    connection_pool_size 256;    client_header_buffer_size 1k;    large_client_header_buffers 8 4k;    request_pool_size 4k;    output_buffers 4 32k;    postpone_output 1460;    client_max_body_size 10m;    client_body_buffer_size 256k;    client_body_temp_path /usr/local/nginx/client_body_temp;    proxy_temp_path /usr/local/nginx/proxy_temp;    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;    fastcgi_intercept_errors on;    tcp_nodelay on;    gzip on;    gzip_min_length 1k;    gzip_buffers 4 8k;    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:

<? Php echo "test php Parsing";?>

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.