Search code examples
commandsymlinklaravel-envoy

Linux Symlink command between two directories adds a directory to link path


so I have a server with Linux to which I deploy staging Laravel application from Gitlab using the Gitlab Envoy guide

The structure of folders is as follows:

  • /public_html/ main folder where user is redirected to
  • /releases/ folder with all releases
    • /timestampA/ specific release app
    • /timestampB/ specific release app

There is a problem when creating a symlink between

ln -nfs releases/timestamp public_html

the symlink that is created looks like this

./releases/timestamp -> public_html/timestamp

now it is supposed to be like this

./releases/timestamp -> public_html

does anyone know why this happens and possibly how to fix it?


Solution

  • This happens because public_html already exists and is a directory.

    From the man ln (bold is mine):

    Given one or two arguments, ln creates a link to an existing file source_file. If target_file is given, the link has that name; target_file may also be a directory in which to place the link; otherwise it is placed in the current directory. If only the directory is specified, the link will be made to the last component of source_file.

    In order to achieve what you want you should remove the public_html folder first (or add -F option to ln command, but it's not guaranteed to work).