2

I'm new to Apache2, so bear with me.

I followed this tutorial to get HTTPS working with a Flask server.

I keep getting the same output when I run the apache2 command:

[Wed Nov 28 01:42:32.210442 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Wed Nov 28 01:42:32.210921 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Wed Nov 28 01:42:32.211029 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Wed Nov 28 01:42:32.211138 2018] [core:warn] [pid 1184] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.219990 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
[Wed Nov 28 01:42:32.220662 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221009 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221106 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221304 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221421 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221710 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Wed Nov 28 01:42:32.221808 2018] [core:warn] [pid 1184:tid 139772922629056] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00543: apache2: bad user name ${APACHE_RUN_USER}

I've tried multiple other StackOverflow, AskUbuntu, and ServerFault questions, and none of them have helped. I'm stuck and I don't know what to do. I will edit the question to what is needed from other people (such as code or something from a conf file)

Any and all help is appreciated.

EDIT: I went to the unsecure (not-https) IP and I got the generic Apache "It works!" page. If I go to the secure (https) domain, I get a 500 Internal Server Error.

EDIT2: Here is my current VirtualHost file:

<VirtualHost *:80>
 ServerName xerix.me
 ServerAlias www.xerix.me
 ServerAdmin [email protected]
 WSGIScriptAlias / /var/www/cf/cf.wsgi
 <Directory /var/www/cf/cf/>
         Order allow,deny
         Allow from all
 </Directory>
 Alias /static /var/www/cf/cf/static
 <Directory /var/www/cf/cf/static/>
         Order allow,deny
         Allow from all
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error.log
 LogLevel warn
 CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =xerix.me [OR]
RewriteCond %{SERVER_NAME} =www.xerix.me
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

EDIT3:

Nov 28 01:50:34 xerix systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit apache2.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit apache2.service has begun starting up.
Nov 28 01:50:34 xerix systemd[1]: Started The Apache HTTP Server.
-- Subject: Unit apache2.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit apache2.service has finished starting up.
-- 
-- The start-up result is RESULT.

EDIT4:

[Wed Nov 28 02:43:15.319965 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218] Traceback (most recent call last):, referer: https://xerix.me/
[Wed Nov 28 02:43:15.320002 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218]   File "/var/www/cf/cf.wsgi", line 7, in <module>, referer: https://xerix.me/
[Wed Nov 28 02:43:15.320215 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218]     from cf import app as application, referer: https://xerix.me/
[Wed Nov 28 02:43:15.320252 2018] [wsgi:error] [pid 2078:tid 139635571181312] [client :40218] ImportError: cannot import name app, referer: https://xerix.me/

Thanks!

12
  • This Config variable ${APACHE_LOG_DIR} is not defined is the problem! Nov 28, 2018 at 1:52
  • 2
    For starters, please post the exact commands you ran and the output you got in the question (as text, instead of a video).
    – muru
    Nov 28, 2018 at 1:52
  • @GeorgeUdosen it is defined in the /etc/apache2/envvars file as APACHE_LOG_DIR=/var/log/apache2$SUFFIX. Nov 28, 2018 at 1:54
  • And is it readable by the apache process? Nov 28, 2018 at 1:56
  • 1
    wrong command do sudo systemctl start apache2 or sudo apche2ctl start Nov 28, 2018 at 2:11

1 Answer 1

0

It should be started as root using systemctl under Debian/Ubuntu.

It can also be started (system wide) using /etc/init.d/apache2 (AKA the older service command) under Debian/Ubuntu, but your best bet is using systemctl / systemd these days:

$ sudo systemctl start apache2.service

See the systemctl man page for more.

If you insist on running it as a non-root user, >at minimum< you need to source the environment first.

For instance:

$ source /etc/apache2/envvars
$ apache2 -V | grep -i 'version\|mpm'
Server version: Apache/2.4.29 (Ubuntu)
Server MPM:     event

# or one line:
$ source /etc/apache2/envvars && apache2 -V | grep -i 'version\|mpm'
Server version: Apache/2.4.29 (Ubuntu)
Server MPM:     event

Should give you proper output (shows version and MPM running).

Sourcing the Apache variables before running the command allows proper reading/writing/parsing of needed Apache file/dir location data.

NOTE: Most flags such as apache2 -M (module list) will parse the Apache configuration file and site file(s). If a file/folder is read restricted to root, then you will get an error running as non-root. You will need to use the Apache variables along with the sudo command. (-V does not parse configs - normal user works fine normally). See comments and https://serverfault.com/a/416613/92023

NOTE: You must run as root user for web service on port 80/443. Please refer to this answer for the why.

Starting it as a daemon/web service (as root user without init script) using the apache2 command should also work as long as current running environment is sourced first. I can't think of a good reason to ever do this. Starting it as a background service using systemctl avoids all this.

4
  • Man, I can't believe this! I was getting the error trying to list the loaded modules with sudo apache2 -M and it drove me crazy all day. I finally removed sudo and it works again. Who would have thought that something that important like Apache does not need sudo...
    – Andyc
    Jul 26, 2021 at 17:55
  • @Andyc - source /etc/apache2/envvars && sudo -E apache2 -M will work on most systems. Or, better: Use apache2ctl instead: source /etc/apache2/envvars && sudo -E apache2ctl -M. Why? If you query apache2 directly or use apache2ctl, you must load the Apache environmental variables. "sudo -E" uses the logged in user's environment. You load the Apache variables as a logged in user and use them to when executing sudo. You may not need to source the variables for apache2ctl to work. It doesn't hurt, though.
    – B. Shea
    Jul 28, 2021 at 14:55
  • thank you. It works fine indeed. Actually I have no real reason to do it with sudo, as long as I get the information about the loaded modules. I just thought I would have to because apache is not my process and I was assuming one needs sudo for that.
    – Andyc
    Jul 29, 2021 at 10:27
  • 1
    @Andyc The user you are logged in as must have sourced the needed variables somehow. Either of those commands above should work fine without SUDO assuming 2 things: the Apache variables are loaded/sourced in AND there is nothing in your apache2 configuration that is read restricted by the given user (such as root owned/read-only SSL directories/files inside a site config). Else you get things like this: SSLCertificateFile: file '/etc/letsencrypt/live/example.com/cert.pem' does not exist or is empty (then it exits) (That file does exist - just cannot be read by normal user.)
    – B. Shea
    Jul 29, 2021 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .