Unable to start httpd service on Centos 7 "GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject" - apache

When trying to (re)start httpd service I get the following error:
** (pkttyagent:2574): WARNING **: 01:33:55.345: Unable to register authentication agent:
GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject Error registering authentication agent:
GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject (polkit-error-quark, 0) Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
Then
systemctl status httpd.service
sheds no light on the problem:
httpd.service - Web server Apache
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2020-07-22 01:33:55 BST; 26min ago
Process: 2578 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, status=1/FAILURE)
Jul 22 01:33:55 server... systemd[1]: Starting Web server Apache...
Jul 22 01:33:55 server... systemd[1]: httpd.service: control process exited, code=exited status=1
Jul 22 01:33:55 server... systemd[1]: Failed to start Web server Apache.
Jul 22 01:33:55 server... systemd[1]: Unit httpd.service entered failed state.
Jul 22 01:33:55 server... systemd[1]: httpd.service failed.
What might be causing this? Where should I look to debug?

[Thu Jul 23 05:40:44.885963 2020] [ssl:emerg] [pid 2877:tid 140514669713280] AH02565: Certificate and private key do not match
Looks like key and certificate do not match. Please check md5 of the key and cert file.

This usually happens when trying to restart a systemd service.
The workaround is as follows:
Run this as root
groupadd -g 23 nohidproc
usermod -a -G nohidproc polkitd
mount -o remount,rw,hidepid=2,gid=nohidproc /proc
systemctl restart polkit

Related

Apache2 crash on boot, but not when started manually

I got a wired problem that I don't understand at all:
I have a home server with an Apache2 installation on Ubuntu 18.04. My problem is that Apache2 keeps crashing on system reboot.
systemctl status apache2 gives me:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit-code) since Sat 2020-05-23 13:42:31 CEST; 3min 52s ago
Process: 1183 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 1224 (code=exited, status=1/FAILURE)
mai 23 13:42:30 potato-server systemd[1]: Starting The Apache HTTP Server...
mai 23 13:42:30 potato-server systemd[1]: Started The Apache HTTP Server.
mai 23 13:42:31 potato-server systemd[1]: apache2.service: Main process exited, code=exited, status=1/FAILURE
mai 23 13:42:31 potato-server systemd[1]: apache2.service: Failed with result 'exit-code'.
What's super weird is that when I do a manual sudo systemctl start apache2, the server starts. And apache2ctl configtest gives me:
Syntax OK
Any idea of where the problem can come from?
I got some updates:
It seems that my bug is due to that fact I changed the group and user of Apache2 in /etc/apache2/envvar, according to this post: https://www.simplified.guide/apache/change-user-and-group
If I change back user and user group to www-data, it works again. However I would like to run Apache2 from an other user than www-data. Is this possible ?

Apache won't start in CentOS 7 due to missing SSLCertificateFile

Apache does not start after installing the web server. (CentOS 7)
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2020-03-28 12:18:22 MSK; 16ms ago
Docs: man:httpd.service(8)
Process: 30144 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 30144 (code=exited, status=1/FAILURE)
Status: "Reading configuration..."
Mar 28 12:18:22 box-40395.localdomain systemd[1]: Starting The Apache HTTP Server...
Mar 28 12:18:22 box-40395.localdomain httpd[30144]: AH00526: Syntax error on line 103 of /etc/httpd/conf.d/ssl.conf:
Mar 28 12:18:22 box-40395.localdomain httpd[30144]: SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty
Mar 28 12:18:22 box-40395.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Mar 28 12:18:22 box-40395.localdomain systemd[1]: Failed to start The Apache HTTP Server.
Mar 28 12:18:22 box-40395.localdomain systemd[1]: Unit httpd.service entered failed state.
Mar 28 12:18:22 box-40395.localdomain systemd[1]: httpd.service failed.
You could try by creating a fake certificate.
In centos there is a handy script which might help
$ cd /etc/pki/tls/certs
$ sudo ./make-dummy-cert localhost.crt
This script produces a self-signed certificate and the certificate's private key.
Therefore SSLCertificateKeyFile in /etc/httpd/conf.d/ssl.conf could be commented out
SLCertificateFile /etc/pki/tls/certs/localhost.crt
# SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
Otherwise service won't start
The error message is very clear:
SSLCertificateFile: file /etc/pki/tls/certs/localhost.crt does not exist or is empty
Remove this invalid configuration or add missing/fix existing certificate file. Either way to have to fix the configuration before Apache can start.
Obtaining an SSL certificate is out of the scope for StackOverflow. There're plenty of resources on the web, you can try on ServerFault too…
When you're done, simply sudo systemctl start httpd to start Apache.

Apache Won't Start after Adding SSL Certificates

Hello so here is the problem
I have generated CSR on CentOS and purchased SSL on Comodo.
I have added following lines to ssl.conf
ServerName mydomain.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/certs/mydomain.key
SSLCertificateFile /etc/pki/tls/certs/mydomain.crt
SSLCACertificateFile /etc/pki/tls/certs/mydomainCA.crt
and following lines to httpd.conf
<VirtualHost *:80>
ServerName thedomain.com
Redirect "/" "https://thedomain.com/"
</VirtualHost>
After this when I do systemctl restart httpd it gives me following error:
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl
-xe" for details.
and when I check journalctl -xe for details this is what it reads:
-- Subject: Unit httpd.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit httpd.service has finished starting up.
-- The start-up result is done. Nov 24 18:36:01 MyWay polkitd[568]: Unregistered Authentication Agent for unix-process:6639:684652621
(system bus name :1.4409, object path
/org/freedesktop/PolicyKit1/AuthenticationAgent, locale e Nov 24
18:36:04 MyWay sshd[6652]: Invalid user oracle from 80.241.211.237
port 54600 Nov 24 18:36:04 MyWay sshd[6652]: input_userauth_request:
invalid user oracle [preauth] Nov 24 18:36:04 MyWay sshd[6652]:
pam_unix(sshd:auth): check pass; user unknown Nov 24 18:36:04 MyWay
sshd[6652]: pam_unix(sshd:auth): authentication failure; logname=
uid=0 euid=0 tty=ssh ruser= rhost=vmi306916.contaboserver.net Nov 24
18:36:06 MyWay sshd[6652]: Failed password for invalid user oracle
from 80.241.211.237 port 54600 ssh2 Nov 24 18:36:06 MyWay sshd[6652]:
Received disconnect from 80.241.211.237 port 54600:11: Normal
Shutdown, Thank you for playing [preauth] Nov 24 18:36:06 MyWay
sshd[6652]: Disconnected from 80.241.211.237 port 54600 [preauth] Nov
24 18:36:16 MyWay sshd[6651]: Received disconnect from 112.85.42.94
port 31545:11: [preauth] Nov 24 18:36:16 MyWay sshd[6651]:
Disconnected from 112.85.42.94 port 31545 [preauth] Nov 24 18:36:18
MyWay polkitd[568]: Registered Authentication Agent for
unix-process:6655:684654361 (system bus name :1.4410
[/usr/bin/pkttyagent --notify-fd 5 --fallback], object path
/org/freedes Nov 24 18:36:18 MyWay systemd[1]: Stopping The Apache
HTTP Server...
-- Subject: Unit httpd.service has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit httpd.service has begun shutting down. Nov 24 18:36:19 MyWay systemd[1]: Stopped The Apache HTTP Server.
-- Subject: Unit httpd.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit httpd.service has finished shutting down. Nov 24 18:36:19 MyWay systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit httpd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit httpd.service has begun starting up. Nov 24 18:36:19 MyWay systemd[1]: httpd.service: main process exited, code=exited,
status=1/FAILURE Nov 24 18:36:19 MyWay kill[6667]: kill: cannot find
process "" Nov 24 18:36:19 MyWay systemd[1]: httpd.service: control
process exited, code=exited status=1 Nov 24 18:36:19 MyWay systemd[1]:
Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Unit httpd.service has failed.
-- The result is failed. Nov 24 18:36:19 MyWay systemd[1]: Unit httpd.service entered failed state. Nov 24 18:36:19 MyWay systemd[1]:
httpd.service failed. Nov 24 18:36:19 MyWay polkitd[568]: Unregistered
Authentication Agent for unix-process:6655:684654361 (system bus name
:1.4410, object path /org/freedesktop/PolicyKit1/AuthenticationAgent,
locale e [
So I have checked lot os solutions but this problems still exists, please note that when I comment out all changes in httpd.conf and ssl.conf apache starts working back normally.
Thanks all in advance
SOLVED
Renaming file to PEM helped the case, besides this I came across some other issues that were causing error ( looking ata apache logs helped me to solv them )
Memory for apache was full so I had to increase it.
I had duplicated SSLCertificateKeyFile in the ssl.conf file and I commented out the default file link.

How to solve error restarting apache Ubuntu

Question originally posted in Spanish, on es.stackoverflow.com, by mnsperez97:
I have a problem with the connection to Apache, after restarting it
with the sudo service apache2 restart command, I get this error
Job for apache2.service failed because the control process exited with
error code. See "systemctl status apache2.service" and "journalctl
-xe" for details.
and then when entering localhost it does not let me in and it makes me
worse, when I run sudo journalctl -xe he told me the following but
still I do not find the error, if you could help me I would be very
grateful
EDIT: run the systemctl status apache2.service command and this
appears to me
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit-code) since Thu 2019-10-17 12:20:34 -04; 29min ago
Process: 21198 ExecStop=/usr/sbin/apachectl stop (code=exited, status=1/FAILURE)
Process: 7385 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Process: 23453 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
Main PID: 1059 (code=exited, status=0/SUCCESS)
oct 17 12:20:34 pcarrasco systemd[1]: Starting The Apache HTTP Server...
oct 17 12:20:34 pcarrasco apachectl[23453]: AH00526: Syntax error on line 47 of /etc/apache2/sites-enabled/cms.local.conf:
oct 17 12:20:34 pcarrasco apachectl[23453]: order takes one argument, 'allow,deny', 'deny,allow', or 'mutual-failure'
oct 17 12:20:34 pcarrasco apachectl[23453]: Action 'start' failed.
oct 17 12:20:34 pcarrasco apachectl[23453]: The Apache error log may have more information.
oct 17 12:20:34 pcarrasco systemd[1]: apache2.service: Control process exited, code=exited status=1
oct 17 12:20:34 pcarrasco systemd[1]: apache2.service: Failed with result 'exit-code'.
oct 17 12:20:34 pcarrasco systemd[1]: Failed to start The Apache HTTP Server.
This is common due to problems in your configuration
it may be the port configuration
lock at the log file (pass can be found as ErrorLog in /etc/httpd/conf/httpd.conf)
or try to undo what you changed in the configuration files till you find the problem

apache2.service: Failed to run 'start' task: No such file or directory

I can't start my apache server on debian 9.
I tried reinstall :
sudo apt-get autoremove --purge apache2 && sudo apt-get install apache2
but no change...
Job for apache2.service failed because of unavailable resources or another system error.
See "systemctl status apache2.service" and "journalctl -xe" for details.
invoke-rc.d: initscript apache2, action "restart" failed.
systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: resources)
journalctl -xeu apache2.service
(I set loglevel to debug mod)
Sep 05 11:45:44 systemd[1]: apache2.service: Failed with result 'resources'.
Sep 05 11:50:26 systemd[1]: apache2.service: Changed dead -> failed
Sep 05 11:50:27 systemd[1]: apache2.service: Trying to enqueue job apache2.service/stop/replace
Sep 05 11:50:27 systemd[1]: apache2.service: Installed new job apache2.service/stop as 1415
Sep 05 11:50:27 systemd[1]: apache2.service: Enqueued job apache2.service/stop as 1415
Sep 05 11:50:27 systemd[1]: apache2.service: Job apache2.service/stop finished, result=done
Sep 05 11:50:27 systemd[1]: apache2.service: Changed dead -> failed
Sep 05 11:50:30 systemd[1]: apache2.service: Failed to run 'start' task: No such file or directory
Sep 05 11:50:30 systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit apache2.service has failed.
--
-- The result is failed.
Sep 05 11:50:30 systemd[1]: apache2.service: Failed with result 'resources'.
what's wrong?
Maybe this is a problem with service 'tmp' directory. I has a similar error with systemd-resolved.service, and reason was missing '/var/tmp' directory after system migration. Check what temp directory the service is using and create it if necessary.
Also, if there is systemd newly running and crap in /var/tmp/, you might have to clear up this crap and try running the service again.
In my case it turned out to be this (without apache2 running at the time):
root#www:/var/tmp # ls -al
total 32
drwxrwxrwt 8 root root 4096 Dec 15 12:48 .
drwxr-xr-x 14 root root 4096 Jul 8 21:43 ..
drwx------ 2 root root 4096 Dec 15 12:48 systemd-private-1dcdfe608b6c41f387936225d86126c7-apache2.service-L0KeaS
drwx------ 2 root root 4096 Dec 8 03:09 systemd-private-39294ac7bf4b44198d87d45660dcbac2-phpsessionclean.service-4ShLZm
drwx------ 2 root root 4096 Dec 15 04:00 systemd-private-451ad0c3bfe6435891a80a6c714a222b-apache2.service-YQyZes
drwx------ 2 root root 4096 Dec 15 07:09 systemd-private-451ad0c3bfe6435891a80a6c714a222b-phpsessionclean.service-5L25TU
drwx------ 3 root root 4096 Dec 15 03:53 systemd-private-68bc1493e8804c968af642a2319c4e79-apache2.service-RY1iLF