96SEO 2025-10-27 19:09 0
在配置PHP的SSL证书之前,确保你的CentOS服务器已经安装了Apache和PHP。
安装Apache:
bash
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd

安装PHP:
bash
sudo yum install php php-mysqlnd
sudo systemctl restart httpd
为了配置SSL证书,你需要一个有效的SSL证书。你可以从Let’s Encrypt免费获取一个证书,或者购买一个商业证书。
安装Certbot:
bash
sudo yum install certbot python2-certbot-apache
运行Certbot:
bash
sudo certbot --apache
Certbot会自动检测你的Apache配置,并添加必要的SSL配置。
一旦你有了SSL证书,你需要配置Apache以使用它。
编辑Apache配置文件:
bash
sudo nano /etc/httpd/conf/httpd.conf
找到以下行并取消注释:
apache
LoadModule ssl_module modules/mod_ssl.so
找到以下行并修改为你的SSL证书和密钥文件的位置:
apache
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
保存并关闭文件。
PHP也需要配置以使用SSL。
编辑PHP配置文件:
bash
sudo nano /etc/php.ini
找到以下行并取消注释:
apache
;extension=openssl
找到以下行并修改为你的SSL证书和密钥文件的位置:
apache
;openssl.cafile = /etc/ssl/certs/ca-bundle.crt
openssl.cafile = /etc/letsencrypt/live/yourdomain.com/fullchain.pem
openssl.certificate_file = /etc/letsencrypt/live/yourdomain.com/privkey.pem
完成上述步骤后你需要重启Apache和PHP-FPM以应用更改:
bash
sudo systemctl restart httpd
sudo systemctl restart php-fpm
要验证SSL配置是否正确,你可以访问你的网站并检查SSL连接是否成功建立。如果你看到HTTPS连接和锁图标,那么你的SSL配置已经成功。
通过以上步骤,你应该能够在CentOS上成功配置PHP的SSL证书。如果你遇到任何问题,请检查Apache和PHP的日志文件以获取更多信息。
Demand feedback