找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
积分等级发帖收益的说明江阴论坛帮助汇总江阴论坛管理规则(必看)江阴论坛版主招聘中江阴论坛已运行
查看: 3514|回复: 0

[技术分享] Ubuntu 11.04 安装nginx+php5+mysql 的web服务器

[复制链接]
发表于 2011-8-27 10:14:59 | 显示全部楼层 |阅读模式
 Nginx是一款有俄罗斯人开发的轻量级的web 服务器软件,现在很多网站都在使用这款软件,包括国内的互联网巨头腾讯网站都在使用Nginx。这款软件优点,免费、开源、高性能,而且稳定、功能强大、配置简单、资源消耗小。通过 PHP-FPM在ubuntu 11.04中支持 php5和mysql。

  好了,不多说了,现在开始安装。

  1.初步说明

  在本教程中使用的主机名为 server1.example.com ,IP地址 192.168.0.100 。你的设置会不一样,所以你必须在适当情况下更换。

  首先所有的步骤使用root,先切换到root用户,终端输入命令:
  1. sudo su
复制代码
2.安装MySQL 5.0,在终端输入:
  1. apt-get install mysql-server mysql-client
复制代码
安装过程中会让你输入根用户密码两次。

  3.安装Nginx
  1. apt-get install nginx
复制代码
启动nginx命令:
  1. /etc/init.d/nginx start
复制代码
如果你的IP是192.168.0.100在终端输入查看nginx是否正常运行.

  提示:在ubuntu11.04中nginx 默认网站目录为
  1. /usr/share/nginx/www
复制代码
4.安装PHP5
  1. apt-get install php5-fpm
复制代码
PHP – FPM是一个守护进程(与初始化脚本 / etc/init.d/php5-fpm )运行FastCGI服务器上的端口 9000 。

  5.nginx的配置

  配置文件/etc/nginx/nginx.conf
  1. vi /etc/nginx/nginx.conf
复制代码
你可以通过http://wiki.codemongers.com/NginxFullExamplehttp://wiki.codemongers.com/NginxFullExample2网址了解更多配置信息。

  增加工作进程,可选,可以不修改
  1.   worker_processes 5;
  2.   keepalive_timeout 2;
复制代码
默认虚拟主机配置文件地址/etc/nginx/sites-available/default
  1. vi /etc/nginx/sites-available/default
复制代码
  1.   server {

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

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

  4.   root /usr/share/nginx/www;

  5.   index index.php index.html index.htm;

  6.   # Make site accessible from http://localhost/

  7.   server_name _;

  8.   location / {

  9.   # First attempt to serve request as file, then

  10.   # as directory, then fall back to index.html

  11.   try_files $uri $uri/ /index.html;

  12.   }

  13.   location /doc {

  14.   root /usr/share;

  15.   autoindex on;

  16.   allow 127.0.0.1;

  17.   deny all;

  18.   }

  19.   location /images {

  20.   root /usr/share;

  21.   autoindex off;

  22.   }

  23.   #error_page 404 /404.html;

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

  25.   #

  26.   error_page 500 502 503 504 /50x.html;

  27.   location = /50x.html {

  28.   root /usr/share/nginx/www;

  29.   }

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

  31.   #

  32.   #location ~ \.php$ {

  33.   # proxy_pass http://127.0.0.1;

  34.   #}

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

  36.   #

  37.   location ~ \.php$ {

  38.   fastcgi_pass 127.0.0.1:9000;

  39.   fastcgi_index index.php;

  40.   include fastcgi_params;

  41.   }

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

  43.   # concurs with nginx’s one

  44.   #

  45.   location ~ /\.ht {

  46.   deny all;

  47.   }

  48.   }
复制代码
稍微有点经验的同学都可以看的懂里面需要修改的信息

  现在保存文件并重新启动nginx的:
  1. /etc/init.d/nginx restart
复制代码
你可以建立一个探针文件,试一试php是否正常运行。
  1. vi /usr/share/nginx/www/info.php
复制代码
在浏览器输入地址查看,例如:http://192.168.0.100/info.php

  6.让PHP5获得MySQL支持,需要一个模块
  1. apt-cache search php5
复制代码
安装软件:
  1. apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
复制代码
现在重新启动PHP-FPM:
  1. /etc/init.d/php5-fpm restart
复制代码
现在浏览器刷新一下:http://192.168.0.100/info.php

  看看是否已经支持安装的模块。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|江阴人家

GMT+8, 2024-3-29 00:14 , Processed in 0.019131 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表