# Symbolic Link and Apache Alias for Web Development

These days, there are many web developers working remotely. We can now find a plenty of collaboration tools and file-sharing applications such as Dropbox. However, one of the problems faced when is that web documents that you save will not be accessible through a localhost address from the browser, as they are outside the Apache Server DocumentRoot.

To solve this issue, you can change the DocumentRoot path to point to the Dropbox folder. But even though this can be done easily in MAMP with the GUI, you may need to change the path – back and forth – to access other websites that are saved in the initial path, which is highly inefficient.

An alternative option you can use is by creating a Symbolic Link (Symlink) and Apache Alias. These allow us to keep the original file in the Dropbox while still being able to access it through the localhost address in the browser – as if the actual folder is in Apache DocumentRoot. This is what we are going to look at in this post.

Setup PHP, Apache, and MySQL in Mac without MAMP – Part II

#### Setup PHP, Apache, and MySQL in Mac without MAMP – Part II

In the previous tutorial of this series, we have configured Apache and PHP and thus we are able... Read more

In OS X as well as the other UNIX-based OS, like Ubuntu, a Symlink is created through Terminal with the following command.

ln -s path/to/source path/destination/symlink


For instance, you have your website files saved under the “Dropbox/Sites/project” directory. In Terminal type the following command to put a Symlink to that folder.

ln -s Dropbox/Sites/project ~/Sites/project


Certainly, you need to change the destination path. If you are using MAMP you can set the path to Applications/MAMP/htdocs/project, or /Library/WebServer/Documents if you are using the built-in Apache from OS X.

One thing that distinguishes Symlink from Shortcut or the Alias Folder is that a Symlink will be treated like the original file. Symlink can be accessed through Terminal and can also be added to any GUI application. In SublimeText, for instance, you can add the Symlink, instead of the original source as a Project. We would not be able for doing so with a Shortcut and an Alias folder.

In Windows, a Symlink is denoted with the mklink command as follows:

mklink /d "path\destination\symlink" "path\to\source"


Launch Command Prompt, type this command below to create a Symlink in WAMPServer directory that points to the source in Dropbox.

mklink /d "c:\wamp\www\project" "c:\Users\thoriq\project"


### Apache Alias in OS X

Aside from creating a Symlink folder, we can also use Apache Alias. Not to be confused with an Alias Folder, Apache Alias is a module in Apache for URL mapping that denotse one particular path with an Alias. That way you can also access folders through the localhost address – as if it is stored inside the Apache DocumentRoot.

Before we can create one, ensure that the mod_alias module is loaded. From Terminal, navigate to /etc/apache2, and open the httpd.conf file. Remove the hash sign at the beginning of the following line:

LoadModule alias_module libexec/apache2/mod_alias.so


At the same time, add this line at the very bottom of httpd.conf, as we will create a dedicated folder, named “alias” to save all Apache Aliases, so that the folder as well as the configuration files in it are picked up.

Include /private/etc/apache2/alias/*.conf


Type the following two lines in Terminal to create the “alias” folder and “app.conf”, where we will write the Alias configuration.

sudo mkdir /etc/apache2/alias
sudo touch /etc/apache/alias/app.conf


Type this command below to open the app.conf in SublimeText.

sudo subl /etc/apache/alias/app.conf


Apache Alias is specified this way:

Alias /alias-name "/source/of/original/folder"


Below is one complete example. You can add these in app.conf which we have created above.

Alias /app "/Users/thoriq/Dropbox/app"

<Directory "/Users/thoriq/Dropbox/app">
AllowOverride all
Order allow,deny
Allow from all
</Directory>


Save the file and restart Apache. And given the above specification, you should be able to access localhost/app address through the browser even though the actual folder is in the Dropbox folder.

### Apache Alias in Windows

If you are running on Windows and using WmpServer, you can create Apache Alias with ease. First, click WampServer icon in the taskbar and navigate to “Apache/Alias directories/Add an alias” menu.

A new window similar to Windows Command Prompt will pop up. In it, set the name of the alias. If you name the alias as “app”, for instance, it will later be accessible within localhost/app address in the browser. Press Enter to confirm the alias name.

Then, specify the source of the alias. For instance, c:/Users/thoriq/Dropbox/Sites/app.

We are done.

### Conclusion

In this post, we have shown you how to create Symbolic Link and Apache Alias, which would be useful to access and manage folders outside the Apache DocumentRoot.