How to Install ssl certificate in xampp server in ubuntu - ssl

I haves domain.crt and domain.key, how can install in xampp server in Ubuntu os,can any one tell me the steps

I think you can do it in httpd-vhost file.
Find this file,
xampp/apache/conf/extra/httpd-vhost.conf
and add this to the bottom of the page.
DocumentRoot /your/project/root/folder
ServerName subdomain.domain.com
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
You will also need to enable vhost in httpd.conf
Add this line to httpd.conf file
~# Virtual hosts
Include etc/extra/httpd-vhosts.conf

Related

Apache conf VirtualHost ignored

I'm running apache on a CentOS 7.
I have 2 config files in /etc/httpd/conf.d :
A10-my_site_dev.conf
A10-my_site_test.conf
As they are similar, I show you only one of the files :
<VirtualHost *:443>
ErrorLog "logs/my_site_test.log"
SSLCertificateFile /etc/ssl/host/host.crt
SSLCertificateKeyFile /etc/ssl/host/host.key
Alias /my-site/test/static /var/www/my_site_test/static/
<Directory /var/www/my_site_test/static>
Require all granted
</Directory>
WSGIScriptAlias /my-site/test /var/www/my_site_test/app/wsgi.py
<Directory /var/www/my_site_test>
Require all granted
</Directory>
</VirtualHost>
Currently, VirtualHost in A10-my_site_test.conf is ignored. If I go to https://my-server.com/my-site/test, I've got a 404, but https://my-server.com/my-site/dev is working fine.
If I remove A10-my_site_dev.conf and restart apache, https://my-server.com/my-site/test works.
I understood that it takes only the first VirtualHost apache finds.
I have the feeling that VirtualHost in my ssl.conf is ignored too cause, if I move SSLCertificateFile and SSLCertificateKeyFile to ssl.conf, I have the following error :
I tried not to use VirtualHost, and everything works fine in that case. I think all VirtualHost are ignored except the first.
I've got the same problem with other ports (like 80).
Another point : I read that I should have a ServerName. But I have the same ServerName for all my environments. I tried to put something random such as "my_site_test" as ServerName, but I've got a 404.
How could I configure apache to make my 2 files work ?
This is not how VirtualHosts work. Especially with SSL.
So you have:
<VirtualHost *:443>
CONFIGURATION FOR DEV
</VirtualHost>
<VirtualHost *:443>
CONFIGURATION FOR TEST
</VirtualHost>
The only difference between both VirtualHosts is the logs and directory? That will not work.
Apache can distinguish between VirtualHost sections based on:
IP associated to the domain
Port
ServerName (for non-SSL configurations)
The way you configured it right now, Apache cannot distinguish between both VirtualHosts. So it takes the first one it finds. That explains the mix up with certificates.
Ex of a working configuration
# www.example1.com == 1.1.1.1
# www.example2.com == 2.2.2.2
<VirtualHost 1.1.1.1:443>
ServerName www.example1.com
# SSL CONFIG
# LOGS CONFIG
# OTHER CONFIGURATION
</VirtualHost>
<VirtualHost 2.2.2.2:443>
ServerName www.example2.com
# SSL CONFIG
# LOGS CONFIG
# OTHER CONFIGURATION
</VirtualHost>
Read the documentation (again?), it will do you good: https://httpd.apache.org/docs/2.4/vhosts/examples.html
There are posts on this site explaining the finer points of SSL VirtualHosts configuration (I even wrote some myself).

One Multisite SSL on Two virtual hosts (Apache2 on Ubuntu 16.04)

I have one SSL certificate from GoDaddy (Standard UCC SSL Certificate for up to 5 sub/domains) and two virtual hosts configuration on Apache2.
I can install SSL certificate one every of them separately and they works fine until I add second one.
When the second HTTPS config is added (...), then I am getting kind of weird redirects from one.abc.com to two.abc or vice versa.
I am using the same certificate files for both configs, because it the same Multisite SSL certificate.
F.ex.:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.abc.com
DocumentRoot /var/www/htdocs
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/abc.crt
SSLCertificateKeyFile /etc/apache2/ssl/abc.key
SSLCertificateChainFile /etc/apache2/ssl/abc_bundle.crt
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName subd2.abc.com
DocumentRoot /var/www/test2
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/abc.crt
SSLCertificateKeyFile /etc/apache2/ssl/abc.key
SSLCertificateChainFile /etc/apache2/ssl/abc_bundle.crt
</VirtualHost>
</IfModule>
What I am doing wrong?
This:
Now - I understand that because SSL wraps around the HTTP request,
there's no way to know which host is being requested until a public
key has been sent to the client first. This essentially breaks the
possibility of SSL virtual hosts using a standard SSL certificate.
from
https://serverfault.com/questions/113076/apache-ssl-virtualhosts-on-a-single-ip-using-ucc-san-certificate
Lead me to idea that problem is simple that in case of abc.com server just do not know which HTTPS server (www.abc.com or subd2.abc.com) config to take and simply take the first one. Tests that approved.
From that comes second question / conclusion - do I have configuration for domain abc.com. And it has not, I just have it defined as ServerAlias in www.abc.com config.
When I removed from ServerAlias and created configuration with for abc.com and with redirect, than all stays in their places.

Setup Certbot on xampp Apache Ubuntu

I tried to setup a SSL certificate with: https://certbot.eff.org/lets-encrypt/ubuntuxenial-apache documentation.
It worked, the only problem was that it's on the wrong Apache server. I got 2 Apache server's on my Ubuntu 16.04 System. 1 is linking to /var/www/html and the other one (this one is of my XWAMPP server) is linking to /opt/lampp/htdocs
The Apache server that links to /var/www/html on this one the SSL is activated. With the command: sudo certbot --apache
I want it to be activated on the Apache server of the XAMPP. How can I edit this command so it calls the other Apache server?
I solved this with next steps:
(*) First of all, you should be avaible certbot command and your virtualhost should be configured for the domain that you need https. f.e. mydomain.com. verify the domain is avaible in your browser.
sudo yum install certbot python2-certbot-apache
certbot --apache-ctl /opt/lampp/bin/apachectl
This, create the cert, in /etc/letsencrypt/live/mydomain.com/.
Also, step 2 create a new vhost file in /opt/lampp/etc/extra/. please review.
then, add this new file in your vhost zone (/opt/lampp/etc/httpd.conf).
restart your xampp apache.
It will work but for this you need and static ip and portforward 80 and 443 to your system ip and link with domain you can try no-ip they will give you free domain after that you need to visit https://www.sslforfree.com/
after this follow the step they say. After verifying you can download the ssl file. you need to put extract file in C:\xampp\apache\conf
after this goto C:\xampp\apache\conf\extra
and edit httpd-vhosts.conf and following thing you can change according to your domain or root directory
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#osticket.dev
DocumentRoot "C:/xampp/htdocs/upload"
ServerName osticketamcat.ddns.net
ServerAlias osticketamcat.ddns.net
SSLEngine on
SSLCACertificateFile "C:\xampp\apache\conf\ssl\ca_bundle.crt"
SSLCertificateFile "C:\xampp\apache\conf\ssl.crt\server.crt"
SSLCertificateKeyFile "C:\xampp\apache\conf\ssl.key\server.key"
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
<Directory "C:/xampp/htdocs/upload">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
I solved this issue.
sudo certbot --apache-ctl /opt/lampp/bin/apachectl
sudo nano /opt/lampp/etc/httpd.conf
------------
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
Include etc/extra/httpd-vhosts-le-ssl.conf #Add it here

Start Apache without Virtual Host's SSL certificate file

I have Apache 2.4.10 with name based SSL (SNI) virtual hosting.
Virtual users can use their own certificate and upload it to server.
Everything works fine until there is some error with certificate file (i.e. file is missing or with wrong name).
Problem is Apache will not start if there is some certificate problem.
Is there some solution how to start Apache with this error (i.e. all vhosts will start except that one virtual host with failure)?
This does not work:
<If "-f /path/to/file.crt">
<VritualHost *:443>
SSLEngine On
SSLCertificateFile /path/to/file.crt
</VirtualHost>
</If>
...and this also does not work:
<VritualHost *:443>
<If "-f /path/to/file.crt">
SSLEngine On
SSLCertificateFile /path/to/file.crt
</If>
</VirtualHost>
Many thanks.

Enabling SSL with XAMPP

I've been following this guide as much as I could
http://robsnotebook.com/xampp-ssl-encrypt-passwords .
However whenever I browse to a page starting with https the apache server replies 404 Object Not Found.
What setting I am missing? Thanks for any help.
Found the answer. In the file xampp\apache\conf\extra\httpd-ssl.conf, under the comment SSL Virtual Host Context pages on port 443 meaning https is looked up under different document root.
Simply change the document root to the same one and problem is fixed.
You can also configure your SSL in xampp/apache/conf/extra/httpd-vhost.conf like this:
<VirtualHost *:443>
DocumentRoot C:/xampp/htdocs/yourProject
ServerName yourProject.whatever
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
</VirtualHost>
I guess, it's better not change it in the httpd-ssl.conf if you have more than one project and you need SSL on more than one of them
For XAMPP, do the following steps:
G:\xampp\apache\conf\extra\httpd-ssl.conf"
Search 'DocumentRoot' text.
Change DocumentRoot DocumentRoot "G:/xampp/htdocs" to DocumentRoot "G:/xampp/htdocs/project name".
configure SSL in xampp/apache/conf/extra/httpd-vhost.conf
http
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/myproject/web"
ServerName www.myurl.com
<Directory "C:/xampp/htdocs/myproject/web">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
https
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs/myproject/web"
ServerName www.myurl.com
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
<Directory "C:/xampp/htdocs/myproject/web">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
make sure server.crt & server.key path given properly otherwise this will not work.
don't forget to enable vhost in httpd.conf
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
There is a better guide here for Windows:
https://shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/
Basic steps:
Create an SSL certificate for your local domain using this: See more details in the link above
https://gist.github.com/turtlepod/3b8d8d0eef29de019951aa9d9dcba546
https://gist.github.com/turtlepod/e94928cddbfc46cfbaf8c3e5856577d0
Install this cert in Windows (Trusted Root Certification Authorities) See more details in the link above
Add the site in Windows hosts (C:\Windows\System32\drivers\etc\hosts)
E.g.: 127.0.0.1 site.test
Add the site in XAMPP conf (C:\xampp\apache\conf\extra\httpd-vhosts.conf)
E.g.:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName site.test
ServerAlias *.site.test
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs"
ServerName site.test
ServerAlias *.site.test
SSLEngine on
SSLCertificateFile "crt/site.test/server.crt"
SSLCertificateKeyFile "crt/site.test/server.key"
</VirtualHost>
Restart Apache and your browser and it's done!
I finally got this to work on my own hosted xampp windows 10 server web site. I.e. padlocks came up as ssl. I am using xampp version from November 2020.
Went to certbot.eff.org. Selected from their home page software [apache] and system [windows]. Then downloaded and installed certbot software found at the next page into my C drive.
Then from command line [cmd in Windows Start and then before you open cmd right click to run cmd as admin] I enhtered the command from Certbot page above. I.e. navigated to system32-- C:\WINDOWS\system32> certbot certonly --standalone
Then followed the prompts and enteredmy domain name. This created certs as cert1.pem and key1.pem in C:\Certbot yourwebsitedomain folder. the cmd windows tells you where these are.
Then took these and changed their names from cert1.pem to my domainname or shorter+cert.pem and same for domainname or shorter+key.key. Copied these into C:\xampp\apache\ssl.crt and ssl.key folders respectively.
Then for G:\xampp\apache\conf\extra\httpd-vhosts entered the following:
<VirtualHost *:443>
DocumentRoot "G:/xampp/htdocs/yourwebsitedomainname.hopto.org/public/" ###NB My document root is public. Yours may not be. Or could have an index.php page before /public###
ServerName yourwebsitedomainnamee.hopto.org
<Directory G:/xampp/htdocs/yourwebsitedomainname.hopto.org>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
ErrorLog "G:/xampp/apache/logs/error.log"
CustomLog "G:/xampp/apache/logs/access.log" common
SSLEngine on
SSLCertificateFile "G:\xampp\apache\conf\ssl.crt\abscert.pem"
SSLCertificateKeyFile "G:\xampp\apache\conf\ssl.key\abskey.pem"
</VirtualHost>
Then navigated to G:\xampp\apache\conf\extra\httpd-ssl.conf and did as was advised above. I missed this important step for days until I read this post. Thank you!
I.e. entered
<VirtualHost _default_:443>
DocumentRoot "G:/xampp/htdocs/yourwebsitedomainnamee.hopto.org/public/"
###NB My document root is public. Yours may not be. Or could have an index.php page before /public###
SSLEngine on
SSLCertificateFile "conf/ssl.crt/abscert.pem"
SSLCertificateKeyFile "conf/ssl.key/abskey.pem"
CustomLog "G:/xampp/apache/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
Note1. I used www.noip.com to register the domain name.
Note2. Rather then try to get them to give me a ssl certificate, as I could not get it to work, the above worked instead.
Note3 I use the noip DUC software to keep my personally hosted web site in sync with noip.
Note4. Very important to stop and start xampp server after each change you make in xampp. If xampp fails for some reason instead of starting the xampp consol try the start xampp as this will give you problems you can bug fix. Copy these quickly and paste into note.txt.
In case you are on Mac OS (catalina or mojave) and wants to enable HTTPS/SSL on XAMPP for Mac, you need to enable the virtual host and use the default certificates included in XAMPP.
On your httpd-vhosts.conf file add a new vhost:
<VirtualHost *:443>
ServerAdmin webmaster#localhost.com
DocumentRoot "/Users/your-user/your-site"
ServerName your-site.local
SSLEngine on
SSLCertificateFile "etc/ssl.crt/server.crt"
SSLCertificateKeyFile "etc/ssl.key/server.key"
<Directory "/Users/your-user/your-site">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>