搜索
首页后端开发php教程手把手教你WSL怎么设置php开发环境

WSL设置php开发环境

相比于 docker 的繁琐,wsl 或许是在 windows 10 系统上开发php的好选择。目前免费的环境是 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

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。