How to create a symbolic link in cPanel

How to create a symbolic link in cPanel

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.
    • Related Articles

    • MultiPHP INI Editor in cPanel

      Making modifications to the php.ini file might occasionally be useful in order to specifically alter PHP settings for particular scripts. One unique file that can be used to easily change the server defaults for PHP settings on a particular website ...
    • What Are Common Login URLs?

      Common Login URLs with your Hosting Account Webmail Non SSL http://www.exampledomain.com/webmail http://exampledomain.com:2095 SSL https://exampledomain.com/webmail https://exampledomain.com:2096 cPanel Domain Non-SSL ...
    • What Is A Cron Job?

      Cron Jobs With the help of the Linux utility Cron, users may program or automate repetitive processes to occur at predetermined periods. These are the individual jobs, or cron jobs. Here are some examples of Crons that your developer or you could ...
    • Giving Access to Developers

      There are several options available to you about how a developer may access your website in the event that you need to provide them access in order for them to construct or maintain it. Before we begin, we advise you to always create a backup of your ...
    • How Can I Monitor The Resources That My Account is Using?

      Viewing Current Resource Usage You may check the current resource use of your account using a few different methods: Top (via Command Line) You may use the Top command in cPanel's Terminal Application or SSH to see how much resource you are now ...