8

I am getting this error trying to restart Apache, does anyone know how to fix this? Thanks,

  • 1
    what command did you try to restart apache ? – sagarchalise May 4 '12 at 5:34
  • Are you using sudo apache2? Try apache2ctl instead. See this answer: askubuntu.com/a/147065/56343 – XåpplI'-I0llwlg'I - May 8 '13 at 6:03
  • 1
    do a source envvars & then run your command. – user160453 May 21 '13 at 1:15
9

To fix this problem, you have to make the changes to two separate files.

First, edit /etc/apache2/apache2.conf, adding these lines:

User www-data
Group www-data

Second, edit /etc/apache2/envvars, adding these lines:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
  • 3
    The first block can probably keep referencing the environment variables; the crucial step is defining them in /etc/apache2/envvars! – Ingo Karkat Jul 30 '13 at 9:23
  • Actually, my environment variables (Ubuntu 12 VPS which I don't have a lot of control over) were set up correctly and were not referenced. The User www-data is the fix that worked for me. – Daniel Chapman Jan 6 '14 at 0:51
5

This will set your apache2 ENV vars for the current session and allow you to use the apache2 binary without modifying your config:

source /etc/apache2/envvars

/etc/apache2/envvars

Is simply a script that sets some environment variables. When you use apachectl it processes this before launching apache2 itself. If you want to invoke apache2 from the terminal, you'll need those vars as well.

So invoking source /etc/apache2/envvars sets up the variables allowing apache2 to work outside of apachectl.

You could potentially set these up in a number of other ways. E.g. invoke envvars when you login.

  • /etc/apache2/envvars simply sets some environment variables. When you use apachectl it processes this before launching apache2 itself. If you want to invoke apache2 from the terminal, you'll need those vars as well. So invoking source /etc/apache2/envvars sets up the variables allowing apache2 to work outside of apachectl. – Henry Sep 23 '14 at 5:30
3

In my case, by restarting the machine the error went away (I had just installed apache2) and I was able to issue the command sudo /etc/init.d/apache2 restart and have apache2 restart.

2

A temporary fix (that I used) was to edit the file in /etc/apache2/apache2.conf. Look for this:

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

and change it to this:

User www-data
Group www-data

For whatever reason, apache2 isn't looking in envvars to get the appropriate environment variables. The real answer to why this is happening is to track down why envvars isn't being consulted.

  • Probably an upgrade that did not affect configuration. /etc/init.d/apache2 is supposed to load this variable. You can manually extract the conffile from a deb file and replace it. – Lekensteyn Jun 5 '12 at 8:17
  • Really? What does your /etc/apach2/apache2.conf say around line 144? I'm wondering what it has for User and Group. This seems bizarre to me because envvars defines it and its right next to apache2.conf. – Avery Chan Jun 5 '12 at 8:25
  • Use apt-get download apache2.2-common and dpkg -x apache2.2-common*.deb fs to extract files to a directory called fs. You can then check it yourself. (this is at least the case with Oneiric and Precise) – Lekensteyn Jun 5 '12 at 8:51
  • This worked for me – Testo Testini Mar 19 '16 at 8:55
1

Got this when I tried sudo /usr/sbin/apache2 -k restart.
Actually apache2 in /usr/sbin was link to shared library '/lib/apache2/mpm-worker/apache2'
Instead sudo /etc/init.d/apache2 restart should be used as mentioned.

1

I got the same error when trying to run apache2 -M also.

I ended up just sourcing the envars file like this:

. /etc/apache2/envvars

That set the environment variable properly since running apache2 outside of the standard init script.

0

When I ran apache2 -M I got the same error. Found this solution:

groupadd sshusers

I have no idea why this fixed it, but it did.

0

manually edit /etc/group and add www-data there then start apache

add www-data:x:1012:www-data at end of file and save it Ctrl-X Yes {enter} (1011 was last num in my group file)

start apache sudo service apache2 start

it worked in my case

0

I had the sane problem and checked apache2ctl status and it said I needed to configure www-browser or adjust apache_lynx

My shell told me to install lynx, so I did, and that solved it for me.

sudo apt-get install lynx

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.