从JetBrains官网下载最新版PhpStorm Linux安装包(.tar.gz
格式),解压至目标目录(如/opt/phpstorm
)。通过终端进入解压目录,运行./phpstorm.sh
启动PhpStorm。
sudo apt update
确保系统包为最新版本。sudo apt install php php-xdebug php-mysql php-zip php-gd
(根据项目需求选择扩展),安装完成后通过php -v
验证PHP版本。sudo apt install apache2
,启动服务并设置开机自启:sudo systemctl start apache2
、sudo systemctl enable apache2
。sudo a2enmod php7.x
(x
为PHP版本号,如php7.4
),重启Apache使模块生效:sudo systemctl restart apache2
。File > Settings > Languages & Frameworks > PHP
。Add
,浏览至PHP可执行文件(通常为/usr/bin/php
),点击OK
保存。Run > Edit Configurations
,点击+
选择PHP Built-in Web Server
。Name
(自定义,如“Local Server”)、Host
(localhost
)、Port
(默认8080
,可修改)、Document root
(项目绝对路径,如/home/username/myproject
)。Apply
→OK
保存,通过Run
菜单启动内置服务器。Tools > Deployment > Configuration
,点击+
选择SFTP
(或其他协议)。SFTP host
(localhost
)、Port
(22
)、Root path
(项目目录)、Username
/Password
(本地服务器登录信息)。Mappings
标签,设置Local path
(本地项目路径)、Deployment path on server
(服务器项目路径,如/var/www/html/myproject
),勾选Automatic Upload
(自动上传)。sudo apt install php-xdebug
。cli
和fpm
配置文件(如/etc/php/8.1/cli/php.ini
、/etc/php/8.1/fpm/php.ini
),添加以下内容:zend_extension=xdebug.so xdebug.mode=debug xdebug.client_host=127.0.0.1 xdebug.client_port=9003 xdebug.start_with_request=yes
保存后重启PHP和Web服务器:sudo systemctl restart php8.1-fpm
、sudo systemctl restart apache2
。File > Settings > Languages & Frameworks > PHP > Servers
,点击+
添加服务器,设置Name
(如“Local Server”)、Host
(localhost
)、Port
(80
或443
)、Debugger
(Xdebug
)。Run > Edit Configurations
,点击+
选择PHP Web Page
,设置URL
(如http://localhost
)、Debugger mode
(PHP Remote Debug
),选择刚添加的服务器。info.php
(内容为<?php phpinfo(); ?>
),通过浏览器访问http://localhost:8080/info.php
(内置服务器)或http://localhost/info.php
(外部服务器),确认PHP信息显示正常。info.php
,在phpinfo()
行设置断点,点击调试工具栏绿色虫子图标启动调试,当代码执行到断点时,调试器应暂停并显示变量信息。通过以上步骤,即可在Ubuntu上完成PhpStorm与本地服务器的配置,支持项目开发、调试及部署需求。