Tencent CentOS ECS nginx + php environment configuration

Source: Internet
Author: User
Tags create index fpm http request centos

1. Configure nginx

1. Start the nginx service.
The command is as follows:
[Root @ VM_185_51/] # service nginx restart

2. Test whether the nginx service is running normally.
If 'index.html 'saved is displayed at the end, the nginx service is normal.
[Root @ VM_185_51/] # wget http: // 127.0.0.1
-- 2013-02-20 17:07:26 -- http: // 127.0.0.1/
Connecting to 127.0.0.1: 80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 151 [text/html]
Saving to: 'index.html'
100% [============================================== ========================================================== ============>] 151 --. -K/s in 0 s
17:07:26 (37.9 MB/s)-'index.html 'saved [151/151]

3. Check whether the nginx service is running properly using the public IP address of the CentOS ECS in the browser.
If the following figure is displayed, nginx is successfully installed and configured.

2. Configure PHP

1. Start php-fpm.
[Root @ VM_185_51/] # service php-fpm start

2. Modify the configuration of php-fpm and nginx to achieve linkage between nginx and php.
(1) view the default php-fpm configuration.
[Root @ VM_185_51/] # cat/etc/php-fpm.d/www. conf | grep-I 'Listen ='
Listen = 127.0.0.1: 9000
(2) the default listening port configured for php-fpm is 9000. Now, you only need to modify the configuration and forward requests parsed by php to 127.0.0.0: 9000.
Modify the nginx configuration by running the following command:
[Root @ VM_185_51/] # vim/etc/nginx/conf. d/default. conf

After the modification is complete, the actual configuration is as follows, and the red text is the modified part:

Server {
Listen 80;
Root/usr/share/nginx/html;
Server_name localhost;
# Charset KOI8-R;
# Access_log/var/log/nginx/log/host. access. log main;
Location /{
Index index.html index.htm;
  }
# Error_page 404/404 .html;
# Redirect server error pages to the static page/50x.html
  #
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/share/nginx/html;
  }
# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
  #
# Location ~ \. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
  #
Location ~ \. Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
  }
# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
  #
# Location ~ /\. Ht {
# Deny all;
#}
}
After the modification, press "Esc" and enter ": wq" to save the file and return it.
Run the following command to check whether the configuration is correct:
[Root @ VM_185_51/] # cat/etc/nginx/conf. d/default. conf

3. The configuration takes effect.

Restart nginx to make the configuration take effect.
The command is as follows:
[Root @ VM_185_51/] # service nginx restart
Stopping nginx: [OK]
Starting nginx: [OK]

4. Verify environment configuration

1. Create index. php in the web directory.
The command is as follows:
[Root @ VM_185_51/] # vim/usr/share/nginx/html/index. php
The content of the index. Php file is as follows:
<? Php
Echo "<title> Test Page </title> ";
Echo "hello world ";
?>
2. Check whether the environment configuration is successful through the public IP address of the CentOS ECS in the browser.

If "hello world" is displayed on the page, the configuration is successful.

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.