Install PHP + Nginx in Ubuntu

Source: Internet
Author: User
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

  1. Server {
  2.  21# Listen80### ListenForIpv4;ThisLine isDefaultAnd implied
  3.  22# Listen [:]:80 DefaultListen 6only = on; # listenForIpv6
  4.  23
  5.  24Root/usr/share/nginx/www;
  6.  25Index index.html index.htm;
  7.  26
  8.  27# Make site accessible from http:// Localhost/
  9.  28Server_name localhost;
  10.  29
  11.  30Location /{
  12.  31# First attempt to serve request as file, then
  13.  32# As directory, then fall back to index.html
  14.  33Try_files $ uri // index.html;
  15.  34# Uncomment to enable naxsi onThisLocation
  16.  35# Include/etc/nginx/naxsi. rules
  17.  36}
  18.  37
  19.  38Location/doc /{
  20.  39Alias/usr/share/doc /;
  21.  40Autoindex on;
  22.  41Allow127.0.0.1;
  23.  42Deny all;
  24.  43}
  25.  44
  26.  45# OnlyForNginx-naxsi: process denied requests
  27.  46# Location/RequestDenied {
  28.  47# For example,ReturnAn error code
  29.  48#Return 418;
  30.  49#}
  31.  50
  32.  51# Error_page404/404. Html;
  33.  52
  34.  53# Redirect server error pages toStaticPage/50x.html
  35.  54#
  36.  55# Error_page500 502 503 504/50x.html;
  37.  56# Location =/50x.html {
  38.  57# Root/usr/share/nginx/www;
  39.  58#}
  40.  59
  41.  60# Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000
  42.  61#
  43.  62Location ~ \. Php $ {
  44.  63# Fastcgi_split_path_info ^ (. + \. php) (/. +) $;
  45.  64# NOTE: You shoshould have"Cgi. fix_pathinfo = 0 ;"In php. ini
  46.  65#
  47.  66# With php5-cgi alone:
  48.  67Fastcgi_pass127.0.0.1:9000;
  49.  68# With php5-fpm:
  50.  69# Fastcgi_pass unix:/var/run/php5-fpm.sock;
  51.  70Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
  52.  71Fastcgi_index index. php;
  53. }

Sudo/etc/init. d/nginx restart)

4. vim index. php (create the file index. php under/usr/share/nginx/www for testing)

  1. Echo "Hello world";
  2. ?>

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.

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.