Enable Apache Userdir on Ubuntu 26.04
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).
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.
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.
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
sudorights (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
systemctlreports an error on an older install, usesudo service apache2 restartwherever this guide says to restart Apache.
Enable Userdir in Apache2
Check that Apache2 is installed and running
- Open your Ubuntu terminal.
- Install Apache2 if you have not already. This step needs sudo:Bash / Shell
sudo apt update
sudo apt install apache2 - Check the service status:You should seeCode
systemctl status apache2
active (running)in green. Press Q to leave the status screen.
Turn on the userdir module
- Enable the module. This step needs sudo:Ubuntu prints a message saying the module is enabled and asks you to restart Apache.Bash / Shell
sudo a2enmod userdir
- Restart Apache so it loads the module. This step needs sudo:Bash / Shell
sudo systemctl restart apache2
Create the public_html folder
- Sign in as the user who will publish the pages. Do not use
sudofor the next steps, so the files belong to that user. - Create the folder in your home directory:Code
mkdir ~/public_html
- Create a test page:The file now exists atCommand Prompt
echo "Userdir is working" > ~/public_html/index.html
~/public_html/index.html.
Set the folder permissions
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.
- Allow other users to pass through your home directory without listing its contents:Bash / Shell
chmod 711 ~
- Make the
public_htmlfolder readable and enterable:Bash / Shellchmod 755 ~/public_html
- Make the test page readable:Bash / Shell
chmod 644 ~/public_html/index.html
Test the page from Windows
- Open a browser on Windows 11, such as Microsoft Edge.
- Type the address below in the address bar. Replace
USERNAMEwith your Linux username:Codehttp://localhost/~USERNAME/
- Press Enter. The page should show
Userdir is working. - If Apache runs on another machine, replace
localhostwith that machine’s IP address, for examplehttp://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.
- Open the file in the Nano text editor. This step needs sudo:Bash / Shell
sudo nano /etc/apache2/mods-available/userdir.conf
- Find the
UserDirlines. By default,UserDir public_htmlsets the folder name, andUserDir disabled rootblocks the root account from publishing. - Edit the values you need. For example, change
public_htmlto another folder name. Use that name when you create the folder in each home directory. - Press Ctrl+O, then Enter to save. Press Ctrl+X to exit.
- Check the configuration for errors before you apply it:The output should end withBash / Shell
sudo apache2ctl configtest
Syntax OK. - 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:
- Run
ls -ld ~ ~/public_htmland confirm the home directory allows execute for others (for exampledrwx--x--x). - Confirm
public_htmland the files in it are readable by others. - 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
- Check that the module is on:You should seeCode
apache2ctl -M | grep userdir
userdir_modulein the output. If nothing appears, repeat the enable and restart steps. - Check the URL. The tilde (
~) must come directly before the username, with no space. - Check that the folder is named
public_htmland sits directly inside the home directory.
Security notes
- Opening your home directory with
chmod 711lets 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 aschmod 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
- Disable the module. This step needs sudo:Bash / Shell
sudo a2dismod userdir
- Restart Apache. This step needs sudo:Bash / Shell
sudo systemctl restart apache2
- 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?
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.
No comments yet — be the first to share your thoughts!