System Environment: ubuntu12.041_top1, sudoapt-getinstallphp5-cgi (because nginx only supports gast-cgi, so install php-5-cgi) Tips install the following resources will install the following additional packages: The packages recommended by the libapache2-mod-php5php5-cliphp5-commonphp5-gdphp5-mysql: php-pe
System Environment: Ubuntu12.04 desktop
1. sudo apt-get install php5-cgi
(Since nginx only supports gast-cgi, you need to install the php-5-cgi)
Prompt to install the following resources
The following additional software packages will be installed:
Libapache2-mod-php5 php5-cli php5-common php5-gd
Recommended software packages:
Php-pear php5-suhosin
The following [new] software packages will be installed:
Php5-cgi
The following software packages will be upgraded:
Libapache2-mod-php5 php5-cli php5-common php5-gd
2. sudo apt-get install nginx
3. vim/etc/init. d/php-fcgi
- Server {
- 21# Listen80### ListenForIpv4;ThisLine isDefaultAnd implied
- 22# Listen [:]:80 DefaultListen 6only = on; # listenForIpv6
- 23
- 24Root/usr/share/nginx/www;
- 25Index index.html index.htm;
- 26
- 27# Make site accessible from http:// Localhost/
- 28Server_name localhost;
- 29
- 30Location /{
- 31# First attempt to serve request as file, then
- 32# As directory, then fall back to index.html
- 33Try_files $ uri // index.html;
- 34# Uncomment to enable naxsi onThisLocation
- 35# Include/etc/nginx/naxsi. rules
- 36}
- 37
- 38Location/doc /{
- 39Alias/usr/share/doc /;
- 40Autoindex on;
- 41Allow127.0.0.1;
- 42Deny all;
- 43}
- 44
- 45# OnlyForNginx-naxsi: process denied requests
- 46# Location/RequestDenied {
- 47# For example,ReturnAn error code
- 48#Return 418;
- 49#}
- 50
- 51# Error_page404/404. Html;
- 52
- 53# Redirect server error pages toStaticPage/50x.html
- 54#
- 55# Error_page500 502 503 504/50x.html;
- 56# Location =/50x.html {
- 57# Root/usr/share/nginx/www;
- 58#}
- 59
- 60# Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000
- 61#
- 62Location ~ \. Php $ {
- 63# Fastcgi_split_path_info ^ (. + \. php) (/. +) $;
- 64# NOTE: You shoshould have"Cgi. fix_pathinfo = 0 ;"In php. ini
- 65#
- 66# With php5-cgi alone:
- 67Fastcgi_pass127.0.0.1:9000;
- 68# With php5-fpm:
- 69# Fastcgi_pass unix:/var/run/php5-fpm.sock;
- 70Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
- 71Fastcgi_index index. php;
- }
Sudo/etc/init. d/nginx restart)
4. vim index. php (create the file index. php under/usr/share/nginx/www for testing)
-
- Echo "Hello world";
- ?>
The following error occurs: connect () failed (111: Connection refused) while connecting to upstream.
That's because php5-fmp is not installed.
5. sudo apt-get install php5-fmp
After restarting the nginx service, you can see the page results.