2.11.7. Symbolic links
A symbolic link (symlink) is a special file that contains a path to another file or directory, which is accessed when the symlink is referenced. Such links can be used to access a single file or directory simultaneously from multiple locations. For example, it is possible to organize the operation of two or more sites from a single directory — the files of the first site are stored in its directory, and instead of directories for the other sites, symlinks are created that point to the directory of the first site.
You can create a symbolic link through:
Creating through the console
Important points:
- The target file or directory must be within the root directory of the hosting account and belong to this hosting account (the hosting account must be the owner). Attempting to create a symlink without considering these conditions will result in a "Permission denied" error. An alternative to a symlink in such situations can be the use of a Bash script.
- It is recommended for the team to use absolute paths for the file and the symlink.
To create a symlink, connect to the hosting account via SSH and use the ln command:
ln -s /path/to/file /path/to/symlink
An example of a command that creates a symlink store, after which accessing it will open the contents of the www directory:
ln -s /home/example/example.com/www /home/example/example.com/store
Alternative to symlink
To call files outside the root directory of the hosting account, instead of symlinks, you can use a Bash script — invoking it with or without arguments will yield the same result as referring to a symlink that would point to a similar file:
#!/bin/bash
exec /usr/local/php83/bin/php "$@"