lnmp 安装笔记

1 篇文章 0 订阅
1 篇文章 0 订阅


lnmp 安装笔记

Introduction

The LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications. This is an acronym that describes a Linux operating system, with an Nginx web server. The backend data is stored in the MySQL database and the dynamic processing is handled by PHP.

In this guide, we will demonstrate how to install a LEMP stack on an Ubuntu 16.04 server. The Ubuntu operating system takes care of the first requirement. We will describe how to get the rest of the components up and running.

Step 1: Install the Nginx Web Server
sudo apt-get update
sudo apt-get install nginx
Step 2: Install MySQL to Manage Site Data
sudo apt-get install mysql-server
Step 3: Install PHP for Processing
sudo apt-get install php-fpm php-mysql
Configure the PHP Processor
sudo vi /etc/php/7.0/fpm/php.ini
## 找到这个参数,并且把它改成0
cgi.fix_pathinfo=0
sudo vi /etc/php/7.0/fpm/pool.d/www.conf
## 将这个注释去掉, 注意这里是/run/php/php7.0-fpm.sock,这个路径不要写错了,请到文件系统里面去检查有没有这个文件,如果没有,请到/var/php/php7.0-fpm.sock找找看,这两个理论上没啥区别(只是前面这个路劲,就需要设置listen的权限,后面路径是不需要设置权限的)
listen = /run/php/php7.0-fpm.sock

## 去掉这两行注释
listen.owner = www-data
listen.group = www-data
## 将listen mode 由0660改成666,不然会没有权限访问,并且去掉注释
listen.mode = 0666
Step 4: Configure Nginx to Use the PHP Processor

可以说是这一步最贱,所有的文档都是让你到/etc/nginx/site-available/default里面去配置,但是如果这样去做,可能会因为nginx的版本问题,导致你永远都不可能配置成功你的nginx和php的集成环境;

首先检查你的/etc/nginx/nginx.config文件,是不是有一行类似下面的语句

## 如果没有这一行,你看看你的config文件是include的什么,那么你就要到相应的地方去配置你的站点,
include /etc/nginx/site-available/*
## 我的电脑里面是这样的, 所以我的配置文件是写在/etc/nginx/conf.d/default.config
include /etc/nginx/conf.d/*.config

配置文件内容如下即可

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
Step5: restart php7.0-fpm, restart nginx
sudo service nginx reload
sudo service php7.0-fpm reload
在root(root /var/www/html)下面写一个info.php
<?php phpinfo()?>

然后查看localhost/info.php,就可以看到你的php 和 nginx是否有集成成功!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值