Ubuntu17.04 搭建LNMP环境

本文详细介绍如何在Linux系统上搭建LAMP(Linux, Apache, MySQL, PHP)环境,包括登录及系统更新、安装Nginx、MySQL、PHP及其配置,以及测试数据库连接和PHP信息显示。

一、登录和更新

#以管理身份登录
    su
    #k系统更新
    apt-get update
    apt-get upgrade
复制代码

二、安装nginx

sudo apt install nginx
    systemctl enable nginx
复制代码

三、安装MySQL

sudo apt install mysql-server
    systemctl enable mysql
复制代码

四、安装PHP

sudo apt install php
    sudo apt install php-fpm
复制代码

五、配置Nginx支持PHP

server {
            listen 80 default_server;
            listen [::]:80 default_server;
    
            root /home/html;
    
            index index.php index.html index.htm index.nginx-debian.html;
    
            server_name localhost;
    
            location / {
                    try_files $uri $uri/ =404;
            }
    
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
            #       # With php-fpm (or other unix sockets):
                    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            #       # With php-cgi (or other tcp sockets):
            #       fastcgi_pass 127.0.0.1:9000;
            }
    
            location ~ /\.ht {
                    deny all;
            }
    }
复制代码

六、测试篇

#注意新版本Mysql 中操作命令 "mysql"改为"mysqli"

#新建网站首页
cd /home/html;
vim index.php;
复制代码
<?php
    echo "测试数据库连接";
    $con = mysqli_connect("localhost","root","NewPass1!");
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }else{
            echo "conneted";
    }
    #打印php信息
    phpinfo();
    ?>
复制代码

转载于:https://juejin.im/post/5c2742b45188255e9b621d37

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值