ubuntu安装lemp步骤


简述

所谓lemp,就是指 linux + nginx + mysql + php,也称之为lnmp,因为nginx(engine x)的读法不同。本文以lemp为该组合的简称。系统环境是Ubuntu 16.04.3 LTS

lemp

安装nginx

sudo apt-get install nginx

启动nginx服务

sudo service nginx start

浏览器访问localhost

nginx访问页面

安装mysql

sudo apt-get install mysql-server

安装过程中需要输入root用户密码

安装php

sudo apt-get install php-fpm php-mysql

启动php-fpm

sudo service php7.0-fpm start

配置nginx

默认的nginx.conf配置是这样的:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }
}

需要进行以下配置才能处理访问php页面的请求

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /.ht {
        deny all;
    }
}

测试nginx配置是否正确

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

重启nginx

sudo service nginx restart

测试php页面

新建 /var/www/html/info.php 文件

phpinfo();

访问http://localhost/info.php

php页面

优质内容筛选与推荐>>
1、Mybatis关联关系配置(一对一、多对一)
2、RESTful风格的Web服务框架:Swagger
3、可排序列细线框表格
4、MongoDB系列(二):C#应用
5、WPF TabControl 模拟动画


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号