Ubuntu 14.04 LTS下安装 LNMP环境

  1. 安装 MySQL 5 数据库

    apt-get install mysql-server mysql-client,安装过程中会询问建立 Root 账户密码,连续输入两次

  2. 安装 Nginx

    在安装 Nginx 之前,如果你已经安装 Apache2 先删除在安装 nginx:
    service apache2 stop
    update-rc.d -f apache2 remove
    apt-get remove apache2
    apt-get install nginx
    启动 nginx 服务:
    service nginx start
    试试安装是否成功,在浏览器输入IP或主机地址看是否出来欢迎页面,
    在 Ubuntu 14.04 中默认的根目录为 /usr/share/nginx/html

  1. 安装 PHP5

    我们必须通过 PHP-FPM 才能让PHP5正常工作,安装命令:
    apt-get install php5-fpm
    php-fpm是一个守护进程

  2. 配置 nginx

    使用Vi打开配置文件/etc/nginx/nginx.conf :
    vi /etc/nginx/nginx.conf
    [...]
    worker_processes 4;
    [...]
    keepalive_timeout 2;
    [...]

  3. 默认虚拟主机设置文件

/etc/nginx/sites-available/default 按如下设置:
vi /etc/nginx/sites-available/default
[...]
server {
listen 80;
listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    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 displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            allow ::1;
            deny all;
    }

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #       proxy_pass http://127.0.0.1:8080;
    #}

    #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/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            # With php5-cgi alone:
            #fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            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;
    }

}
[...]


取消同时侦听 IPv4 和 IPv6 的80端口。
server_name _; 默认主机名 (当然你可以修改,例如修改为: www.example.com).
index主页这一行我们加入 index.php。
PHP 重要配置配置 location ~ .php$ {} 这几行我们需要启动,反注释掉。另外再添加一行:try_files $uri =404。
(其他配置查看http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHP 和 http://forum.nginx.org/read.php?2,88845,page=3).
保存文件并重新加载 nginx 命令:
service nginx reload
如果加载失败,直接用删除所有配置内容,用上面的信息替换

  1. 打开配置文件 /etc/php5/fpm/php.ini

    vi /etc/php5/fpm/php.ini
    设置 cgi.fix_pathinfo=0

  1. 重新加载 PHP-FPM:

    service php5-fpm reload
    现在创建一个探针文件保存在 /usr/share/nginx/html目录下
    vi /usr/share/nginx/html/info.php

  1. 让 PHP5 支持 MySQL

    apt-cache search php5
    然后使用下面的命令安装:
    apt-get install php5-mysql php5-curl php5-gd php5-intl 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
    APC是一个自由和开放的PHP操作码缓存器缓存和优化PHP的中间代码。这是类似于其他PHP操作码cachers,
    如eAccelerator、XCache。这是强烈建议有一个安装加速你的PHP页面。
    使用下面的命令安装 APC:
    apt-get install php-apc
    现在重新加载 PHP-FPM:
    service php5-fpm reload
    刷新 http://192.168.0.100/info.php 向下滚动看看模块是否支持

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值