ubuntu下nginx+php5环境的部署和centos系统下的部署稍有不同,废话不多说,以下为操作记录:
1)nginx安装
root@ubuntutest01-KVM:~# sudo apt-get update && sudo apt-get upgrade
root@ubuntutest01-KVM:~# sudo apt-get install libpcre3 libpcre3-dev zlib1g-dev libssl-dev build-essential openssl libssl0.9.8 libssl-dev
root@ubuntutest01-KVM:~# wget http://nginx.org/download/nginx-1.8.0.tar.gz
root@ubuntutest01-KVM:~# tar -zxvf nginx-1.8.0.tar.gz
root@ubuntutest01-KVM:~# cd nginx-1.8.0
root@ubuntutest01-KVM:~# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
root@ubuntutest01-KVM:~# make && make install

2)php5的安装
add-apt-repository 命令是 apt 源的添加,ppa 就是软件对应的源,在官网上可以找到
root@ubuntutest01-KVM:~# sudo add-apt-repository ppa:ondrej/php5-5.6

如果上面命令执行后报错和没有发现命令则执行
root@ubuntutest01-KVM:~# sudo apt-get install Python-software-properties
root@ubuntutest01-KVM:~# sudo apt-get update
root@ubuntutest01-KVM:~# sudo apt-get install php
root@ubuntutest01-KVM:~# php5 -v

安装好php后,在nginx里添加对接php的配置后,访问.php文件会报错502!
这是因为nginx中访问.php文件的请求都交给php-fpm程序处理的,php-fpm监听9000端口
所以还有启动php-fpm程序。

安装php-fpm
root@ubuntutest01-KVM:~# apt-get install php5-fpm php5-gd php5-cli php5-curl php5-mcrypt php5-mysql php5-readline

启动php-fpm
root@ubuntutest01-KVM:~# service php5-fpm start
root@ubuntutest01-KVM:~# ps -ef|grep php5-fpm
root@ubuntutest01-KVM:~# lsof -i:9000

但是发现php5-fpm启动后,9000端口却没有起来!这是为什么?
这是因为php-fpm有两种监听方式:一种是.sock文件方式,另一种是9000端口方式
修改办法:
root@ubuntutest01-KVM:~# vim /etc/php5/fpm/pool.d/www.conf
.....
;listen = /var/run/php5-fpm.sock               //注释这行,这是默认的监听方式
listen = 9000                                            //改为监听9000端口方式

重启php-fpm
root@ubuntutest01-KVM:~# service php5-fpm restart
root@ubuntutest01-KVM:~# lsof -i:9000        //发现9000端口已经起来了

3)nginx+php配置
root@ubuntutest01-KVM:~# vim /usr/local/nginx/conf/nginx.conf       //将nginx启动用户改成www-data,确保这个用户存在,不存在就手动创建,保证nginx和php启动用户一致

user  www-data;
worker_processes 8; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; pid logs/nginx.pid; events {
worker_connections 65535;
} http {
include mime.types;
default_type application/octet-stream;
charset utf-8; log_format main '$http_x_forwarded_for $remote_addr $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_cookie" $host $request_time';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65; fastcgi_connect_timeout 3000;
fastcgi_send_timeout 3000;
fastcgi_read_timeout 3000;
fastcgi_buffer_size 256k;
fastcgi_buffers 8 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on; client_header_timeout 600s;
client_body_timeout 600s; client_max_body_size 100m;
client_body_buffer_size 256k; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
gzip_vary on; include vhosts/*.conf;
}

root@ubuntutest01-KVM:~# vim /usr/local/nginx/conf/vhosts/vote.com.conf

server {
listen 8080;
server_name www.wangshibo.com; access_log /usr/local/nginx/logs/access.log main;
error_log /usr/local/nginx/logs/error.log; location / {
root /home/www/vote;
try_files $uri $uri/ @router;
index index.html index.php index.htm;
} location /nginx_status {
stub_status on;
access_log off;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} location @router {
rewrite ^.*$ /index.php last;
} location ~ \.php$ {
root /home/www/vote;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //这一行和下面一行要加上,不然访问php文件可能出现空白!
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
} location ~ ^/(status|ping)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
}

测试文件(html文件和php文件)
root@ubuntutest01-KVM:~# vim /home/www/vote/test.html
sdfsadf
12313123
root@ubuntutest01-KVM:~# vim /home/www/vote/test.php

<?php              //这一行不能空格,否则访问会有问题
phpinfo();
?>

修改php-fpm文件(确保/etc/php5/fpm/php-fpm.conf文件中打开了include=/etc/php5/fpm/pool.d/*.conf)
root@ubuntutest01-KVM:~# vim /etc/php5/fpm/pool.d/www.conf
....
user = www-data
group = www-data
....
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

重启nginx和php-rpm
root@ubuntutest01-KVM:~# /usr/local/nginx/sbin/nginx -s reload
root@ubuntutest01-KVM:~# /etc/init.d/php5-fpm restart

最后,验证访问是否正常:

ubuntu下nginx+php5的部署的更多相关文章

  1. Ubuntu下Nginx启动、停止等常用命令

    本文详细介绍Ubuntu下Nginx启动.停止等常用命令.在开发过程中,我们会经常的修改Nginx的配置文件,每次修改配置文件都可以先测试下本次修改的配置文件是否正确,可以利用以下命令: servic ...

  2. Ubuntu下Zabbix服务器监控工具部署

    Ubuntu下Zabbix服务器监控工具部署 一 安装安装Apache.Mysql.Php.zabbix sudo apt-get update sudo apt-get install apache ...

  3. Ubuntu下nginx+uwsgi+flask的执行环境搭建

    选择web framwork是个非常艰难的事情, 主要分为轻量级和重量级框架. 因为没有搭建站点这样的须要, 所以回避SSH, Django这样的框架, 而选择一个轻量级框架. 自己也比較青睐pyth ...

  4. linux下nginx负载均衡部署

    nginx负载均衡部署 Nginx("engine x") 是一个高性能的 HTTP 和 反向代理 server,也是一个 IMAP/POP3/SMTP 代理server. Ngi ...

  5. ubuntu 下 Nginx相关设置

    ubuntu安装Nginx之后的文件结构大致为: 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下 启动程序文件在/usr/ ...

  6. 【转】windows下nginx+mono+fastCGI部署asp.net网站

    原文链接:http://www.cnblogs.com/amityat/archive/2011/08/23/2150153.html 1,什么是nginx 简介Nginx ("engine ...

  7. Ubuntu下Nginx安装

    1.1 安装Nginx $sudo apt-get install nginx Ubuntu安装之后的文件结构大致为: 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/ ...

  8. ubuntu下nginx+PHP-FPM安装配置

    安装nginx apt-get install nginx 配置nginx 位置: /etc/nginx/nginx.conf  ,其中包含了 include /etc/nginx/conf.d/*. ...

  9. ubuntu下nginx的启停等常用命令

    开发过程中,我们会经常的修改nginx的配置文件,每次修改配置文件都可以先测试下本次修改的配置文件是否正确,可以利用以下命令: ? 1 service nginx -t -c /alidata/ser ...

随机推荐

  1. CoreLocation 定位

    前言: 本章会使用OC和Swift分别进行实现,需要了解Swift的小伙伴可以翻一下之前的博文 LBS和SoloMo(索罗门) LBS:基于位置的服务,根据定位展示周边美食.景点等信息(全称:Loca ...

  2. Android 网络图片查看器

    今天来实现一下android下的一款简单的网络图片查看器 界面如下: 代码如下: <LinearLayout xmlns:android="http://schemas.android ...

  3. AFNetworking 3.0 源码解读 总结

    终于写完了 AFNetworking 的源码解读.这一过程耗时数天.当我回过头又重头到尾的读了一篇,又有所收获.不禁让我想起了当初上学时的种种情景.我们应该对知识进行反复的记忆和理解.下边是我总结的 ...

  4. PreferenceScreen监听子项的刷新

    有个PreferenceScreen,他有一些个子项目.它的Summary需要根据子项的设置来改变的,所以需要监听子项的刷新事件. preferenceScreen.setOnPreferenceCh ...

  5. .Net Attribute详解(下) - 使用Attribute武装枚举类型

    接上文.Net Attribute详解(上)-Attribute本质以及一个简单示例,这篇文章介绍一个非常实用的例子,相信你一定能够用到你正在开发的项目中.枚举类型被常常用到项目中,如果要使用枚举To ...

  6. 【转发】揭秘Facebook 的系统架构

    揭底Facebook 的系统架构 www.MyException.Cn   发布于:2012-08-28 12:37:01   浏览:0次 0 揭秘Facebook 的系统架构 www.MyExcep ...

  7. HTML基础(四)——设置超链接的样式示例

     ***设置超链接的样式示例  a:link 超链接被点前状态 a:visited 超链接点击后状态 a:hover 悬停在超链接时 a:active 点击超链接时 在定义这些状态时,有一个顺序l v ...

  8. Tomcat:Custom a common error page valve for all web application in tomcat

    如果在一个Tomcat Server上会部署多个Web应用,又希望这多个Web应用共用一套错误页面,而不是使用默认的错误页面.就需要自定义错误页面了. 在每个web应用中都可以通过error-page ...

  9. 记录一些在用wcf的过程中走过的泥巴路 【第一篇】

    自从转移战场之后,比以前忙多了,博客也没能及时跟上,原本准备继续mvc系列,但是在那边技术比较陈旧还没能用得上,话说有3年没接触这玩意了,东西也 都忘了差不多了,既然再次接触,我也就继续温习温习,记录 ...

  10. PHP 5.3.0以上推荐使用mysqlnd驱动

    1. 什么是 mysqlnd 驱动 ? PHP 手册上的描述 : MySQL Native Driver is a replacement for the MySQL Client Library ( ...