Access other folder then /var/www/html in Apache2 over http

Solution 1:

Symlink way

If you want you can simply make an symlink to it, like i did on my Raspberry Pi, but I'm not sure if it's safe when your website is public. It works in home network.

Let's say you want to access /home/j (because "j" is my username) from your /var/www. To do that you'll need command ln -s /home/j jhome. Make sure you are in /var/www while running this command.

Now you should be able to access it simply using cd jhome. You can test it by putting html file inside /home/j and linking to it by for example your index.html.

You can do same thing with other directories and names.

More professional, Apache configuration way

Also, I've found some Apache documentation here and Stack Overflow topic, I think it's more professional way to do same thing and I believe it's right way to do it.

It turns out that you need to add Alias /alias_directory /path_on_your_machine line to your Apache config file (which for me is /etc/apache2/apache2.conf). (it also works for me) I recommend backuping file before editing it.


Here are exact commands I used:

  • cp /etc/apache2/apache2.conf{,.bak} - make backup
  • echo "Alias /jhome /home/j" >> /etc/apache2/apache2.conf - append line, you can also do that with nano or other text editor.
  • service apache2 restart - restart Apache, it won't work without it

Remember to run commands as root, because You'll get permission errors without it.

I hope I helped you in some way. :)

Solution 2:

If you have phpMyAdmin up and running, you probably have installed apache2. The process of mapping an http address to a directory in your localmachine is called a virtual host. Read more on this here. Or google for how to create a virtual host and a domain for my local machine.

I can guide you if you need more assistance on this matter.