php 如何在 WAMP 服务器 (v2.5) 中启用 https (localhost) url?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29047078/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:13:04  来源:igfitidea点击:

How to enable https (localhost) url in WAMP server (v2.5)?

phpapachesslhttpswamp

提问by appsntech

I am using wamp server and running php project in localhost. I would like to test my project using "https" based url.

我正在使用 wamp 服务器并在本地主机中运行 php 项目。我想使用基于“https”的 url 来测试我的项目。

I tried with "https://localhost/myproject/" and it redirecting me to "This webpage is not available" page.

我尝试使用“ https://localhost/myproject/”并将我重定向到“此网页不可用”页面。

I have enabled "php_openssl" and "ssl" module into apache config. But still unable to access https based url.

我已经在 apache 配置中启用了“php_openssl”和“ssl”模块。但仍然无法访问基于 https 的 url。

回答by azdoud

You have to set up your WAMP first with key and a certificate:

您必须首先使用密钥和证书设置 WAMP:

  1. Download openssl choose the appropriate version according to your Operating system from here.
  2. Install it, than run the cmd and get where you've installed it: cd 'C:\OpenSSL-Win**'be sure be in the appropriate folder

  3. run these commands :

    • C:\OpenSSL-Win..\bin>openssl genrsa -aes256 -out private.key 2048
    • C:\OpenSSL-Win..\bin>openssl rsa -in private.key -out private.key
    • C:\OpenSSL-Win..\bin>openssl req -new -x509 -sha1 -key private.key -out certificate.crt -days 36500 -config C:\OpenSSL-Win..\bin\openssl.cfg

    You will be asked to enter a pass phrase for private.key, Country Nameand so on.

  4. Once you are done, the files will be generated: private.keyand certificate.crt, create a folder, name it keyin this path C:\wamp...bin\apache\apache2.*.**\conf.

  5. Open this file httpd.conf. You'll find it in C:\wamp...bin\apache\apache2.*.**\confuncomment these lines by removing #at the beginning of the line, than save the file.

    LoadModule ssl_module modules/mod_ssl.so
    LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
    Include conf/extra/httpd-ssl.conf
    
  6. Open httpd-ssl.conffile you'll find it also in C:\wamp...bin\apache\apache2.*.**\conf\extraand change the default value by these lines, pay attention to the path, I ve created a folder sslinside C:/wamp../bin/apache/apache2.*.**/logs/

    <VirtualHost _default_:443>
    #   General setup for the virtual host
    DocumentRoot "C:/wamp../www"
    ServerName localhost:443
    ServerAdmin [email protected]
    ErrorLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/error.log"
    TransferLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/access.log"
    ....
    CustomLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/ssl_request.log" \
    ....
    SSLCertificateFile "C:/wamp../bin/apache/apache2.*.**/conf/key/certificate.crt"
    SSLCertificateKeyFile "C:/wamp../bin/apache/apache2.*.**/conf/key/private.key"
    

    once done save your file.

  7. I copied ssleay32.dll & libeay32.dll from C:\wamp..\bin\php\php7.0.10folder to c:\windows\system32.

  8. finaly check the configuration get in cd C:\wamp64\bin\apache\apache2.4.23\binand run this command httpd -tif everything is okay you will get .

    C:\wamp64\bin\apache\apache2.4.23\bin>httpd -t
    Syntax OK
    
  9. https://localhost/will work for you :)

  1. 这里下载 openssl 根据您的操作系统选择合适的版本。
  2. 安装它,然后运行 ​​cmd 并获取安装它的位置: cd 'C:\OpenSSL-Win**'确保位于适当的文件夹中

  3. 运行这些命令:

    • C:\OpenSSL-Win..\bin>openssl genrsa -aes256 -out private.key 2048
    • C:\OpenSSL-Win..\bin>openssl rsa -in private.key -out private.key
    • C:\OpenSSL-Win..\bin>openssl req -new -x509 -sha1 -key private.key -out certificate.crt -days 36500 -config C:\OpenSSL-Win..\bin\openssl.cfg

    您将被要求输入private.key国家名称等的密码短语。

  4. 完成后,将生成文件:private.key然后certificate.crt,创建一个文件夹,将其命名为keyin this path C:\wamp...bin\apache\apache2.*.**\conf

  5. 打开这个文件httpd.confC:\wamp...bin\apache\apache2.*.**\conf通过#在行的开头删除而不是保存文件,您可以在取消注释这些行中找到它。

    LoadModule ssl_module modules/mod_ssl.so
    LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
    Include conf/extra/httpd-ssl.conf
    
  6. 打开httpd-ssl.conf文件,你也会在其中找到它C:\wamp...bin\apache\apache2.*.**\conf\extra并通过这些行更改默认值,注意路径,我在ssl里面创建了一个文件夹C:/wamp../bin/apache/apache2.*.**/logs/

    <VirtualHost _default_:443>
    #   General setup for the virtual host
    DocumentRoot "C:/wamp../www"
    ServerName localhost:443
    ServerAdmin [email protected]
    ErrorLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/error.log"
    TransferLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/access.log"
    ....
    CustomLog "C:/wamp../bin/apache/apache2.*.**/logs/ssl/ssl_request.log" \
    ....
    SSLCertificateFile "C:/wamp../bin/apache/apache2.*.**/conf/key/certificate.crt"
    SSLCertificateKeyFile "C:/wamp../bin/apache/apache2.*.**/conf/key/private.key"
    

    完成后保存您的文件。

  7. 我将 ssleay32.dll 和 libeay32.dll 从C:\wamp..\bin\php\php7.0.10文件夹复制到c:\windows\system32.

  8. 最后检查配置进入cd C:\wamp64\bin\apache\apache2.4.23\bin并运行此命令,httpd -t如果一切正常,您将获得。

    C:\wamp64\bin\apache\apache2.4.23\bin>httpd -t
    Syntax OK
    
  9. https://localhost/将为您工作:)

回答by David Peicho

By default, you can't use https protocol for your wamp connections. What you need to do is to set up a self-signed certificate on wamp.

默认情况下,您不能为 wamp 连接使用 https 协议。您需要做的是在 wamp 上设置一个自签名证书。

Follow this tutorialfor more information.

按照本教程获取更多信息。

回答by T.Todua

Edit:I've moved my answer to the original topic - How to enable SSL in WAMP Server?

编辑:我已将答案移至原始主题 -如何在 WAMP 服务器中启用 SSL?