笔记 : Ubuntu部署LNMP环境

Posted 骑着小毛驴过冬的八阿哥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了笔记 : Ubuntu部署LNMP环境相关的知识,希望对你有一定的参考价值。

一、准备与安装

  1. 安装php7.1

  #添加php源
  :~$ sudo add-apt-repository ppa:ondrej/php
  #更新apt数据,载入php源数据
  :~$ sudo apt update
  :~$ #安装php-fpm
  :~$ sudo apt install php7.1-fpm
  :~$ sudo apt install php7.1

  2. 安装nginx

  :~$ sudo apt-get install nginx

  3. 为laravel 5.5安装php扩展

  :~$ sudo apt install php7.1-mysql  mcrypt  php7.1-mcrypt  php7.1-mbstring  php7.1-xml  openssl

 

二、修改PHP配置文件  

  1. 找到 cgi.fix_pathinfo 修改为 0 ,如下:cgi.fix_pathinfo=0

  :~$ sudo vim /etc/php/7.1/fpm/php.ini

三、修改Nginx配置文件

  :~$ sudo vi /etc/nginx/sites-enabled/default

  1. # Default server configuration : 默认配置,根目录为nginx下的root /var/www/html;
  2. 默认访问没有php格式文件, 39行添加index.php
  3. #
Virtual Host configuration for example.com : 通过虚拟机访问的自定义目录 root /home/share/www;自定义端口为8000
 1 ##
 2 # You should look at the following URL‘s in order to grasp a solid understanding
 3 # of Nginx configuration files in order to fully unleash the power of Nginx.
 4 # http://wiki.nginx.org/Pitfalls
 5 # http://wiki.nginx.org/QuickStart
 6 # http://wiki.nginx.org/Configuration
 7 #
 8 # Generally, you will want to move this file somewhere, and start with a clean
 9 # file but keep this around for reference. Or just disable in sites-enabled.
10 #
11 # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
12 ##
13 
14 # Default server configuration
15 #
16 server {
17     listen 80 default_server;
18     listen [::]:80 default_server;
19 
20     # SSL configuration
21     #
22     # listen 443 ssl default_server;
23     # listen [::]:443 ssl default_server;
24     #
25     # Note: You should disable gzip for SSL traffic.
26     # See: https://bugs.debian.org/773332
27     #
28     # Read up on ssl_ciphers to ensure a secure configuration.
29     # See: https://bugs.debian.org/765782
30     #
31     # Self signed certs generated by the ssl-cert package
32     # Don‘t use them in a production server!
33     #
34     # include snippets/snakeoil.conf;
35 
36     root /var/www/html;
37 
38     # Add index.php to the list if you are using PHP
39     index index.html index.php index.htm index.nginx-debian.html;
40 
41     server_name _;
42 
43     location / {
44         # First attempt to serve request as file, then
45         # as directory, then fall back to displaying a 404.
46         try_files $uri $uri/ =404;
47     }
48 
49     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
50     #
51     #location ~ \.php$ {
52     #    include snippets/fastcgi-php.conf;
53     #
54     #    # With php7.0-cgi alone:
55     #    fastcgi_pass 127.0.0.1:9000;
56     #    # With php7.0-fpm:
57     #    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
58     #}
59 
60     # deny access to .htaccess files, if Apache‘s document root
61     # concurs with nginx‘s one
62     #
63     #location ~ /\.ht {
64     #    deny all;
65     #}
66 }
67 
68 
69 # Virtual Host configuration for example.com
70 #
71 # You can move that to a different file under sites-available/ and symlink that
72 # to sites-enabled/ to enable it.
73 #
74 #server {
75 #    listen 8000;
76 #    listen [::]:8000;
77 #
78 #    server_name example.com;
79 #
80 #    root /home/share/www;
81 #    index index.html index.php;
82 #
83 #    location / {
84 #        try_files $uri $uri/ =404;
85 #    }
86 #}

 

  









以上是关于笔记 : Ubuntu部署LNMP环境的主要内容,如果未能解决你的问题,请参考以下文章

Linux学习笔记之搭建LNMP服务器环境

干货Ubuntu 下php7 mysql5.7 LNMP 环境搭建

如何彻底卸载安装在lnmp环境下的ssl证书?

如何在lnmp上部署Thinkphp

nginx+php-fpm独立节点的部署wordpress笔记

Python实现一键安装部署LNMP环境