Win10子系統ubuntu(wsl)中配置nginx和 php7.4(php-fpm) 的介紹


Win10子系統ubuntu(wsl)中配置nginx和 php7.4(php-fpm) 的介紹

鏈接

  1. 使用sudo apt install nginx安裝nginx 沒有問題

  2. 使用sudo apt-fast install php7.4 和php7.4-fpm關於安裝的詳細步驟,在另一篇文章中詳細介紹,這里不再贅述。鏈接

  3. 安裝完php-fpm后的配置文件所在路徑 /etc/php/7.4/fpm/php-fpm.conf /etc/php/7.4/fpm/pool.d/www.conf

  4. 運行sudo /usr/sbin/php-fpm.7.4 報錯如下:

    unable to bind listening socket for address '/run/php/php7.4-fpm.sock'

    判斷由於php-fpm配置的賬戶權限不夠無法創建該文件 臨時解決辦法替php-fpm創建:

    # sudo mkdir -p /run/php/
    # sudo touch /run/php/php-fpm.sock
  5. 在nginx中配置php-fpm:

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    root /mnt/d/web/php/; #本機掛載盤路徑地址
    
    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;
    
    server_name _;
    
       location / {
           if (!-e $request_filename) {
               rewrite ^(.*)$ /index.php?s=$1 last;
               break;
           }
       }
    
       location ~ \.php$ {
    
           fastcgi_pass unix:/run/php/php7.4-fpm.sock;  #此處需要替換成 fpm.sock所在路徑
    
           fastcgi_index index.php;
    
           fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
           include fastcgi_params;
    
       }
    
    }

    此處需要注意的是,以往在linux上 fastcgi_pass 會配置成127.0.0.1:9000,而此處需要與php-fpm中配置的listen 一致不是url+port 而是sock地址

原文鏈接


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM