手机版
你好,游客 登录 注册
背景:
阅读新闻

Ubuntu下安装PHP+Nginx

[日期:2012-08-30] 来源:Linux社区  作者:liuzhijun [字体:大 中 小]

系统环境:Ubuntu12.04 desktop

1、sudo apt-get install php5-cgi

(因为nginx只支持gast-cgi,所以要安装php-5-cgi)

提示安装以下资源

将会安装下列额外的软件包:

libapache2-mod-php5 php5-cli php5-common php5-gd php5-mysql

建议安装的软件包:

php-pear php5-suhosin

下列【新】软件包将被安装:

php5-cgi

下列软件包将被升级:

libapache2-mod-php5 php5-cli php5-common php5-gd php5-mysql

2、sudo apt-get install nginx

3、vim /etc/init.d/php-fcgi

  1. server {   
  2.  21         #listen   80; ## listen for ipv4; this line is default and implied   
  3.  22         #listen   [::]:80 default ipv6only=on; ## listen for ipv6   
  4.  23    
  5.  24         root /usr/share/nginx/www;   
  6.  25         index index.html index.htm;   
  7.  26    
  8.  27         # Make site accessible from http://localhost/   
  9.  28         server_name localhost;   
  10.  29    
  11.  30         location / {   
  12.  31                 # First attempt to serve request as file, then   
  13.  32                 # as directory, then fall back to index.html   
  14.  33                 try_files $uri $uri/ /index.html;   
  15.  34                 # Uncomment to enable naxsi on this location   
  16.  35                 # include /etc/nginx/naxsi.rules   
  17.  36         }   
  18.  37    
  19.  38         location /doc/ {   
  20.  39                 alias /usr/share/doc/;   
  21.  40                 autoindex on;   
  22.  41                 allow 127.0.0.1;   
  23.  42                 deny all;   
  24.  43         }   
  25.  44    
  26.  45         # Only for nginx-naxsi : process denied requests   
  27.  46         #location /RequestDenied {   
  28.  47                 # For example, return an error code   
  29.  48                 #return 418;   
  30.  49         #}   
  31.  50    
  32.  51         #error_page 404 /404.html;   
  33.  52    
  34.  53         # redirect server error pages to the static page /50x.html   
  35.  54         #   
  36.  55         #error_page 500 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 on 127.0.0.1:9000  
  42.  61         #   
  43.  62         location ~ \.php$ {   
  44.  63         #       fastcgi_split_path_info ^(.+\.php)(/.+)$;   
  45.  64         #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini   
  46.  65         #   
  47.  66         #       # With php5-cgi alone:   
  48.  67                 fastcgi_pass 127.0.0.1:9000;   
  49.  68         #       # With php5-fpm:   
  50.  69         #       fastcgi_pass unix:/var/run/php5-fpm.sock;   
  51.  70                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   
  52.  71                 fastcgi_index index.php;   
  53.               }       

sudo /etc/init.d/nginx restart  (注意这里以sduo的方式重启,否则因为权限文件报错)

4、vim index.php   (在  /usr/share/nginx/www 下面创建文件index.php测试)

  1. <?php   
  2.   
  3. echo "hello world";   
  4.   
  5. ?> 

结果出现如下错误:connect() failed (111: Connection refused) while connecting to upstream

那是因为没有安装  php5-fmp

5、sudo apt-get install php5-fmp

重启nginx服务后就可以看到页面结果了。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款