跳至主要內容

把windows主機變成 laravel web server

環境 : Windows 10 專業版 | Intel(R) Core(TM) i9–7900X CPU

第一步 : 下載nginx

第二步 : 安裝 nginx 且啟用

  • 打開cmd
  • cd 至nginx資料夾中 如下圖
  • 輸入 nginx 就可以啟動了

第三步 : 確認nginx 是否正常運作

  • 在cmd 中 輸入 nginx -t 若出現以下test is successful 則為正常運作

第四步 : 下載並安裝php

第五步 : 下載並安裝composer

  • 安裝時要選擇正確的php
  • 都安裝好了後若有使用mysql 記得設定php.ini
  • 以下為 php.ini 檔案內容,將pdo_mysql 從註解中打開

第六步 : 設定 nginx.conf

  • 開啟 nginx.conf 路徑通常在 你的nginx資料夾 /nginx-1.24.0/conf/nginx.conf
  • 以下為要修改的區塊
server {
    listen       80;
    server_name  localhost;

  //專案路徑要改成你的
  root C:\Users\專案路徑\public;
   index index.php;
    
  location / {
   try_files $uri $uri/ /index.php?$query_string;
  }
    
  location ~ \.php$ {
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   include        fastcgi_params;
  }
}

第七步 : 重新載入nginx

  • 使用cmd cd 到nginx 的資料夾中
  • 輸入以下指令
nginx -s reload
  • 在cmd 中 輸入 nginx -t 若出現以下test is successful 則為正常運作

接著在瀏覽器中輸入 http://127.0.0.1 就會顯示你的專案了 👏

以上為個人實作經驗,若有不一樣的情況發生,歡迎在底下留言討論。

分類:伺服器安裝

搶先發佈留言

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

由 Compete Themes 設計的 Author 佈景主題