Skip to content
Follow
Ubuntu Linux

Enable Apache Userdir on Ubuntu 24.04

Richard
Written by
Richard
Feb 19, 2025 Updated Oct 13, 2026 4 min read
Enable Apache Userdir on Ubuntu 24.04
Enable Apache Userdir on Ubuntu 24.04

Apache Userdir is a module for the Apache web server on Ubuntu 24.04 that lets you host a personal website straight from your home folder. Visitors reach it with a web address like yourserver.com/~yourusername.

Advertisement

The module serves any web pages you put inside a public_html folder in your user account. Each user on the server can have their own folder and their own address, so you never edit the main server configuration to publish a page.

Sharing files or running a small personal site this way takes a few quick steps. You need a user account with sudo rights and a terminal. Apache 2.4 is the version that ships with Ubuntu 24.04, and the steps below apply to it.

⚡ Quick Answer

Enable Apache Userdir on Ubuntu 24.04 by running sudo a2enmod userdir, then sudo systemctl restart apache2. Create a public_html folder in your home directory with mkdir ~/public_html, set its permissions with chmod 711 $HOME and chmod 755 ~/public_html, and add an index.html file. Then open http://localhost/~yourusername/ in your browser.

Advertisement

Enable Userdir

Start by installing Apache. Without it there is no web server to enable Userdir on. Run the command below. If Apache is already installed, the command simply reports that and changes nothing, so it is safe to run again.

🐧Bash / Shell
sudo a2enmod userdir

Restart Apache so it reads the new configuration. The restart applies the changes immediately. If you restarted before enabling the Userdir module, restart once more afterwards, because Apache only loads modules when it starts. The restart prints nothing when it works. If you see an error instead, check the message it gives, which usually names the file and line that caused the problem.

🐧Bash / Shell
sudo systemctl restart apache2

Enable the Userdir module with the command above. The terminal should print a short message saying the module is being enabled and that Apache needs a restart to activate it. That is normal. Enabling the module completes the main configuration. To undo it later, disable the module the same way you enabled it and restart Apache.

Advertisement

Test Apache Userdir

⚠️WarningNext, test that personal web pages work.

You will create a public folder in your home directory, set the correct file permissions, and add a simple test page. Then you will view the page in your browser. Run these commands as the user whose page you want to publish, not as root. Otherwise the folder ends up owned by root and your own account cannot edit it.

First, create the public_html document root in your home directory. The name must match exactly, including the lowercase letters and the underscore, because that is the folder Apache looks for. The command prints nothing when it succeeds.

💻Code
mkdir ~/public_html

Next, secure the new folder by updating its permissions. Apache runs as its own user, www-data, so it must be able to enter your folders and read the files inside them. It does not need to write to them. Ubuntu 24.04 makes home directories private by default, which can block Apache even when public_html is set correctly. If the page later shows 403 Forbidden, check that Apache's user can pass through your home folder as well as public_html.

🐧Bash / Shell
chmod 711 $HOME && chmod 755 ~/public_html

Now add a basic HTML index.html file with the command above. It opens a text editor on a new, empty file inside public_html. Apache serves index.html by default when someone visits your address without naming a file.

Advertisement
💻Code
nano ~/public_html/index.html

Type or paste the lines below into the file to fill in the page content. Any short HTML works here. The goal is to see something recognisable in the browser.

💻Code
<html>
<title>My basic HTML page</title>
<body>
<p style="width: 100%; font-weight: bold; font-size: 60px; text-align: center;">
UserDir is enabled!
</p>
</body>
</html>

Save the file and exit the editor. This finishes creating the file. If you can't tell whether it saved, list the contents of public_html and check that index.html is there.

Once the module is active, web browsers can display files from your home directory. Follow these steps to load your page:

  1. Open a web browser on any computer that can reach the server.
  2. Enter http://localhost/~yourusername/yourfile.html in the address bar. This loads specific files such as index.html.
  3. Replace yourusername with an actual Ubuntu username and yourfile.html with the target file name so the URL resolves properly.

You should now see the test page you wrote. If you get 404 Not Found, check the username and file name for typos. If you get 403 Forbidden, recheck the permissions step above.

Advertisement
💻Code
http://example.com/~richard/

To open the page, put the ~username part after the server hostname or IP address. The tilde (~) is required, and it comes before the username with no space. On the server itself you can use localhost as the hostname. From another machine, use the server's IP address or its domain name.

Apache Userdir feature enabled on Ubuntu 24.04
Apache Userdir feature enabled on Ubuntu 24.04
⚠️WarningThat completes the setup.

Anything you place in public_html is now public, so keep private files out of that folder.

Conclusion:

Web pages on Ubuntu 24.04 are now accessible through Apache's Userdir feature. Keep these key takeaways in mind:

  • User Empowerment: Users can host web content directly from their home directories without server administration.
  • Easy Access: With a simple URL format, files become accessible online.
  • Quick Setup: Enabling Userdir is straightforward, requiring just a few commands in the terminal.
  • Secure Configuration: Setting appropriate permissions ensures that directories are safe while allowing public access.
  • Test Your Setup: Creating and viewing a basic HTML page is a simple test to confirm that the Userdir feature functions correctly.

With these steps done, every user on the server can publish their own pages from a public_html folder. Add more pages to that folder as you need them, and keep the permissions as tight as the setup allows.

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

1 Comment

Leave a Comment

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