apache2ubuntu-22.04

how to create www-data:www-data


www-data is in /etc/group but not /etc/passwd. When I try to create a www-data user with

sudo adduser www-data

I get this message:

adduser: The group `www-data' already exists

This message doesn't make any sense. When I run

apache2ctl configtest

I get

chown: invalid user: 'www-data'

which also doesn't make sense. There is nothing in the apache error.log file. The apache envars file specifies that the user and group must be www-data:www-data, but Ubuntu will not let me make a user named www-data. I have tried different ways to do this, such as using the system Options dialog, useradd, usermod, etc., with no luck.

Apache2 will not run without www-data:www-data.

Any help, please.


Solution

  • As confusing as it might seem, you should use useradd instead of adduser

    useradd -g www-data --shell=/usr/sbin/nologin www-data
    

    This command will create an user named www-data and add it to the existing group named www-data.

    The adduser command is just a helper that will call useradd and a few more commands. Furthermore useradd won't create a /home/www-data folder, which would be unwanted.

    EDIT : adding the --shell prevents from directly logging in as www-data, as it must remain a system account.