Ubuntu16.04搭建LNMP

1、更新系统源

sudo apt-get update

2、安装Nginx

sudo apt-get install nginx

3、安装MySQL5.7

sudo apt-get install mysql-server  mysql-client

4、 安装php7.0、php7.0-fpm、php7.0-mysql

sudo apt-get install php7.0  php7.0-fpm  php7.0-mysql

5、配置Nginx使其解析php

(1)修改php7.0-fpm配置

// 打开其配置文件
vim /etc/php/7.0/fpm/php.ini
找到cgi.fix_pathinfo=0,将其改为cgi.fix_pathinfo=1

(2)修改Nginx配置

// 打开配置文件
vim /etc/nginx/sites-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html; #网站根目录
    index index.html index.htm index.nginx-debian.html index.php; #追加index.php

    server_name _; #绑定网站域名

    location / {
        try_files $uri $uri/ =404 /index.php?$query_string; #配置转发规则
    }

    # 解析php
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock; #利用php-fpm套接字解析php
    }
}

6、重启Nginx和PHP

// 重启nginx 
sudo service nginx restart
// 重启php7.0-fpm服务 
sudo service php7.0-fpm restart
标签: