Close Menu
    Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»General Articles»Configuring Apache Userdir on Ubuntu and Debian: A Simplified Guide

    Configuring Apache Userdir on Ubuntu and Debian: A Simplified Guide

    By RahulMay 26, 20233 Mins Read

    Apache is a versatile, open-source HTTP server for modern operating systems including UNIX and Windows. It provides a secure, efficient, and extensible server that provides HTTP services in sync with the current HTTP standards. In this article, we’ll delve into the specifics of configuring Apache’s Userdir on Ubuntu and Debian.

    Userdir is a module that enables users to view their sites by entering a tilde (~) followed by their username. By configuring this module, you can set up Apache to serve files from a specific directory in the user’s home directory – typically public_html.

    Prerequisites

    Before we start, make sure you have the following:

    • A Debian or Ubuntu system.
    • Sudo or root access to run administrative commands.
    • Apache installed. If not, you can install it using the command `sudo apt install apache2`.

    Enabling the Userdir Module

    The first step is to enable the `userdir` module. By default, this module is not enabled in the Apache installation. You can do this by typing:

    sudo a2enmod userdir 
    

    Then, restart the Apache server to implement the changes.

    sudo systemctl restart apache2 
    

    Configuring the Userdir Directive

    The next step involves configuring the `Userdir` directive in the Apache configuration file. The location of the configuration file differs depending on whether you’re using Ubuntu or Debian. Here’s how you can do this:

    On Ubuntu:

    Open the userdir.conf file by typing:

    sudo nano /etc/apache2/mods-available/userdir.conf 
    

    Within this file, you’ll find the Userdir directive, which might look something like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <IfModule mod_userdir.c>
        Userdir public_html
        Userdir disabled root
     
        <Directory /home/*/public_html>
            AllowOverride FileInfo AuthConfig Limit Indexes
            Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
            Require method GET POST OPTIONS
        </Directory>
    </IfModule>

    If you want to modify the directory that the Userdir module points to, you can replace `public_html` with the name of your desired directory. Save and exit the file.

    On Debian:

    Open the `apache2.conf` file by typing:

    sudo nano /etc/apache2/apache2.conf 
    

    Search for the section titled . It will look similar to the section mentioned above.

    Make the desired changes, then save and exit the file.

    Creating the public_html Directory

    Now, you need to create the `public_html` directory (or your chosen directory) within the user’s home directory:

    mkdir ~/public_html 
    

    Then, create a test HTML file:

    echo "UserDir test page" > ~/public_html/index.html 
    

    Testing the Configuration

    Finally, you can test your configuration. Open your preferred web browser and navigate to http://your_server_ip/~username. If you see the text “UserDir test page”, your Userdir configuration is working.

    Conclusion

    And that’s it! You’ve successfully configured Apache Userdir on Ubuntu and Debian. By doing so, you’ve made it possible for users to host their own content on their personal directories, enhancing flexibility and decentralization on your server. This guide has provided you with a simplified, yet comprehensive, path to achieving this configuration. Happy web hosting!

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Change Port in Next.Js

    Ubuntu 24.04 LTS: The Future of Open-Source Excellence

    How to Execute Linux Commands in Python

    View 1 Comment

    1 Comment

    1. Jhon on July 21, 2023 3:12 am

      This does not work if you have to execute php (e.g index.php)

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Change Port in Next.Js
    • Ubuntu 24.04 LTS: The Future of Open-Source Excellence
    • How to Execute Linux Commands in Python
    • Creating MySQL User with GRANT OPTION
    • Where to find crontab (cron) logs in Ubuntu & Debian
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.