系統更新
sudo apt update
sudo apt upgrade

安裝 nginx 
sudo apt install nginx

啟動 nignx 檢查是否有錯誤
sudo systemctl start nginx 

安裝 php 及相關 extention
sudo apt install php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

正常狀況下,安裝完後會自動啟動
以下指令檢查是否正常啟動
systemctl status php7.4-fpm.service
ps aux | grep php

修改nginx 設定檔用來支援 php 
sudo vi /etc/nginx/sites-available/default

找到 server 區段
新增 index.php 為index 頁
        index index.php index.html index.htm index.nginx-debian.html;
如果副檔名為 php 則透過 fastcgi 執行
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }

重新啟動 nginx 
sudo systemctl restart nginx 

建立一個測試檔案
cd /var/www/html/
vi test.php

<?php
    echo "Hello World";
?>

最後打開瀏覽器,網址列輸入 http://ip/test.php
如果畫面顯示 Hello World ,表示安裝設定成功

arrow
arrow
    創作者介紹
    創作者 helloworld 的頭像
    helloworld

    Hello World

    helloworld 發表在 痞客邦 留言(0) 人氣()