Certbot on ubuntu 20.04

Please, I would like to create a certificat with certbot on ubuntu 20.04
I run a command following,
sudo certbot --apache
sudo certbot --nginx
sudo certbot --apache -d example.com -d www.example.com

the output is here for each command
The requested apache plugin does not appear to be installed

Please someone can help me

How did install Certbot? Did you also install the Apache plugin?

I've installed certbot with snap
sudo snap install --classic certbot

Hm, weird, if I read the instructions (Certbot Instructions | Certbot) right, that command should also include the apache plugin..

Can you perhaps show the contents of /var/log/letsencrypt/letsencrypt.log ?

This is the contents of /var/log/letsencrypt/letsencrypt.log

root@nextcloud:~# cat /var/log/letsencrypt/letsencrypt.log
2022-02-14 08:46:51,710:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 08:46:51,711:DEBUG:certbot.main:Arguments: ['--email', 'ouattara_koudoussou@bfix.bf']
2022-02-14 08:46:51,711:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 08:46:51,727:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 08:46:51,727:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 08:46:51,884:DEBUG:acme.client:Sending GET request to https://acme-v02.api.letsencrypt.org/directory.
2022-02-14 08:46:51,910:DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org:443
2022-02-14 08:46:53,765:DEBUG:urllib3.connectionpool:https://acme-v02.api.letsencrypt.org:443 "GET /directory HTTP/1.1" 200 658
2022-02-14 08:46:53,766:DEBUG:acme.client:Received response:
HTTP 200
Server: nginx
Date: Mon, 14 Feb 2022 08:46:53 GMT
Content-Type: application/json
Content-Length: 658
Connection: keep-alive
Cache-Control: public, max-age=0, no-cache
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800

{
"-g257LhM4_A": "Adding random entries to the directory",
"keyChange": "https://acme-v02.api.letsencrypt.org/acme/key-change",
"meta": {
"caaIdentities": [
"letsencrypt.org"
],
"termsOfService": "https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf",
"website": "https://letsencrypt.org"
},
"newAccount": "https://acme-v02.api.letsencrypt.org/acme/new-acct",
"newNonce": "https://acme-v02.api.letsencrypt.org/acme/new-nonce",
"newOrder": "https://acme-v02.api.letsencrypt.org/acme/new-order",
"revokeCert": "https://acme-v02.api.letsencrypt.org/acme/revoke-cert"
}
2022-02-14 08:47:02,206:DEBUG:acme.client:Requesting fresh nonce
2022-02-14 08:47:02,206:DEBUG:acme.client:Sending HEAD request to https://acme-v02.api.letsencrypt.org/acme/new-nonce.
2022-02-14 08:47:02,457:DEBUG:urllib3.connectionpool:https://acme-v02.api.letsencrypt.org:443 "HEAD /acme/new-nonce HTTP/1.1" 200 0
2022-02-14 08:47:02,458:DEBUG:acme.client:Received response:
HTTP 200
Server: nginx
Date: Mon, 14 Feb 2022 08:47:02 GMT
Connection: keep-alive
Cache-Control: public, max-age=0, no-cache
Link: https://acme-v02.api.letsencrypt.org/directory;rel="index"
Replay-Nonce: 0001Okr75rQPg6xoEC8fBzDm_pTY5YNjlTGq_61RlAYPL8o
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800

2022-02-14 08:47:02,458:DEBUG:acme.client:Storing nonce: 0001Okr75rQPg6xoEC8fBzDm_pTY5YNjlTGq_61RlAYPL8o
2022-02-14 08:47:02,458:DEBUG:acme.client:JWS payload:
b'{\n "contact": [\n "mailto:ouattara_koudoussou@bfix.bf"\n ],\n "termsOfServiceAgreed": true,\n "resource": "new-reg"\n}'
2022-02-14 08:47:02,463:DEBUG:acme.client:Sending POST request to https://acme-v02.api.letsencrypt.org/acme/new-acct:
{
"protected": "eyJhbGciOiAiUlMyNTYiLCAiandrIjogeyJuIjogIngweUNvUXprdEtVenFfME5VVjRTNGV0UGp4R2plZnJodmtFWkFKcEtsVnFoSWtJOGtCMnI1eTk5Z08xdmdNV3IwT2dkUDdqZFdPcWJSdHJEalhHTm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:DEBUG:urllib3.connectionpool:https://acme-v02.api.letsencrypt.org:443 "POST /acme/new-acct HTTP/1.1" 201 569
2022-02-14 08:47:02,722:DEBUG:acme.client:Received response:
HTTP 201
Server: nginx
Date: Mon, 14 Feb 2022 08:47:02 GMT
Content-Type: application/json
Content-Length: 569
Connection: keep-alive
Boulder-Requester: 408392430
Cache-Control: public, max-age=0, no-cache
Link: https://acme-v02.api.letsencrypt.org/directory;rel="index", https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf;rel="terms-of-service"
Location: https://acme-v02.api.letsencrypt.org/acme/acct/408392430
Replay-Nonce: 0001VhowKre75zunDdVIBQpbqRAGjmY381HONpBCJN0VMA0
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800

{
"key": {
"kty": "RSA",
"n": "x0yCoQzktKUzq_0NUV4S4etPjxGjefrhvkEZAJpKlVqhIkI8kB2r5y99gO1vgMWr0OgdP7jdWOqbRtrDjXGNfcwVN8FLzwO4Q78gef0fDhBWMF8IjVwgOK-pFYkPoX3wpqMyE30FPI3Oh4CLIY3h--4TZolt-DHqWaxYeLy4is7AyFLfh2XYxNK7hukNE4IazJuWoSoPnF4uA6RMm6waKzwL_rUOqdaGjeqnQoXSa7Wu-P0OEOOLeg9vGNL0EXXY5VhGWt9lEALlsLDZ0yTHYVHMO98QK1sLyI7_jTc_hKflU6bkxaoDUAJs9Il5anJb4KBDbdAvfu3IKdd6OFAcPw",
"e": "AQAB"
},
"contact": [
"mailto:ouattara_koudoussou@bfix.bf"
],
"initialIp": "196.49.19.49",
"createdAt": "2022-02-14T08:47:02.599998704Z",
"status": "valid"
}
2022-02-14 08:47:02,722:DEBUG:acme.client:Storing nonce: 0001VhowKre75zunDdVIBQpbqRAGjmY381HONpBCJN0VMA0
2022-02-14 08:47:02,724:DEBUG:certbot.reporter:Reporting to user: Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal.
2022-02-14 08:47:07,707:DEBUG:certbot.eff:Sending POST request to Read Our Newsletter | Electronic Frontier Foundation
{'data_type': 'json', 'email': 'ouattara_koudoussou@bfix.bf', 'form_id': 'eff_supporters_library_subscribe_form'}
2022-02-14 08:47:07,709:DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): supporters.eff.org:443
2022-02-14 08:47:09,780:DEBUG:urllib3.connectionpool:https://supporters.eff.org:443 "POST /subscribe/certbot HTTP/1.1" 200 52
2022-02-14 08:47:09,782:DEBUG:certbot.eff:Received response:
b'{"status":false,"message":"Please try again later."}'
2022-02-14 08:47:09,783:DEBUG:certbot.reporter:Reporting to user: We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
2022-02-14 09:48:11,917:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 09:48:11,918:DEBUG:certbot.main:Arguments: ['--apache']
2022-02-14 09:48:11,918:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 09:48:11,931:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 09:48:11,931:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 09:48:11,932:DEBUG:certbot.plugins.selection:Requested authenticator apache and installer apache
2022-02-14 09:48:11,932:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 09:48:11,932:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None
2022-02-14 09:49:00,885:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 09:49:00,885:DEBUG:certbot.main:Arguments: ['--apache']
2022-02-14 09:49:00,886:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 09:49:00,899:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 09:49:00,899:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 09:49:00,900:DEBUG:certbot.plugins.selection:Requested authenticator apache and installer apache
2022-02-14 09:49:00,900:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 09:49:00,901:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None
2022-02-14 09:49:23,532:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 09:49:23,533:DEBUG:certbot.main:Arguments: ['--nginx']
2022-02-14 09:49:23,533:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 09:49:23,545:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 09:49:23,546:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 09:49:23,547:DEBUG:certbot.plugins.selection:Requested authenticator nginx and installer nginx
2022-02-14 09:49:23,547:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 09:49:23,547:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None
2022-02-14 09:50:16,099:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 09:50:16,100:DEBUG:certbot.main:Arguments: ['--apache', '-d', 'nextcloud.bfix.bf', '-d', 'www.nextcloud.bfix.bf']
2022-02-14 09:50:16,100:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 09:50:16,113:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 09:50:16,113:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 09:50:16,114:DEBUG:certbot.plugins.selection:Requested authenticator apache and installer apache
2022-02-14 09:50:16,114:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 09:50:16,114:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None
2022-02-14 09:50:41,974:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 09:50:41,974:DEBUG:certbot.main:Arguments: ['--apache']
2022-02-14 09:50:41,974:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 09:50:41,987:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 09:50:41,987:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 09:50:41,988:DEBUG:certbot.plugins.selection:Requested authenticator apache and installer apache
2022-02-14 09:50:41,988:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 09:50:41,988:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 09:50:41,988:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None
2022-02-14 09:50:41,988:INFO:certbot.main:Could not choose appropriate plugin: The requested apache plugin does not appear to be installed
2022-02-14 09:50:41,989:DEBUG:certbot.log:Exiting abnormally:
Traceback (most recent call last):
File "/usr/bin/certbot", line 11, in
load_entry_point('certbot==0.40.0', 'console_scripts', 'certbot')()
File "/usr/lib/python3/dist-packages/certbot/main.py", line 1382, in main
return config.func(config, plugins)
File "/usr/lib/python3/dist-packages/certbot/main.py", line 1244, in certonly
installer, auth = plug_sel.choose_configurator_plugins(config, plugins, "certonly")
File "/usr/lib/python3/dist-packages/certbot/plugins/selection.py", line 235, in choose_configurator_plugins
diagnose_configurator_problem("authenticator", req_auth, plugins)
File "/usr/lib/python3/dist-packages/certbot/plugins/selection.py", line 339, in diagnose_configurator_problem
raise errors.PluginSelectionError(msg)
certbot.errors.PluginSelectionError: The requested apache plugin does not appear to be installed
2022-02-14 10:03:32,070:DEBUG:certbot.main:certbot version: 0.40.0
2022-02-14 10:03:32,071:DEBUG:certbot.main:Arguments: ['--apache']
2022-02-14 10:03:32,071:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#dns-ovh,PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2022-02-14 10:03:32,085:DEBUG:certbot.log:Root logging level set at 20
2022-02-14 10:03:32,085:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2022-02-14 10:03:32,086:DEBUG:certbot.plugins.selection:Requested authenticator apache and installer apache
2022-02-14 10:03:32,087:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 10:03:32,087:DEBUG:certbot.plugins.selection:No candidate plugin
2022-02-14 10:03:32,087:DEBUG:certbot.plugins.selection:Selected authenticator None and installer None
2022-02-14 10:03:32,087:INFO:certbot.main:Could not choose appropriate plugin: The requested apache plugin does not appear to be installed
2022-02-14 10:03:32,087:DEBUG:certbot.log:Exiting abnormally:
Traceback (most recent call last):
File "/usr/bin/certbot", line 11, in
load_entry_point('certbot==0.40.0', 'console_scripts', 'certbot')()
File "/usr/lib/python3/dist-packages/certbot/main.py", line 1382, in main
return config.func(config, plugins)
File "/usr/lib/python3/dist-packages/certbot/main.py", line 1244, in certonly
installer, auth = plug_sel.choose_configurator_plugins(config, plugins, "certonly")
File "/usr/lib/python3/dist-packages/certbot/plugins/selection.py", line 235, in choose_configurator_plugins
diagnose_configurator_problem("authenticator", req_auth, plugins)
File "/usr/lib/python3/dist-packages/certbot/plugins/selection.py", line 339, in diagnose_configurator_problem
raise errors.PluginSelectionError(msg)
certbot.errors.PluginSelectionError: The requested apache plugin does not appear to be installed

I run this command after to read the instructions (Certbot Instructions | Certbot)
before I had used the same instructions to install certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
ln: failed to create symbolic link '/usr/bin/certbot': File exists

Did you remove any older version of Certbot as instructed by the manual? Because the Certbot that is running now, is quite old:

Most definitely not the snap version.

snap run certbot were my answer

So running Certbot directly from snap works like a charm, as expected.

Nevertheless, you should look into older installed versions of Certbot. Maybe installed using apt? Or perhaps the ancient, deprecated certbot-auto script? I'm not sure how the cronjob or systemd timer installed by snap is running exactly. Maybe automated renewal is hampered by having older, non-functional Certbots laying around.

When found, please delete any non-snap Certbot version(s) and redo step 6 ("Prepare the Certbot command") of the Certbot instructions you and I both have linked above.

Thank you the problem is resolved