在Debian系統上配置PhpStorm可以提升開發效率。以下是一些實用的配置技巧:
安裝PHP及其擴展:
sudo apt update
sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
配置PHP-FPM(可選):
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
配置Web服務器(如Nginx或Apache):
Nginx:
sudo apt install nginx
sudo nano /etc/nginx/sites-available/default
在配置文件中添加以下內容:
server {
listen 80;
server_name your_domain_or_ip;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php{version}-fpm.sock;
}
}
重啟Nginx:
sudo systemctl restart nginx
Apache:
sudo apt install apache2
sudo nano /etc/apache2/sites-available/000-default.conf
在配置文件中添加以下內容:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
Directory /var/www/html
Options Indexes FollowSymLinks AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php{version}-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
重啟Apache:
sudo systemctl restart apache2
在PhpStorm中配置PHP解釋器:
File
- Settings
。Languages & Frameworks
- PHP
。Add
按鈕,然后瀏覽并選擇你的PHP解釋器的路徑。OK
保存設置。配置Xdebug:
在PhpStorm中,進入File
- Settings
- Languages & Frameworks
- PHP
- Debug
。
配置調試端口(例如9000)。
在PHP配置文件(如/etc/php/{version}/fpm/php.ini
)中配置Xdebug:
zend_extension="xdebug.so"
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9000
重啟PHP-FPM或Web服務器。
配置運行/調試配置:
Run
- Edit Configurations
。PHP Web Page
或PHP Script
。安裝中文語言包:
File
- Settings
- Plugins
。Chinese
語言包。配置版本控制:
VCS
- Git
- Remotes
,配置你的Git倉庫地址。VCS
- Git
- Commit Directory
進行代碼提交。配置SFTP自動上傳(可選):
Settings
- Tools
- Deployment
- Configuration
中,添加SFTP服務器配置。Automatic Upload
,修改代碼即可自動上傳部署。使用Docker:
Settings
- Build, Execution, Deployment
- Docker
中配置Docker連接,方便進行容器化開發。安裝插件:
Settings
- Plugins
中安裝其他有用的插件,如代碼質量工具、版本控制工具等。通過以上步驟,你可以在Debian系統上配置一個功能齊全的PhpStorm開發環境。如果有商業用途,請購買正版軟件以獲得更好的技術支持和安全保障。