搜尋
首頁後端開發php教程手把手教你WSL怎麼設定php開發環境

#相較於 docker 的繁瑣,wsl 或許是在 windows 1

## 相比於 docker 的繁瑣,wsl 或許是在 windows 10 系統上開發的好選擇。目前免費的環境是 ubuntu20,centos 試過好像不太好用,就此記錄一下。

購買ubuntu

因為是免費的,所以只要進入微軟商店找到,下載安裝即可,比較簡單。

安裝開發環境

開啟powershell
ubuntu2004.exe config –default-user root

查看版本指令
cat /etc/issue
應該顯示
Ubuntu 20.04.xxxxx

進入系統,必須先apt update ,否則什麼軟體都不太好。

apt install nginx(nginx官网推荐的方法放最后)/etc/init.d/nginx  start

apt install redis

apt install php7.4-fpm

假設需要安裝php其他插件

apt install php7.4-memcache
apt install php7.4-mbstring
apt install php7.4-gd
apt install php7.4-dom
apt install php7.4-mysql
apt install php7.4-redis

要注意,這裡,只要新安裝了php的插件,就需要重新啟動php7.4-fpm的服務。

/etc/init.d/php7.4-fpm start


apt install mysql-server
apt install mysql-client/etc/init.d/mysql start/etc/init.d/redis-server start


curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar
chmod +x /usr/local/bin/composer

需要在設定檔加 ~/.bashrc
export COMPOSER_ALLOW_SUPERUSER=1

然後命令列
composer -V
可以測試 composer 是否安裝成功。

apt install net-tools
apt install unzip

netstat -antup

如何修改MySQL監聽IP位址

Mysql預設在本機迴路位址127.0.0.1的3306埠監聽,要使用其它IP地址需要修改設定檔。

1.編輯/etc/my.cnf

在[mysqld]節中增加下面一行:

bind-address=0.0.0.0  #全部位址或指定的ip位址

2.重啟服務

service mysqld restart

3、然後必須修改mysql的密碼,否則客戶端無法登入。
先在指令列

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

雜項和 nginx 設定

ssh-keygen -t rsa -b 4096
然後修改成自己的,注意檔案權限。

拉程式碼到本機。

composer config –global github-oauth.github.com ghp_xxxxxxxxxxxx

mount -t drvfs F: /mnt/myshare

再次修改nginx
vim /etc/ nginx/sites-enabled/default
或也可以刪除這個default 檔案
把所有的虛擬主機都放conf.d 或許更習慣。

   charset  utf-8;

      location / {
        try_files $uri $uri/ /index.php?$query_string;
      }

      location ~ \.php$ {
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  #      fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include snippets/fastcgi-php.conf;
        #include fastcgi_params;
      }

終於,看見 laravel 的介面了。

上傳檔案的大小限制

這是nginx 設定在 http 項目內。
client_max_body_size 10m;

php.ini 需要設定
post_max_size=10m
upload_max_filesize=10m

nginx 官網推薦的方式

echo $'deb https://nginx.org/packages/ubuntu/ focal nginx
deb-src https://nginx.org/packages/ubuntu/ focal nginx ' > /etc/apt/sources.list.d/nginx.list
apt update
apt install nginx

推薦學習:《PHP影片教學

以上是手把手教你WSL怎麼設定php開發環境的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:learnku。如有侵權,請聯絡admin@php.cn刪除
高流量網站的PHP性能調整高流量網站的PHP性能調整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依賴注入:初學者的代碼示例PHP中的依賴注入:初學者的代碼示例May 14, 2025 am 12:08 AM

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

PHP性能:是否可以優化應用程序?PHP性能:是否可以優化應用程序?May 14, 2025 am 12:04 AM

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

PHP性能優化:最終指南PHP性能優化:最終指南May 14, 2025 am 12:02 AM

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

PHP依賴注入容器:快速啟動PHP依賴注入容器:快速啟動May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依賴注入與服務定位器PHP中的依賴注入與服務定位器May 13, 2025 am 12:10 AM

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

PHP性能優化策略。PHP性能優化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP電子郵件驗證:確保正確發送電子郵件PHP電子郵件驗證:確保正確發送電子郵件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。