Ubuntu17.04 搭建LNMP環境

1、登陸和更新php

#以管理身份登陸
    su
    #k系統更新
    apt-get update
    apt-get upgrade
複製代碼

2、安裝nginxhtml

sudo apt install nginx
    systemctl enable nginx
複製代碼

3、安裝MySQLmysql

sudo apt install mysql-server
    systemctl enable mysql
複製代碼

4、安裝PHPnginx

sudo apt install php
    sudo apt install php-fpm
複製代碼

5、配置Nginx支持PHPsql

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;
            }
    }
複製代碼

6、測試篇數據庫

#注意新版本Mysql 中操做命令 "mysql"改成"mysqli"vim

#新建網站首頁
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();
    ?>
複製代碼
相關文章
相關標籤/搜索