在Ubuntu上为PHP启用SSL,您需要执行以下步骤:
sudo apt update
sudo apt install certbot
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
将yourdomain.com
替换为您的实际域名。Certbot将自动配置Nginx以使用SSL,并将证书文件存储在/etc/letsencrypt/live/yourdomain.com/
目录中。
如果您使用的是Apache而不是Nginx,请运行以下命令:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Certbot将自动配置Apache以使用SSL,并将证书文件存储在/etc/letsencrypt/live/yourdomain.com/
目录中。
/etc/php/7.4/cli/php.ini
或/etc/php/7.4/fpm/php.ini
),将以下行添加到文件末尾:openssl.cafile=/etc/letsencrypt/live/yourdomain.com/fullchain.pem
将yourdomain.com
替换为您的实际域名。这将告诉PHP使用Let’s Encrypt证书颁发机构文件来验证SSL连接。
sudo systemctl restart nginx
对于Apache,请运行以下命令:
sudo systemctl restart apache2
现在,您的Ubuntu服务器上的PHP应用程序应该已经启用了SSL。您可以通过访问https://yourdomain.com
来验证这一点。如果一切正常,您将看到一个绿色的锁图标,表示您的网站已成功使用SSL加密。