DEV Community

Cover image for Setting up an Alias for a Directory in Apache2 Server
Sajidur Rahman Shajib
Sajidur Rahman Shajib

Posted on

16

Setting up an Alias for a Directory in Apache2 Server

In most Apache installations, the default root directory is typically located at /var/www/html on Linux systems. This means that the index.html file should be placed in the /var/www/html directory for it to be served as the default file when accessing the web server.

When you develop something in your apache2 server that time this var/www/html directory might not be suitable for you. So if you can alias your directory where you want to develop or write your program it will help you develop your program.

First, check that is your apache2 server active or not using service apache2 status. If apache2 server is stopped then activate apache2 server using this command service apache2 start

Open apache2.conf file in your vs code editor using this command - code /etc/apache2/apache2.conf.
Hope, you will find this code below -

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
Enter fullscreen mode Exit fullscreen mode

Bellow this code add your code which alias your custom directory location.

Alias /yoursite /yourDirectory
<Directory /yourDirectory>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
Enter fullscreen mode Exit fullscreen mode

For better understanding, I share my settings. Hope you will understand now.

Alias /local-wp /home/sajiudr/all-wp
<Directory /home/sajidur/all-wp>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
Enter fullscreen mode Exit fullscreen mode

Now, restart your apache2 server using this command service apache2 restart. Then check apache2 server status service apache2 status.

If you create a file index.html in yourDirectory you can show this in your browser to hit this link http://localhost/yoursite.

Hope you will understand. If you face any problem please comment bellow my post.

Happy coding, fellow Devs! Until next time, bye and keep building amazing things!

Concerned about the future of the software development career?

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Okay let's go

Community matters

Top comments (2)

Collapse
 
khairulbashar010 profile image
Khairul Bashar

Awesome stuff. Will surely be helpful!

Collapse
 
sajidurshajib profile image
Sajidur Rahman Shajib

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay