以下是使用PhpStorm远程连接CentOS服务器的步骤:
配置服务器SSH服务
sudo yum install openssh-server
。sudo systemctl start sshd
,sudo systemctl enable sshd
。sudo firewall-cmd --permanent --add-service=ssh
,sudo firewall-cmd --reload
。生成并配置SSH密钥(可选,推荐)
ssh-keygen -t rsa -b 4096
,按提示保存私钥和公钥。ssh-copy-id username@server_ip
,输入密码后完成配置。在PhpStorm中配置远程连接
File > Settings > Tools > SSH Configurations
,点击“+”选择“SFTP”,填写服务器IP、端口(默认22)、用户名,选择私钥文件认证。
Deployment > Configuration
,添加服务器,设置本地项目路径与服务器目标路径的映射关系。远程开发与调试(可选)
Languages & Frameworks > PHP > CLI Interpreter
,添加远程解释器,选择SSH连接,指定服务器PHP路径(如/usr/bin/php
)。sudo yum install php-xdebug
,编辑php.ini
配置xdebug.remote_host
(本地IP)、xdebug.remote_port
(如9003)。Run > Edit Configurations
,选择“PHP Web Page”,设置服务器、端口及Xdebug参数,启动监听后即可断点调试。注意事项:
~/.ssh/authorized_keys
。参考来源: