Symbolic links, or "symlinks," are essentially shortcuts to specific files or directories. A symlink's ability to traverse file systems due to its reference to abstract filenames and directories rather than actual locations is one of its benefits.
There is a number of ways to create a symlink in cPanel:
1. You may use the following command to create a symlink using the Terminal in cPanel or over SSH:
ln -s /path/to/target /path/to/shortcut
2. The same command may be used to generate it via a cronjob as well:
NOTE: Once the symlink has been formed, be careful to remove the cronjob.
3. You can also create a symlink using the PHP function.
The example of the script can be found below:
<?php
$target = '/home/cPanelusername/public_html/index.html';
$shortcut = 'script.html';
symlink($target, $shortcut);
?>
Just run this PHP file in the browser and it will create symlink right away.
Example of the symlink usage
There are several situations where a symlink could be the ideal answer. For the addon domain website (/public_html/domain1.com), we will utilize a symlink in our example to access photos stored in the main domain web root (/public_html/):
The only method to use the photos in the /public_html/images folder is to build a symlink in the addon domain folder because the addon domain website lacks access to /public_html or any higher level directory:
ln -s /home/ncexample/public_html/images/ /home/ncexample/public_html/domain1.com/images
As you can see, symlinks will help you to avoid duplicate content if you use the same files for multiple websites.
NOTE: Since symlinks to other websites' root directories can lead to major security lapses, we strongly advise against using symlinks for any folders that expose configuration or system files. If these data are obtained, they might be exploited for hacking or other nefarious purposes.