如何一步步设置WSL中的PHP开发环境?

更新于
2026-09-30 11:08:24
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1018个文字,预计阅读时间需要5分钟。

如何一步步设置WSL中的PHP开发环境?

WSL配置PHP开发环境相比Docker的详细步骤,WSL(Windows Subsystem for Linux)可能是Windows 10系统上开发PHP的更好选择。目前免费的环境包括Ubuntu 20,虽然CentOS试用表现不佳,以下是一些建议:

1. 安装WSL: - 确保Windows 10版本为1809或更高。 - 打开Windows设置,搜索启用或关闭Windows功能。 - 在列表中找到并启用Windows Subsystem for Linux和Virtual Machine Platform。

2. 安装Ubuntu 20: - 在应用商店搜索Windows Subsystem for Linux。 - 选择Ubuntu并点击安装。

3. 设置Ubuntu: - 第一次启动时,会提示设置用户名和密码。

4. 安装PHP: - 打开终端,输入以下命令: sudo apt update sudo apt install php php-cli php-fpm

5. 配置PHP: - 编辑PHP配置文件,如`php.ini`,以启用所需扩展。 - 使用`sudo nano /etc/php/7.4/fpm/php.ini`(根据你的PHP版本可能有所不同)。

6. 启动PHP-FPM: - 输入以下命令启动PHP-FPM服务: sudo systemctl start php7.4-fpm

7. 测试PHP安装: - 创建一个名为`info.php`的文件,内容如下: - 将文件保存在你的Web服务器的根目录。 - 在浏览器中访问`http://localhost/info.php`,你应该能看到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 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.重启服务

如何一步步设置WSL中的PHP开发环境?

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 设置在 nginx.org/packages/ubuntu/ focal nginx deb-src nginx.org/packages/ubuntu/ focal nginx ' > /etc/apt/sources.list.d/nginx.list apt update apt install nginx

推荐学习:《PHP视频教程》

以上就是手把手教你WSL怎么设置php开发环境的详细内容,更多请关注自由互联其它相关文章!

本文共计1018个文字,预计阅读时间需要5分钟。

如何一步步设置WSL中的PHP开发环境?

WSL配置PHP开发环境相比Docker的详细步骤,WSL(Windows Subsystem for Linux)可能是Windows 10系统上开发PHP的更好选择。目前免费的环境包括Ubuntu 20,虽然CentOS试用表现不佳,以下是一些建议:

1. 安装WSL: - 确保Windows 10版本为1809或更高。 - 打开Windows设置,搜索启用或关闭Windows功能。 - 在列表中找到并启用Windows Subsystem for Linux和Virtual Machine Platform。

2. 安装Ubuntu 20: - 在应用商店搜索Windows Subsystem for Linux。 - 选择Ubuntu并点击安装。

3. 设置Ubuntu: - 第一次启动时,会提示设置用户名和密码。

4. 安装PHP: - 打开终端,输入以下命令: sudo apt update sudo apt install php php-cli php-fpm

5. 配置PHP: - 编辑PHP配置文件,如`php.ini`,以启用所需扩展。 - 使用`sudo nano /etc/php/7.4/fpm/php.ini`(根据你的PHP版本可能有所不同)。

6. 启动PHP-FPM: - 输入以下命令启动PHP-FPM服务: sudo systemctl start php7.4-fpm

7. 测试PHP安装: - 创建一个名为`info.php`的文件,内容如下: - 将文件保存在你的Web服务器的根目录。 - 在浏览器中访问`http://localhost/info.php`,你应该能看到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 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.重启服务

如何一步步设置WSL中的PHP开发环境?

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 设置在 nginx.org/packages/ubuntu/ focal nginx deb-src nginx.org/packages/ubuntu/ focal nginx ' > /etc/apt/sources.list.d/nginx.list apt update apt install nginx

推荐学习:《PHP视频教程》

以上就是手把手教你WSL怎么设置php开发环境的详细内容,更多请关注自由互联其它相关文章!