PhpStorm本身无需直接配置SSL证书,因为它是本地开发的IDE,主要功能是编写和调试代码。SSL证书的配置通常针对运行PHP的Web服务器(如Apache、Nginx),以确保网站通过HTTPS提供服务。以下是在Ubuntu上为Web服务器配置SSL证书的详细步骤(以Let’s Encrypt免费证书为例):
sudo apt update && sudo apt upgrade -y sudo apt install certbot python3-certbot-apache -y sudo apt install certbot python3-certbot-nginx -y Certbot可自动修改Web服务器配置文件(Apache/Nginx),无需手动编辑。
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com 执行后会提示选择SSL配置选项(如强制HTTPS重定向),按需选择即可。若需自定义配置,可手动获取证书并指定路径:
sudo certbot certonly --manual -d yourdomain.com -d www.yourdomain.com 证书文件会保存至/etc/letsencrypt/live/yourdomain.com/目录,包含:
fullchain.pem(证书链,需配置给Web服务器)privkey.pem(私钥,需严格保密)Certbot自动修改Apache配置文件(位于/etc/apache2/sites-available/),需确保以下指令存在:
<VirtualHost *:443> ServerName yourdomain.com DocumentRoot /var/www/html SSLEngine on SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem # 可选:强制HTTP重定向至HTTPS RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] </VirtualHost> 保存后测试配置语法并重启Apache:
sudo apache2ctl configtest && sudo systemctl restart apache2 Certbot自动修改Nginx配置文件(位于/etc/nginx/sites-available/),需确保以下指令存在:
server { listen 443 ssl; server_name yourdomain.com www.yourdomain.com; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # 可选:强制HTTP重定向至HTTPS if ($scheme != "https") { return 301 https://$host$request_uri; } root /var/www/html; index index.php index.html; } 保存后测试配置语法并重启Nginx:
sudo nginx -t && sudo systemctl restart nginx https://yourdomain.com,确认地址栏显示锁形图标(无安全警告)。sudo openssl s_client -connect yourdomain.com:443 -servername yourdomain.com | openssl x509 -noout -dates 输出应显示证书有效期(如notBefore和notAfter)。Let’s Encrypt证书有效期为90天,Certbot会自动创建定时任务(certbot.timer)续期。可手动测试续期流程:
sudo certbot renew --dry-run 若输出显示“Congratulations, all renewals succeeded”,则续期正常。
若需在PhpStorm中调试HTTPS请求(如使用Guzzle、cURL),需确保PHP的openssl扩展已启用:
/etc/php/8.1/apache2/php.ini):extension=openssl sudo systemctl restart apache2 # 或nginx 通过以上步骤,Ubuntu上的Web服务器将成功配置SSL证书,PhpStorm可通过HTTPS与服务器通信。若需进一步优化SSL性能(如启用OCSP Stapling),可参考Web服务器官方文档调整配置。