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!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (2)

Collapse
 
khairulbashar010 profile image
Khairul Bashar

Awesome stuff. Will surely be helpful!

Collapse
 
sajidurshajib profile image
Sajidur Rahman Shajib

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay