Skip to content
Follow
Ubuntu Linux 🟡 Intermediate

Enable Apache Userdir on Ubuntu 26.04

Richard
Written by
Richard
5 min read
An Ubuntu Linux desktop with a dark terminal window and a web browser showing a page, illustrating how to enable Apache Userdir.
An Ubuntu Linux desktop with a dark terminal window and a web browser showing a page, illustrating how to enable Apache Userdir.

To turn on per-user web folders in Apache2 on Ubuntu, run sudo a2enmod userdir, restart Apache, then put your files in a public_html folder inside your home directory. After that, the site loads at http://localhost/~USERNAME/. This guide assumes Apache2 is already running on Ubuntu. If you work from Windows 11, the Ubuntu instance can be a WSL (Windows Subsystem for Linux) distribution, a virtual machine, or a remote server you reach over SSH (a secure way to log in to another computer).

Advertisement
⚡ Quick Answer

To enable Apache userdir on Ubuntu 26.04, run sudo a2enmod userdir, then restart Apache with sudo systemctl restart apache2. Create a public_html folder in your home directory and put your files there. Then open http://localhost/~USERNAME/ in a browser, replacing USERNAME with your Linux username. Set home directory permissions to 711 with chmod 711 ~ if you get a 403 error.

Advertisement

What the Userdir module does

The Userdir module (mod_userdir) lets each Linux user publish web pages from a folder in their own home directory. The folder is called public_html. Apache maps it to a URL that starts with a tilde (the ~ character), such as /~USERNAME/. Users can then publish pages without touching the main web root at /var/www/html.

📝Good to KnowThis suits shared lab machines, teaching setups and personal test servers.

It is less suited to a public server, because it exposes part of every user’s home directory to the web server. Read the security notes below before you enable it on a machine that other people can reach.

Before you start

  • You need a user account with sudo rights (administrator rights on Ubuntu). Every step marked sudo (a command that runs with administrator rights) needs them.
  • Apache2 must be installed and running. Step 1 below checks this.
  • On WSL, use the Ubuntu app or open Windows Terminal and choose the Ubuntu profile. Recent WSL versions run systemd (the Linux service manager) by default on new installs. If systemctl reports an error on an older install, use sudo service apache2 restart wherever this guide says to restart Apache.

Enable Userdir in Apache2

Check that Apache2 is installed and running

  1. Open your Ubuntu terminal.
  2. Install Apache2 if you have not already. This step needs sudo:
    🐧Bash / Shell
    sudo apt update
    sudo apt install apache2
  3. Check the service status:
    💻Code
    systemctl status apache2
    You should see active (running) in green. Press Q to leave the status screen.

Turn on the userdir module

  1. Enable the module. This step needs sudo:
    🐧Bash / Shell
    sudo a2enmod userdir
    Ubuntu prints a message saying the module is enabled and asks you to restart Apache.
  2. Restart Apache so it loads the module. This step needs sudo:
    🐧Bash / Shell
    sudo systemctl restart apache2

Create the public_html folder

  1. Sign in as the user who will publish the pages. Do not use sudo for the next steps, so the files belong to that user.
  2. Create the folder in your home directory:
    💻Code
    mkdir ~/public_html
  3. Create a test page:
    ⬛Command Prompt
    echo "Userdir is working" > ~/public_html/index.html
    The file now exists at ~/public_html/index.html.

Set the folder permissions

📝Good to KnowApache runs as the www-data user.

It needs permission to pass through your home directory and read the files in public_html. On current Ubuntu releases, home directories are private by default, so the page fails with a 403 error until you adjust this.

  1. Allow other users to pass through your home directory without listing its contents:
    🐧Bash / Shell
    chmod 711 ~
  2. Make the public_html folder readable and enterable:
    🐧Bash / Shell
    chmod 755 ~/public_html
  3. Make the test page readable:
    🐧Bash / Shell
    chmod 644 ~/public_html/index.html

Test the page from Windows

  1. Open a browser on Windows 11, such as Microsoft Edge.
  2. Type the address below in the address bar. Replace USERNAME with your Linux username:
    💻Code
    http://localhost/~USERNAME/
  3. Press Enter. The page should show Userdir is working.
  4. If Apache runs on another machine, replace localhost with that machine’s IP address, for example http://192.0.2.10/~USERNAME/.

Change the default Userdir settings

The defaults work for most setups. To change the folder name or what users can do in it, edit the module’s configuration file.

  1. Open the file in the Nano text editor. This step needs sudo:
    🐧Bash / Shell
    sudo nano /etc/apache2/mods-available/userdir.conf
  2. Find the UserDir lines. By default, UserDir public_html sets the folder name, and UserDir disabled root blocks the root account from publishing.
  3. Edit the values you need. For example, change public_html to another folder name. Use that name when you create the folder in each home directory.
  4. Press Ctrl+O, then Enter to save. Press Ctrl+X to exit.
  5. Check the configuration for errors before you apply it:
    🐧Bash / Shell
    sudo apache2ctl configtest
    The output should end with Syntax OK.
  6. Restart Apache:
    🐧Bash / Shell
    sudo systemctl restart apache2

Fix common errors

403 Forbidden

This is the most common problem. Apache cannot read something along the path. Check these items in order:

Advertisement
  1. Run ls -ld ~ ~/public_html and confirm the home directory allows execute for others (for example drwx--x--x).
  2. Confirm public_html and the files in it are readable by others.
  3. Open the Apache error log (the file where Apache records problems) and read the newest lines to find the exact reason:
    🐧Bash / Shell
    sudo tail -n 20 /var/log/apache2/error.log

404 Not Found

  1. Check that the module is on:
    💻Code
    apache2ctl -M | grep userdir
    You should see userdir_module in the output. If nothing appears, repeat the enable and restart steps.
  2. Check the URL. The tilde (~) must come directly before the username, with no space.
  3. Check that the folder is named public_html and sits directly inside the home directory.

Security notes

  • Opening your home directory with chmod 711 lets other accounts on the machine pass through it. They still cannot list your files, but they can open a file if they know its exact name. Keep private files in a subfolder with tighter permissions, such as chmod 700.
  • Do not enable Userdir on an internet-facing server unless you need it. Each account becomes a public web location.
  • Do not leave passwords, keys or backups inside public_html. Anyone who can reach the server can request them.

Turn Userdir off again

  1. Disable the module. This step needs sudo:
    🐧Bash / Shell
    sudo a2dismod userdir
  2. Restart Apache. This step needs sudo:
    🐧Bash / Shell
    sudo systemctl restart apache2
  3. Optionally, restore your home directory's privacy:
    🐧Bash / Shell
    chmod 750 ~

Your public_html folder and its files stay in place. Only the web mapping goes away.

What to do next

If the page still does not load, the error log from the 403 section usually names the exact file or folder at fault. Once static pages work, the next step is running scripts from public_html. Ubuntu's PHP configuration disables PHP in user directories by default, so check that before you expect .php files to run.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *