I want to install a certificate for my website but I am encountering some issues. I use a LAMP stack to host my website and things seem to work fine over HTTP. When I try to install a certificate using Certbot, I get the following.
$ sudo certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError('Cannot find Apache executable apache2ctl')
However, I get the same error as previously mentioned, plus I could not see the parameter --apache-server-root in the options when consulting certbot --help.
I am now back to my initial problem where I was able to install a certificate following this tutorial. However, then I needed to do further configurations such as enabling PHP-file execution and using phpMyAdmin. Since I am not a web-hosting wizard or any kind of wizard, I decided to use LAMP which makes things work out of the box.
When trying to start LAMP, the system moans about an Apache server running:
> $ sudo /opt/lampp/lampp start
> Starting XAMPP for Linux 7.4.11-0...
> XAMPP: Starting Apache...fail.
> XAMPP: Another web server is already running.
> XAMPP: Starting MySQL...already running.
> XAMPP: Starting ProFTPD...already running.
Now in this system state, I have a working website in the sense PHP files are executed and phpMyAdmin is accessible, but I can no longer access it using https. It looks like the certificate attaches itself to apache2, but not httpd.
So there is where httpd operates from [not from /etc/apache2/].
I don't think certbot using --apache is well prepared for this Apache spinoff.
We need to take a look at this file:
to see if we can use certbot with --webroot instead.
[&2* readers: Get involved; Be heard. It starts with: if you read something you like, then like it ]
This is the content of /etc/apache2/sites-enabled/000-default.conf:
$ cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /home/aminemarref/websites/marref_org
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =marref.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
OK. I would remove the "noise" and also rework the redirect logic to just redirect all HTTP to HTTPS [except for the challenge requests].
So it would would something like this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/aminemarref/websites/marref_org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<LocationMatch "^/(?!\.well-known)">
#send all other requests to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1
</LocationMatch>
</VirtualHost>
[&2* readers: Get involved; Be heard. It starts with: if you read something you like, then like it ]
We can now use that DocumentRoot path as the --webroot parameter for certbot.
[instead of --apache]
Try: certbot certonly --webroot -w /home/aminemarref/websites/marref_org -d marref.org
Then also show this file: /etc/apache2/sites-enabled/000-default-le-ssl.conf
and just to be sure: certbot certificates
[&2* readers: Get involved; Be heard. It starts with: if you read something you like, then like it ]