在Ubuntu上为PHP启用SSL,您需要执行以下步骤:
sudo apt update
sudo apt install certbot python3-certbot-apache
这将安装Certbot以及与Apache Web服务器相关的插件。
sudo certbot --apache -d example.com -d www.example.com
Certbot将自动配置Apache以使用SSL,并将证书文件存储在/etc/letsencrypt/live/example.com
目录中。
sudo systemctl restart apache2
.htaccess
文件中添加以下代码来实现:RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这将确保所有HTTP请求都被重定向到HTTPS。
完成以上步骤后,您应该已经成功地在Ubuntu上为PHP启用了SSL。