PhpStorm远程开发设置

实验环境

服务器:Windows Server 2019(WAMP)
客户端:Windows 10 企业版

在服务器上安装SSH服务器

按 Win+I 打开“设置”,选择“应用”>“应用和功能”,然后选择“管理可选功能” 。

扫描列表,查看是否已安装 OpenSSH。 如果未安装,请在页面顶部选择“添加功能”,然后:

查找“OpenSSH 客户端”,再单击“安装”

查找“OpenSSH 服务器”,再单击“安装”

设置完成后,回到“应用”>“应用和功能”和“管理可选功能”,你应会看到已列出 OpenSSH 。

file

file

安装好后的效果如下:

file

启动并配置 OpenSSH 服务器

若要启动并配置 OpenSSH 服务器来开启使用,请以管理员身份打开 PowerShell,然后运行以下命令来启动 sshd service:

Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

添加防火墙规则,如果没开防火墙可以忽略:

if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {

    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."

    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

} else {

    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."

}

测试SSH连接

查看服务器IP地址:

file

在客户端上连接服务器:

ssh 用户名@IP地址

file

成功连接!

file

PhpStorm设置

打开 Settings -> Build, Execution, Deployment -> Deployment,点击“+”号,添加SFTP类型。

file

服务器名字可以自己起一个。

file

第一次连接需要先配置SSH连接。

file

file

点击“Test Connection”测试连接,显示成功连接。

file

SFTP设置:

Root path就是把文件上传到服务器上的哪个目录(可以设置成网站目录)

Web server URL就是查看网站所访问的地址

file

设置 Mappings:

file

PhpStorm远程开发

将服务器上的内容同步到本地。

file

file

以下是服务器上的内容,已经下载到本地。

file

新建一个文件,然后上传到服务器。

file

file

在服务器上查看一下,上传成功!

file