Unable to install certificate via PHP

I am trying to use the PHP exec function to generate a certificate dynamically.

I ran this command:
exec("certbot certonly --webroot -w /var/www/html/mysite/ -d mydomain.com 2>&1", $output);

It produced this error:
Either run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.

So I tried the following instead:
exec("certbot certonly --webroot -w /var/www/html/mysite -d mydomain.com --config-dir /var/www/html/sslconfig 2>&1", $output);

Where sslconfig is a writeable path.

It gives me the same output

My web server is: NGINX

The operating system my web server runs on is: Ubuntu 18.04

What is the correct way to use --config-dir when?

1 Like

The error message sums up three paths with the word “and”. So just setting --config-dir isn’t enough. The other two paths also need to be directories writable by the user running certbot.

1 Like

Tried that aswell but got the same error:

exec("certbot certonly --webroot -w /var/www/html/mysite -d mydomain.com --config-dir /var/www/html/sslconfig --work-dir /var/www/html/sslconfig --logs-dir /var/www/html/sslconfig");

Will try it out with different directories:

edit - same error again

1 Like

What are the rights of those directories? (I.e., the output of ls -l.)

1 Like

sslconfig:
— one
— two
— three

They all have Chmod permissions of 775.

ls -l returns Total 0 as they are empty directories

The error I receive is this:

Either run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.

1 Like

You could of course run ls -l on the parent directory to list the rights, so you can paste them here. Or add -d to the command to list a directory seperately.

For example, I’m not sure if 775 is sufficient. That depends on the user and group of the directories.

2 Likes

Changed to 777 and it works now, thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.