在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。