PHP-lnmp 環境搭建

Alden發表於2020-01-07

參考網站:http://www.liyblog.top/p/9
1.nginx和php基本安裝

1.更新apt

apt update

2.安裝nginx

apt install nginx

3.檢視nginx狀態

systemctl status nginx

4.安裝php

apt install php php-fpm

apt-get install php7.2 php7.2-fpm

5.檢視php版本(ubuntu 預設安裝php7.2)

php -v

2.nginx配置php-fpm

1.檢視nginx具體位置,查詢nginx配置檔案位置(當前是在 /etc/nginx )

whereis nginx

2.進入站點配置目錄

cd /etc/nginx/sites-available

3.配置站點資訊

    server配置注意:

    1.listen 80; 設定監聽埠

    2.root /var/www/html 設定專案目錄

    3.index index.php 設定站點目錄入口檔案

    4.server_name www.liyblog.top 設定站點域名

    5.php配置見下圖程式碼

    6.fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; (配置socket,要配置相對應版本的php)

    7.刪除/etc/nginx/sites-enabled/default 檔案

    8.連結到站點目錄    ln -s /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/blog(這一步很重要必須執行)

server {

        listen 80;

        #listen [::]:80 default_server;

        # SSL configuration

        #

        # listen 443 ssl default_server;

        # listen [::]:443 ssl default_server;

        #

        # Note: You should disable gzip for SSL traffic.

        # See: <https://bugs.debian.org/773332>

        #

        # Read up on ssl_ciphers to ensure a secure configuration.

        # See: <https://bugs.debian.org/765782>

        #

        # Self signed certs generated by the ssl-cert package

        # Don't use them in a production server!

        #

        # include snippets/snakeoil.conf;

        root /var/[www/html](http://www/html);

        # Add index.php to the list if you are using PHP

        index index.php index.html index.htm index.nginx-debian.html;

        server_name [www.default.](http://www.liyblog.top/)com;

        location / {

                # First attempt to serve request as file, then

                # as directory, then fall back to displaying a 404.

                try_files $uri $uri/ =404;

        }

        # pass PHP scripts to FastCGI server

        #

        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;

        }

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #      deny all;

        #}

}

3.安裝配置mysql

1.安裝mysql

apt install mysql-server 

2.檢視mysql

netstat -tap | grep mysql

3.設定mysql初始密碼

mysql_secure_installation

4.安裝配置phpmyadmin

1.安裝phpmyadmin

apt install phpmyadmin

** 注意:Web 自動選擇: apache ,lightd 一個都不選!

2.nginx配置phpmyadmin

1)、為了統一,將 phpmyadmin ln 到 /var/www

     sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

2)、直接 cp default 過來修改

    cd /etc/nginx/sites-available/

    sudo cp default phpmyadmin

3)sudo vim /etc/nginx/site-available/phpmyadmin

    修改這個 phpmyadmin 以下 2 處

    listen 999;(此處需要在阿里雲平臺放行999埠)

     root /var/www/phpmyadmin;

4)、連線到 sites-enabled

    sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin

5)測試、重啟 nginx 服務

    sudo nginx -t

    必須測試正確!

    sudo systemctl restart nginx

3.訪問phpmyadmin(需要加上index.php)

http://IP地址:999/index.php

phpmyadmin賬戶

預設使用者名稱:phpmyadmin 

密碼:自己設定的密碼

本作品採用《CC 協議》,轉載必須註明作者和本文連結