ubuntu16.04如何搭建lnmp环境 傻瓜教程

2017-02-20  本文已影响0人  拉风的老衲

本文重点介绍在Ubuntu中使用apt-get安装LAMP(Ubuntu 16.04,Apache2.4.18,mysql5.7.12,php7.0.4)环境,所以不再介绍如何安装Ubuntu。(比较怕麻烦就直接用root用户进行操作了=.=)
1 准备工作

root@iZbp1gz7uqi3jr524cj29bZ:/# apt-get update

这个命令,会访问源列表里的每个网址,并读取软件列表,然后保存在本地电脑。我们在新立得软件包管理器里看到的软件列表,都是通过update命令更新的

root@iZbp1gz7uqi3jr524cj29bZ:/# apt-get upgrade

这个命令,会把本地已安装的软件,与刚下载的软件列表里对应软件进行对比,如果发现已安装的软件版本太低,就会提示你更新。如果你的软件都是最新版本,会提示:
2 安装nginx

root@iZbp1gz7uqi3jr524cj29bZ:/# apt-get install nginx  

2.1 查看nginx

root@iZbp1gz7uqi3jr524cj29bZ:/# nginx -v  
nginx version: nginx/1.10.0 (Ubuntu)

3安装PHP

root@iZbp1gz7uqi3jr524cj29bZ:/# apt-get install php7.0

用于php与nginx交互

root@iZbp1gz7uqi3jr524cj29bZ:/# apt-get install php7.0-fpm

查看是否安装成功


Paste_Image.png

4安装mysql

root@iZbp1gz7uqi3jr524cj29bZ:/# apt-get install mysql-server

到现在为止我们已经把基本软件安装完成了 但是别急啊 还有些简单的设置
首先我们找到/etc/nginx/sites-available下的default 文件

root@iZbp1gz7uqi3jr524cj29bZ:/# vim /etc/nginx/sites-available/default

找到

    #location ~ \.php$ {      
    #       #include snippets/fastcgi-php.conf;      
    #      
    #       #With php5-cgi alone:        
    #       fastcgi_pass 127.0.0.1:9000;              
    #       # With php5-fpm:
    #       fastcgi_pass unix:/var/run/php5-fpm.sock;        
    # }

改成

    location ~ \.php$ {      
           #include snippets/fastcgi-php.conf;      
          
           #With php5-cgi alone:        
           fastcgi_pass 127.0.0.1:9000;              
           # With php5-fpm:
           fastcgi_pass unix:/var/run/php5-fpm.sock;        
     }

添加index.php到配置文件

       root /var/www/html;
    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

重启后,访问即可

上一篇下一篇

猜你喜欢

热点阅读