php 在本地 xampp/apache 服务器上设置 SSL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2643462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up SSL on a local xampp/apache server
提问by horgen
I'm trying to access a Active Directory from my local webserver. To do this I'm using the latest version of xampp and a PHP script called adLDAP. If I understand things right, I need to enable SSL to access https URLs. I've tried to google it but with no luck :( Could anyone link a tutorial or explain to me how to install SSL on xampp/apache for windows 7 64bit? Any help would be appreciated :)
我正在尝试从本地网络服务器访问 Active Directory。为此,我使用了最新版本的 xampp 和一个名为adLDAP的 PHP 脚本。如果我理解正确,我需要启用 SSL 才能访问 https URL。我试过用谷歌搜索它,但没有运气:(任何人都可以链接教程或向我解释如何在 xampp/apache 上为 windows 7 64bit 安装 SSL?任何帮助将不胜感激:)
回答by VolkerK
Apache part - enabling you to open https://localhost/xyz
Apache 部分 - 使您能够打开https://localhost/xyz
There is the config file xampp/apache/conf/extra/httpd-ssl.conf which contains all the ssl specific configuration. It's fairly well documented, so have a read of the comments and take look at http://httpd.apache.org/docs/2.2/ssl/.
The files starts with <IfModule ssl_module>, so it only has an effect if the apache has been started with its mod_ssl module.
配置文件 xampp/apache/conf/extra/httpd-ssl.conf 包含所有 ssl 特定配置。它有很好的文档记录,因此请阅读评论并查看http://httpd.apache.org/docs/2.2/ssl/。文件以 开头<IfModule ssl_module>,所以只有当 apache 已经用它的 mod_ssl 模块启动时它才有效。
Open the file xampp/apache/conf/httpd.conf in an editor and search for the line
在编辑器中打开文件 xampp/apache/conf/httpd.conf 并搜索该行
#LoadModule ssl_module modules/mod_ssl.so
remove the hashmark, save the file and re-start the apache. The webserver should now start with xampp's basic/default ssl confguration; good enough for testing but you might want to read up a bit more about mod_ssl in the apache documentation.
删除哈希标记,保存文件并重新启动 apache。网络服务器现在应该从 xampp 的基本/默认 ssl 配置开始;足以进行测试,但您可能想在 apache 文档中阅读更多有关 mod_ssl 的信息。
PHP part - enabling adldap to use ldap over ssl
PHP 部分 - 使 adldap 能够通过 ssl使用ldap
adldap needs php's openssl extension to use "ldap over ssl" connections. The openssl extension ships as a dll with xampp. You must "tell" php to load this dll, e.g. by having an extension=nameofmodule.dllin your php.ini
Run
adldap 需要 php 的 openssl 扩展来使用“ldap over ssl”连接。openssl 扩展作为带有 xampp 的 dll 提供。你必须“告诉” php 加载这个 dll,例如extension=nameofmodule.dll在你的 php.ini 中
运行
echo 'ini: ', get_cfg_var('cfg_file_path');
It should show you which ini file your php installation uses (may differ between the php-apache-module and the php-cli version).
Open this file in an editor and search for
它应该显示您的 php 安装使用哪个 ini 文件(在 php-apache-module 和 php-cli 版本之间可能有所不同)。
在编辑器中打开此文件并搜索
;extension=php_openssl.dll
remove the semicolon, save the file and re-start the apache.
删除分号,保存文件并重新启动apache。
回答by Flak DiNenno
It turns out that OpenSSL is compiled and enabled in php 5.3 of XAMPP 1.7.2 and so no longer requires a separate extension dll.
事实证明,OpenSSL 是在 XAMPP 1.7.2 的 php 5.3 中编译和启用的,因此不再需要单独的扩展 dll。
However, you STILL need to enable it in your PHP.ini file the line extension=php_openssl.dll
但是,您仍然需要在 PHP.ini 文件中启用它 extension=php_openssl.dll
回答by dc-aoxn
I did most of the suggested stuff here, still didnt work. Tried this and it worked: Open your XAMPP Control Panel, locate the Configbutton for the Apache module. Click on the Config button and Select PHP (php.ini). Open with any text editor and remove the semi-column before php_openssl. Save and Restart Apache. That should do!
我在这里做了大部分建议的东西,仍然没有用。试过了,它奏效了:打开XAMPP 控制面板,找到Apache 模块的Config按钮。单击配置按钮并选择PHP (php.ini)。使用任何文本编辑器打开并删除php_openssl之前的半列。保存并重新启动 Apache。应该这样做!
回答by sAn
You can enable SSL on XAMPP by creating self signed certificates and then installing those certificates. Type the below commands to generate and move the certificates to ssl folders.
您可以通过创建自签名证书然后安装这些证书来在 XAMPP 上启用 SSL。键入以下命令以生成证书并将其移动到 ssl 文件夹。
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
cp server.crt /opt/lampp/etc/ssl.crt/domainname.crt
cp server.key /opt/lampp/etc/ssl.key/domainname.key
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
cp server.crt /opt/lampp/etc/ssl.crt/domainname.crt
cp server.key /opt/lampp/etc/ssl.key/domainname.key
(Use sudo with each command if you are not the super user)
(如果您不是超级用户,请对每个命令使用 sudo)
Now, Check that mod_ssl is enabled in [XAMPP_HOME]/etc/httpd.conf:
现在,检查在 [XAMPP_HOME]/etc/httpd.conf 中是否启用了 mod_ssl:
LoadModule ssl_module modules/mod_ssl.so
LoadModule ssl_module modules/mod_ssl.so
Add a virtual host, in this example "localhost.domainname.com" by editing [XAMPP_HOME]/etc/extra/httpd-ssl.conf as follows:
添加一个虚拟主机,在本例中为“localhost.domainname.com”,通过编辑 [XAMPP_HOME]/etc/extra/httpd-ssl.conf 如下:
<virtualhost 127.0.1.4:443>
ServerName localhost.domainname.com
ServerAlias localhost.domainname.com *.localhost.domainname.com
ServerAdmin admin@localhost
DocumentRoot "/opt/lampp/htdocs/"
DirectoryIndex index.php
ErrorLog /opt/lampp/logs/domainname.local.error.log
CustomLog /opt/lampp/logs/domainname.local.access.log combined
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /opt/lampp/etc/ssl.crt/domainname.crt
SSLCertificateKeyFile /opt/lampp/etc/ssl.key/domainname.key
<directory /opt/lampp/htdocs/>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</directory>
BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
</virtualhost>
Add the following entry to /etc/hosts:
将以下条目添加到 /etc/hosts:
127.0.1.4 localhost.domainname.com
Now, try installing the certificate/ try importing certificate to browser. I have checked this and this worked on Ubuntu.
现在,尝试安装证书/尝试将证书导入浏览器。我已经检查过这个,这在 Ubuntu 上有效。
回答by Tarik
I have been through all the answers and tutorials over the internet but here are the basic stepsto enableSSL (https) on localhost with XAMPP:
我已经通过所有在互联网上的答案和教程,但这里的基本步骤,以使SSL(HTTPS在本地主机上)与XAMPP:
Required:
必需的:
Run -> "C:\xampp\apache\makecert.bat" (double-click on windows) Fill passowords of your choice, hit Enter for everything BUT define "localhost"!!! Be careful when asked here:
Common Name (e.g. server FQDN or YOUR name) []:localhost
(Certificates are issued per domain name zone only!)
- Restart apache
- Chrome -> Settings -> Search "Certificate" -> Manage Certificates -> Trusted Root Certification Authorities -> Import -> "C:\xampp\apache\conf\ssl.crt\server.crt" -> Must Ask "YES" for confirmation!
- https://localhost/testssl.php-> [OK, Now Green!] (any html test file)
运行 -> "C:\xampp\apache\makecert.bat"(双击 Windows)填写您选择的密码,按 Enter 输入所有内容,但请定义“localhost”!!!在这里询问时要小心:
通用名称(例如服务器 FQDN 或您的姓名)[]:本地主机
(证书仅针对每个域名区域颁发!)
- 重启apache
- Chrome -> Settings -> Search "Certificate" -> Manage Certificates -> Trusted Root Certification Authorities -> Import -> "C:\xampp\apache\conf\ssl.crt\server.crt" -> Must Ask "YES"确认!
- https://localhost/testssl.php-> [OK, Now Green!](任何 html 测试文件)
Optional: (if above doesn't work, do more of these steps)
可选:(如果以上不起作用,请执行更多这些步骤)
- Run XAMPP As admin (Start -> XAMPP -> right-click -> Run As Administrator)
XAMPP -> Apache -> Config -> httpd.conf ("C:\xampp\apache\conf\httpd.conf")
LoadModule ssl_module modules/mod_ssl.so (remove # form the start of line)
XAMPP -> Apache -> Config -> php.ini ("C:\xampp\php\php.ini")
extension=php_openssl.dll (remove ; from the start of line)
Restart apache and chrome!
- 以管理员身份运行 XAMPP(开始 -> XAMPP -> 右键单击 -> 以管理员身份运行)
XAMPP -> Apache -> 配置 -> httpd.conf ("C:\xampp\apache\conf\httpd.conf")
LoadModule ssl_module modules/mod_ssl.so(从行首删除#)
XAMPP -> Apache -> 配置 -> php.ini ("C:\xampp\php\php.ini")
extension=php_openssl.dll(从行首删除 ;)
重启apache和chrome!
Check any problems or the status of your certificate:
Chrome -> F12 -> Security -> View Certificate
检查任何问题或证书的状态:
Chrome -> F12 -> 安全 -> 查看证书
回答by Chris Dutrow
I did all of the suggested stuff here and my code still did not work because I was using curl
我在这里做了所有建议的东西,但我的代码仍然无法工作,因为我正在使用 curl
If you are using curlin the php file, curl seems to reject all ssl traffic by default. A quick-fix that worked for me was to add:
如果您curl在 php 文件中使用,curl 似乎默认拒绝所有 ssl 流量。对我有用的快速修复是添加:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
before calling:
在打电话之前:
curl_exec():
in the php file.
在 php 文件中。
I believe that this disables all verification of SSL certificates.
我相信这会禁用对 SSL 证书的所有验证。

