How to add custom directory e.g. phpmyadmin?

As my knowledge about apache is minimal. I'd like to let it grow so I'd have more experience with LAMP. My hot question for today is:

How to add custom directory to webserver? (e.g. phpmyadmin)?

My goal is to be able to create custom addresses with custom websites within. Let's suppose that I have my custom directory at: /media/my/web/portal1 and I'd like to load it when client calls

http://localhost/myportal1 at webbrowser. 

Could you give me a list of steps with few words of explanation?


Edit your Apache config file and add an Alias Directive. For example, let's use the default file.

sudo -e /etc/apache2/sites-available/default

Make your alias by adding a section within the VirtualHost directive:

Alias /database/ "/usr/share/php5/phpmyadmin/"
<Directory "/usr/share/php5/phpmyadmin/">
    Order allow,deny
    Allow from all
    # New directive needed in Apache 2.4.3: 
    Require all granted
</Directory>

Save and restart: sudo /etc/init.d/apache2 restart

Or for the other reference:

sudo -e /etc/apache2/sites-available/default

And the contents...

Alias /myportal1/ "/media/my/web/portal1/"
<Directory "/media/my/web/portal1/">
    Order allow,deny
    Allow from all
    # New directive needed in Apache 2.4.3: 
    Require all granted
</Directory>

Save and restart: sudo /etc/init.d/apache2 restart

Add more directives within the Directory directives, such as

Options Indexes FollowSymLinks 

See http://httpd.apache.org/docs/2.2/mod/core.html#directory

That what you were after?


A simpler alternative is to create a soft link from the document root. For example, if the document root is "/var/www" (the default on most Linux systems), then the following command does the trick:

sudo ln -s /media/my/web/portal1 /var/www/myportal1

This works immediately - you don't even need to reload the Apache server.


Apache is a user in your system, just like you are, except that it cannot login. That means file access is exactly the same for Apache as it is for you. So, first, if Apache should serve a directory in /media/something, then Apache must have access to read it and its files.

Second, to setup a site that uses this directory as its home, you create sites-files, like /etc/apache2/sites-available/your-site. This is part of what's called vhosting. There are two different types; one based on name (the domain name) and one based on IP. The most common setup is to use name-based vhosts. You can read more about that here: http://httpd.apache.org/docs/2.2/vhosts/