skip to Main Content

I want to check the content of apachectl configtest from within PHP, but the below code returns an error, yet running it via command line says it is OK.

This code:

$output = shell_exec('/usr/sbin/apachectl configtest');
echo $output;

Give this:

Action 'configtest' failed.
The Apache error log may have more information.

But running it directly like this:

user@server:~# /usr/sbin/apachectl configtest

Give this:

Syntax OK

Any idea why?

Thanks.

Update : I checked the error and it says this:

AH00526: Syntax error on line 17 of /etc/apache2/sites-enabled/000-default-le-ssl.conf:
SSLCertificateFile: file '/etc/letsencrypt/live/server/fullchain.pem' does not exist or is empty

But that file does exist (well, it’s a symlink) and the command works via command line.

2

Answers


  1. Chosen as BEST ANSWER

    Ahhh, my bad, I was trying to access it externally and it didn't work, but when I ran it as a php via command line script it did, so it didn't really matter anyway. Leaving here as it may help somewone.


  2. This could be because the user executing PHP doesn’t have permissions to access the certificate file but the user in the command line does. In a similar setup, I’ve run into an error when running [apache] configtest but not with sudo [apache] configtest (running the same command as a superuser), since the superuser can see the certificate.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search