lnmp 安装笔记

来源:互联网 发布:超链接调用js 编辑:程序博客网 时间:2024/04/30 20:47


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 updatesudo 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## 找到这个参数,并且把它改成0cgi.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-datalisten.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.configinclude /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 reloadsudo service php7.0-fpm reload
在root(root /var/www/html)下面写一个info.php
<?php phpinfo()?>

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

1 0
原创粉丝点击