ubuntu安装lemp步骤

简述

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

ubuntu安装lemp步骤_第1张图片
lemp

安装nginx

sudo apt-get install nginx

启动nginx服务

sudo service nginx start

浏览器访问localhost

ubuntu安装lemp步骤_第2张图片
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

ubuntu安装lemp步骤_第3张图片
php页面

你可能感兴趣的:(ubuntu安装lemp步骤)