ubuntu 16.04 搭建 nginx+php 环境

安装 nginx

apt install nginx

访问 localhost,出现 Welcome to nginx! 则证明安装成功。

安装php

apt install php-fpm

PHP fix_pathinfo 潜在安全漏洞修复,在 /etc/php/7.0/fpm/php.ini 中找到

;cgi.fix_pathinfo=1

改为

cgi.fix_pathinfo=0

重启 php

service php7.0-fpm restart

创建新配置 /etc/nginx/sites-available/domain

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

    # listen [::]:443 ssl http2;
    # listen 443 ssl http2;

    # include ssl.conf;
    # ssl_certificate /path/to/crt;
    # ssl_certificate_key /path/to/key;

    root /var/www/domain;
    index index.html index.htm index.php;

    # server_name localhost;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

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

    location ~ /\.ht {
        deny all;
    }
}

启用新站点

sudo ln -s /etc/nginx/sites-available/domain /etc/nginx/sites-enabled

重启Nginx

service nginx restart

安装使用 phpmyadmin

apt-get install phpmyadmin php-mbstring php-gettext
# ln -s /usr/share/phpmyadmin/  /var/www/html/

修改上传文件大小
打开nginx配置文件,路径一般是 /etc/nginx/nginx.conf,在 http{} 段中加入 client_max_body_size 20m;(20m为允许最大上传的大小),重启Nginx