清理Vscode的缓存
C:\Users\Administrator\AppData\Roaming\Code
删除 Cache 和 CachedData
应用的扩展
Remote SSH 远程开发
phpcs - php psr12规范
PHP DocBlocker - phpDoc注释
PHP Debug - php xdebug 调试
PHP Intelephense - php语法检查
PHP Namespace Resolver - php命名空间引用
vscode 全局 setting 配置
{
"php.validate.executablePath": "/usr/bin/php",
"workbench.colorTheme": "Default Light+",
"editor.fontSize": 17,
"intelephense.environment.includePaths": [
"/home/wwwroot/xmvc/composer/vendor",
],
"php.debug.ideKey" : "vsc",
"php.debug.executablePath": "/usr/bin/php",
"workbench.tree.indent": 24,
"editor.formatOnPaste": true,
"workbench.startupEditor": "none",
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"intelephense.telemetry.enabled": false,
"phpcs.enable": true,
"phpcs.executablePath": "/home/qg/.config/composer/vendor/bin/phpcs",
"phpcs.standard": "PSR12",
"phpcs.ignorePatterns": [
"*/vendor/*",
"*/cache/*",
"*/view/*",
"*/xview/*"
]
}
[Remote SSH]
安装 vscode 的 Remote SSH 扩展
Ctrl+Shift+P 打开命令面板输入 Remote-SSH: Connect to Host...,
然后选择 Configure SSH Hosts...。在配置文件中添加SSH 主机的信息
配置文件一般在 C:\Users\Administrator\.ssh 目录下
Host VM.debian12
HostName vm.debian12
User root
Port 22
#PreferredAuthentications password
IdentityFile C:\Users\Administrator\.ssh\id_rsa
#HostName
#vm.debian12 在 hosts 指向了 debian虚拟机的IP 192.168.1.90
#PreferredAuthentications password 使用密码认证,每次打开vscode需要输入一次
#IdentityFile your_path_file 使用密钥进行身份验证
在 windows 电脑上生成 SSH 密钥
> ssh-keygen -t rsa -b 4096 -C "admin.yipxxxx.com"
> Enter++
C:\Users\Administrator\.ssh 目录下会生成 id_rsa(私钥) 和 id_rsa.pub(公钥) 两个文件
在 debian 电脑上添加公钥
> mkdir ~/.ssh
> touch ~/.ssh/authorized_keys
> chmod 700 ~/.ssh
> chmod 600 ~/.ssh/authorized_keys
将 windows下生成的 SSH 公钥文件 id_rsa.pub 中的内容复制到 ~/.ssh/authorized_keys 文件中
[composer]
将 composer.phar 改名为 composer 放入 /usr/local/bin 全局可执行目录下, 并使用普通用户来操作 composer
查看全局安装路径
composer global config home
添加 comoser bin 到环境目录
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
source ~/.bashrc #使用path生效
[phpcs]
全局安装
composer global require "squizlabs/php_codesniffer=*"
phpcs --version
phpcs 在 .vscode 的当前工作目录的 setting.josn 中加入配置
"phpcs.enable": true,
"phpcs.executablePath": "/home/qg/.config/composer/vendor/bin/phpcs",
"phpcs.standard": "PSR12",
"phpcs.ignorePatterns": [
"*/vendor/*",
"*/cache/*",
"*/view/*",
"*/xview/*"
]
忽略 psr12规范开始
// @codingStandardsIgnoreStart
结束忽略
// @codingStandardsIgnoreEnd
修改psr12规则
一行最大120个字符,设置为最大 1200
<!-- There MUST NOT be a hard limit on line length.
The soft limit on line length MUST be 120 characters.
Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD be split into multiple subsequent lines of no more than 80 characters each. -->
<rule ref="Generic.Files.LineLength">
<properties>
<!--<property name="lineLimit" value="120"/>-->
<property name="lineLimit" value="1200"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
[PHP Debug]
php.ini 中配置
[xdebug]
xdebug.remote_enable = on
xdebug.start_with_request = 1
xdebug.mode=trace
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=vsc
; 临时开启调试日志,一般刚安装时用, xdebug 正常用,注释掉它
xdebug.log=/home/wwwroot/debian_logs/xdebug.log
; 日志级别 3 为最高
;xdebug.remote_log_level=3
// 手动添加断点
<?php
$t = time();
xdebug_break();
echo $t;
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for PHP Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
//"log": true,
"externalConsole": false,
"pathMappings": {
"/home/wwwroot/xmvc": "${workspaceFolder}"
},
"xdebugSettings": {
"max_data": 65535,
"show_hidden": 1,
"max_children": 100,
"max_depth": 5
}
}
]
}
查看端口占用
> sudo lsof -i :9003
或 > sudo netstat -tuln | grep 9003
增大xdebug调试时间
增至 10 分钟, 注:开发环境才用,正式环境下不要如此
php.ini
max_execution_time = 600
nginx.conf
http {
# 增加代理超时时间
proxy_read_timeout 600s;
}
*/sites-available/vhost.xxx.xxx.conf 虚拟主机配置 fastcgi_read_timeout
server {
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# 禁用 OPcache
fastcgi_param PHP_ADMIN_VALUE "opcache.enable=0";
# 增加 FastCGI 超时时间
fastcgi_read_timeout 600s;
}
}