Configuring MAMP for SSL
Ok fellow coders, I am trying to c开发者_如何学运维onfigure MAMP with SSL on my mac for development purposes. I have read and tried the following instructions:
http://www.emersonlackey.com/article/mamp-with-ssl-https http://www.webopius.com/content/355/getting-mamp-working-with-ssl-on-os-xwith no luck. I can hit either 127.0.0.1
or localhost with http but both https://localhost
and https://127.0.0.1
return host not found error.
looking at phpinfo, i can't see mod_ssl being loaded.
has anyone done this with os x 10.6.7? i have no idea where to go from here.
hope someone can help.
thanks
------edit start------
the following are the changes i have made to the config files to get https working. Please follow the tuts listed above to get the certificate/key created and the password removed (as also mentioned by @dallas below).
httpd.conf
Comment out the ifdef to make sure LoadModule is executed
#<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
#</IfDefine>
make sure the following is in the file...
Listen 80
ServerName localhost:80
ssl.conf
Add the following ....
<VirtualHost localhost:443>
DocumentRoot /Users/myname/Documents/DevProjects/WebdevProjects
ServerName localhost
SSLEngine on
SSLCertificateFile /Applications/MAMP/conf/ssl/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/ssl/server.key
</VirtualHost>
before the existing
<VirtualHost _default_:443>
server.crt and server.key are the newly created ones as per the obove tuts' links.
Comment out
#<IfDefine SSL>
around line 35 and its closing tag around line 245 to enable the line...
Listen 443
in between, update all certificate references to the newly created files as per the above VirtualHost definition.
If you're using MAMP 3 or 4 the instructions are slightly different. Here's what worked for me, starting from a fresh install of MAMP 3.0.5 on Mavericks without Pro.
Update: Still works on Yosemite after fixing Apache as described in this answer.
Further Update: Comments suggest this still works at least through MAMP 5.4.
Generate the certificate
This part is straight from the tutorials, so if you already did it you can skip to "Set up MAMP".
Use the terminal to generate a private key in your default folder:
cd ~
# generate a private key
openssl genrsa -des3 -out server.key 2048
# make up a passphrase and remember it, you’ll need it 3 more times.
# generate certificate signing request
openssl req -new -key server.key -out server.csr
# same password
# answer the questions, use "localhost" for your Common Name
Country Name: US
State Name: California
Locality: My City
Organization: My Company
Organization Unit Name: # leave blank
Common Name: localhost
Email address: email@example.com
A challenge password: # leave blank
An optional company name: # leave blank
# generate the certificate from the CSR for 5 years
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt
# remove the password requirement from the server key
cp server.key server.tmp
openssl rsa -in server.tmp -out server.key
Set up MAMP 3.0.5
Here's where the instructions from previous versions are a little off. The filenames and locations changed and some of the commands in the conf files are different. The following is what worked for me on a fresh install of MAMP 3.0.5.
Move the certificate files (server.key and server.crt) to:
/Applications/MAMP/conf/apache/
Open Apache's httpd.conf file:
/Applications/MAMP/conf/apache/httpd.conf
# set your listen port to 80 (near the top of the file)
Listen 80
# set your ServerName to localhost:80 (default is 8888)
ServerName localhost:80
# uncomment the line that includes the secure (SSL/TLS) connection conf
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
Save it and close. Now open Apache's ssl conf file:
/Applications/MAMP/conf/apache/extra/httpd-ssl.conf
Find the <VirtualHost>
entry (big block at the end of the file starting with <VirtualHost _default_:443>
and ending with </VirtualHost>
) and replace the entire thing with:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /Applications/MAMP/conf/apache/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/server.key
</VirtualHost>
Save and close. Start your MAMP server. You should be able to access your document root at http://localhost
and https://localhost
.
It's Very Difficult way for https here is simple way.
Open MAMP Pro.
- In Server Tab Make Sure Your HTTP Port is 80 and HTTPS Port is 443
- Click on Hosts Tab
- Click On Plus Arrow for add new host.
- Add 127.0.0.1 As Hostname
- Click SSL Enable
- Select Directory Where is your htdocs or websites folder
- Click on SSL Tab
- Create Self Signed Certificate By Button Below.
- Then it will ask for save location after save it will select certificate auto.
- Restart your MAMP Server.
Enjoy!!!!
Type : https with localhost then you can see result.
Next
I just ran into the same problem but was able to fix it.
I'm running; Mac OS 10.6.7 MAMP 1.9.4
I have only read the tut from webopius which does a good job but it missed something.
I changed in the httpd.conf
Listen 80
not Listen 127.0.0.1:80
I also forgot to run this in the terminal
cp server.key server.tmp
openssl rsa -in server.tmp -out server.key
That removes the password needed to use the key, which if you don't start apache in the terminal, then you can't enter the pass phrase for the cert.
What you can do is, run this command to start apache for MAMP and see if any errors pop out.
sudo /Applications/MAMP/Library/bin/apachectl start
Ok, think that covers about it.
I followed the webopius instructions as well, but couldn't get SSL pages to load. As mentioned by @djeetee, the definition of the virtual server in httpd.conf and ssl.conf is problematic. The best guide I found recommended making the following revisions to those files:
- Before you make these edits, make sure you've generated the key/cert as detailed by webopius and made the basic edits to httpd.conf, such as commenting out the SSL IfDefine statements.
Edit ssl.conf, deleting the existing VirtualHost declaration (around 160 lines, runs to the end of the file) and replacing it with something simple:
<VirtualHost *:443> SSLEngine on SSLCertificateFile /Applications/MAMP/conf/ssl/server.crt SSLCertificateKeyFile /Applications/MAMP/conf/ssl/server.key </VirtualHost>
In my case, I was only enabling SSL for a specific VirtualHost; I had to add a DocumentRoot to the definition to make it work:
DocumentRoot "/Applications/MAMP/htdocs/subfolder"
Edit httpd.conf, again, configuring the VirtualHosts a bit differently than the default.
NameVirtualHost *:80 NameVirtualHost *:443 <VirtualHost *:80> DocumentRoot "/Applications/MAMP/htdocs" ServerName localhost:80 </VirtualHost>
Again, in my case I had an additional VirtualHost where my SSL action was going on:
<VirtualHost *> DocumentRoot "/Applications/MAMP/htdocs/subfolder" ServerName dev.subfolder.localhost </VirtualHost>
Again, check out Mr. Lackey's blog for more comprehensive instructions that'll take you through the entire process; these were just the things I did to salvage my install after using Webopius.
Also make sure you uncomment this line in httpd.conf
# Secure (SSL/TLS) connections
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
Otherwise it will not be included when you start Apache. Mine was commented out for some reason.
If you're using MAMP 4 and you're still struggling to get ssl working.
Here is how I got it working.
Step 1: Generate the certificate (Follow Roberts Instruction)
Step 2: Make sure 'LoadModule ssl_module modules/mod_ssl.so' has been uncommented.
Step 3: I use 'Listen 81' (without quotes) instead of 80 (I think something is using it but test it out on some port numbers if you can or just stick to 81).
Step 4: Make 'ServerName localhost:81' (without quotes).
Step 5: Uncomment 'Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf'
Step 6: Make sure the 'server.crt' and the 'server.key' are in the right place (this should be right if you follow Roberts instruction)
Step 7: Open httpd-ssl.conf file (follow the path that the include is pointing at) Change 'Listen 443' to 'Listen *:443'
Step 8: Find <VirtualHost _default_:443>
change it to <VirtualHost *:443>
Step 9: You can either do it two ways on this one, you can point the 'DocumentRoot' to the folder of your project/website or you can just comment out the 'DocumentRoot' (I have chosen to comment it out).
Step 10: Change 'ServerName www.example.com:443' to 'localhost:443'
Step 11: Optional- The Directory path maybe wrong because the 'cgi-bin' is actually in the MAMP folder not library, however I left that alone and it seems to work fine for me.
Quit MAMP, reopen it and start the server. You should be able to access http://localhost:81 and to get to the ssl site its https://localhost:443.
I hope my instruction were clear and your MAMP works. Good luck
P.s if it is still not working use 'sudo /Applications/MAMP/Library/bin/apachectl start' in the terminal to see what error you get.
精彩评论