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. Android TextView走马灯效果

    布局: <TextView android:id="@+id/myTextView" android:layout_width="match_parent" ...

  2. 操作系统开发系列—13.e.三进程

    我们再来添加一个任务,首先添加一个进程体: void TestC() { int i = 0x2000; while(1){ disp_str("C"); disp_int(i++ ...

  3. 运算符&,|,^

    1.&按位“与”的计算是把两个数字分别写成二进制形式,然后按照每一位进行比较,&计算中,只要有一个是0就算成02.|运算转换成2进制进行比较,两个位只要有一个为1,那么结果就是1,否则 ...

  4. IOS OC声明变量在@interface括号中与使用@property的区别

    方式一:直接在@interface中的大括号中声明. @interface MyTest : NSObject{ NSString *mystr; } 方式二:在@interface中声明,然后再在@ ...

  5. JSP中request getParameter和getAttribute不同(转载)

    (1)request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据,,request.setAttribute()和getAttribute()只是在 ...

  6. jQuery加载一个html页面到指定的div里

    一.jQuery加载一个html页面到指定的div里 把a.html里面的某一部份的内容加载到b.html的一个div里.比如:加载a.html里面的<div id=“row"> ...

  7. WPF学习之路(四)路由

    路由事件概述 功能定义:路由事件是一种可以针对元素树中的多个侦听器(而不是仅针对引发该事件的对象)调用处理程序的事件. 实现定义:路由事件是一个 CLR 事件,可以由RouteEvent 类的实例提供 ...

  8. selenium+python测试

    pip install selenium, 得有图形界面, 这里简单的先演示一个打开浏览器,输入网址的demo,以百度为例 # encoding = utf-8 from selenium impor ...

  9. activiti入门

    一.Activiti简介 Activiti 是一个针对商务人士. 开发人员和系统管理员的轻量级的工作流和业务流程管理 (BPM) 平台.它的核心是Java的高速和可靠的 BPMN 2 流程引擎.它是开 ...

  10. 烂泥:学习Nagios(三): NRPE安装及配置

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 在前两篇文章中,我们介绍了有关nagios的安装与配置,文章为<烂泥:学习Nagios(一):Nagios安装>.<烂泥:学习Nagio ...