环境:Ubuntu 12.0.4 LTS

nginx(发音"engine x")是一个自由,开放源码,高性能的HTTP server。Nginx以稳定性,丰富的功能集,简单的配置,和低资源消耗而出名。本文将向你展示怎么在ubuntu 12.0.4 LTS 上安装Nginx,php5(及php-fpm),MySQL。

一:安装前做个简单的说明

我使用的域名为example.com,ip地址是218.198.177.252。你可以视具体情况更改这些设置。在下文中我将使用root权限安装所需软件,所以请先切换到root用户:sudo su

二:安装MySQL

apt-get install mysql-server mysql-client

安装过程会提示你为MySQL root 用户提供一个密码----这个密码对 root@localhost可用,同时对root@example.com也可用,因此你需要手动为MySQL root用户指定一个密码:

New password for the MySQL "root" user:

Repeat password for the MySQL "root" user:

三:安装Nginx

apt-get install nginx

1,启动nginx

/etc/init.d/nginx start

2,打开浏览器输入http://127.0.0.1,如果看到Welcome to nginx!,则说明安装成功,ubuntu 12.0.4 LTS上nginx默认的网站根目录在 /usr/share/nginx/www。

四:安装PHP5

PHP5可以在nginx上通过PHP-FPM(PHP—FPM(FastCGI Process Manager) 是一个可选的 FastCGI,添加了一些了一些很有用的特性,特别是对于繁忙的站点)工作。

说明:Nginx不支持对外部程序的直接调用或解析,所有的外部程序(包括PHP)必须通过FastCGI接口调用。

apt-get install php5-fpm

PHP-FPM是一个守护进程(init脚本文件在/etc/init.d/php5-fpm),它运行了一个FastCGI server,端口是 9000。

五:配置 nginx,以下是我本机的配置文件。

1,nginx的配置文件在/etc/nginx/nginx.conf, vim /etc/nginx/nginx.conf 如下:

user www-data;        //指定Nginx Worker 进程运行用户及用户组

worker_processes 4;      / /指定Nginx开启的进程数,每个Nginx进程平均耗费10M-20M内存。

pid /var/run/nginx.pid;    //用来指定进程id的存储文件的位置

events {                      //用来指定Nginx的工作模式,及连接上限数

use epoll;

worker_connections 768;

# multi_accept on;

}

http {

##

# Basic Settings    //基本的设置

##

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 2048;

# server_tokens off;

# server_names_hash_bucket_size 64;

# server_name_in_redirect off;

include /etc/nginx/mime.types;

default_type application/octet-stream;

##

# Logging Settings   //指定日志的存放路径

##

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

##

# Gzip Settings         //开启Gzip 压缩

##

gzip on;

gzip_disable "msie6";

gzip_vary on;

gzip_proxied any;

gzip_comp_level 6;

gzip_buffers 16 8k;

gzip_http_version 1.1;

gzip_types text/plain text/css application/json application/x-Javascript text/xml application/xml application/xml+rss text/javascript;

##

# nginx-naxsi config

##

# Uncomment it if you installed nginx-naxsi

##

#include /etc/nginx/naxsi_core.rules;

##

# nginx-passenger config

##

# Uncomment it if you installed nginx-passenger

##

#passenger_root /usr;

#passenger_ruby /usr/bin/ruby;

##

# Virtual Host Configs      //虚拟主机的配置

##

include /etc/nginx/conf.d/*.conf;

include /etc/nginx/sites-enabled/*;

}

#mail {

#       # See sample authentication script at:

#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

#

#       # auth_http localhost/auth.php;

#       # pop3_capabilities "TOP" "USER";

#       # imap_capabilities "IMAP4rev1" "UIDPLUS";

#

#       server {

#               listen     localhost:110;

#               protocol   pop3;

#               proxy      on;

#       }

#

#       server {

#               listen     localhost:143;

#               protocol   imap;

#               proxy      on;

#       }

#}

2,虚拟主机被定义在server{}中,默认文件在/etc/nginx/sites-available/default,vim /etc/nginx/sites-available/default。

server {

listen   80; ## listen for ipv4; this line is default and implied

listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www;

index index.php index.html index.htm;

# Make site accessible from http://localhost/

server_name _;

location / {

# First attempt to serve request as file, then

# as directory, then fall back to index.html

try_files $uri $uri/ /index.html;

}

location /doc {

root /usr/share;

autoindex on;

allow 127.0.0.1;

deny all;

}

location /images {

root /usr/share;

autoindex off;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/www;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#       proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

try_files $uri =404;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

3,保存文件,使配置生效 /etc/init.d/nginx reload

4,在Nginx的默认网站根目录创建一个PHP的测试文件 vim /usr/share/nginx/www/info.php

php

phpinfo();

?>

5,打开浏览器输入http://127.0.0.1/info.php

你可以看见PHP5已经通过FPM/FastCGI工作了,具体可看Server API那行。向下滚动可以看见所有的模块在PHP5中都是可用的,MySQL还没有被列出来,意味着MySQL还没支持PHP5。

ubuntu nginx php-fpm mysql_Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL相关推荐

  1. nginx etag php,Linux下安装nginx如何启用ETag

    nginx更新速度杠杠的,不到一年时间就更新了这么多版本了,今天一口气从1.2.3升级到1.8.0.为什么升级?因为nginx提供了ETag功能,对流量控制很有效果. 升级之前特意去查了一下资料,看看 ...

  2. ubuntu 编译安装nginx php mysql_ubuntu下安装nginx php mysql

    以下操作是在root下进行(为了方便自己使用) 1.安装nginx a)下载nginx.pcre.openssl.zlib库后,直接解压到/usr/local目录下. b)进入zlib目录后,执行ch ...

  3. linux下安装nginx详细步骤_mac下安装nginx

    前言:nginx的强大不必多言,所以很自然很应当的我也来玩一玩.但是网上许多安装和配置都太那啥了,在这里真的想说一句带有引战性质但我真的无意引战的言论:现在的好多程序员的文笔实在是烂,写的教程让人着实 ...

  4. Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL

     Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL 2012-09-15 11:12:31 标签:php mysql ubuntu nginx php-fpm 原创作品,允许转载 ...

  5. Ubuntu下安装Nginx服务器并进行优化

    一.Nginx介绍   Nginx是由俄罗斯人开发的一款高性能的Web和反向代理服务器,它也可以作为电子邮件的反向代理服务器.其以稳定.并发能力强.占用资源少等显著特点备受广大互联网公司青睐. Ngi ...

  6. 检查linux中nginx是否已安装成功,linux服务下安装nginx 系统版本Ubuntu 18.04.4

    linux服务下安装nginx  系统版本Ubuntu 18.04.4 一.下载nginx包(已存入我的百度网盘) 链接:https://pan.baidu.com/s/19e4FbscqZXNrPP ...

  7. linux环境下安装nginx步骤(不错)

    开始前,请确认gcc g++开发类库是否装好,默认已经安装. ububtu平台编译环境可以使用以下指令 apt-get install build-essential apt-get install ...

  8. mac下安装nginx和php

    From: http://www.jb51.net/article/42715.htm mac下使用homebrew安装安装.配置nginx.mysql.php-fpm的方法. 一.前话: 1.1.环 ...

  9. linux裸机安装nginx,linux环境下安装nginx步骤 - 进击的乌龟 - 博客园

    开始前,请确认gcc g++开发类库是否装好,默认已经安装. ububtu平台编译环境可以使用以下指令 apt- get install build- essential apt - get inst ...

最新文章

  1. Cost Function
  2. 1.3.2 java程序的运行机制和jvm
  3. numpy 点乘_斯坦福CS217(六)Spatial点乘示例
  4. 阿里面试官整理的JVM面试要点,99%的你都不知道!
  5. 和整数相乘_人教版五年级上册第1单元《小数乘整数》课件及同步练习
  6. python 网易_python发送网易邮件
  7. 关于公司建设的一些思考
  8. 云计算云存储的一些基本概念
  9. Nginx的优点和缺点
  10. 孩子握笔姿势错误也易致近视
  11. 052试题 86 - crosscheck 命令及expried
  12. HashMap灵魂26问
  13. YII2 数据库常用操作案例
  14. 维基解密再爆料:CIA 2008年就开始监控iPhone了
  15. JS - Date对象转时间戳
  16. 030 Rust死灵书之让Vec支持slice
  17. java敏感词过滤器组件
  18. 测时差定位算法matlab,时差和频差无源定位方法研究matlab程序
  19. 全网最全的权限系统设计方案
  20. 计算机在心理学实验中的应用举例,普通高等教育国家级规划教材 实验心理学...

热门文章

  1. 很幽默的讲解六种Socket IO模型
  2. 【运维囧事】事先没想到客户光驱坏了,主要原因还是自己当初经验不足
  3. 判断javascript数组的方法
  4. 【转】QString 与中文问题
  5. valueOf与toString方法研究
  6. 头文字C的混战何时方能休?论从某语言怎么怎么样到我要怎样怎样的语言
  7. golang 随机数 math/rand包 crypto/rand包
  8. linux 判断网线是否插入
  9. linux shell 产生随机数
  10. python3 not 用法