Ubuntu16.04搭建LNMP

说明:nginx、 mysql5.7、php7.0

1.安装之前先更新系统

sudo apt-get update

2.安装nginx

sudo apt-get install nginx

3.安装php7.0和php7.0-fpm

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

4.配置nginx使其解析php

打开nginx的网站配置文件

vim /etc/nginx/sites-available/default

修改成以下配置:

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/ /index.php?$query_string; #配置转发规则
   }

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

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

修改php7.0-fpm配置,打开其配置文件,找到cgi.fix_pathinfo=1,将其改为cgi.fix_pathinfo=0

vim /etc/php/7.0/fpm/php.ini

a. 重启nginx service nginx restart
b.重启php7.0-fpm服务 service php7.0-fpm restart

5.安装mysql5.7

sudo apt-get install mysql-server php7.0-mysql
sudo apt-get install mysql-client

安装一些依赖库

sudo apt-get install libxml2
sudo apt-get install openssl
sudo apt-get install curl
sudo apt-get install libjpeg
sudo apt-get install libpng
sudo apt-get install libfreetype6-dev
sudo apt-get isntall libxslt1-dev
sudo apt-get install 
sudo apt-get install autoconf //【注】 如果不安装的话,会出现PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
文 / Aex
LEAVE A REPLY
loading