Ubuntu Symlink – Understanding the Structure of Symbolic Links

apache-httpdphpmyadminsymlinkUbuntu

I use Ubuntu 15.10 and I'm very new in Linux. After reading in Wikipedia what is a symbolic link in general, and after executing a symlink creation command in the Ubuntu Unix-bash terminal, I ought to better understand the structure of a symlink I worked with several times when creating (and "destroying") Ubuntu learning environments.

There is a short syntax I ran each time when installing a PHPmyadmin (PMA) service. Without running it, the service just didn't work. From the information I gathered, this following syntax creates a symlink that connects Apache to a certain PMA file that includes conf directions.

This is the syntax I ran each time:

cd /etc/apache2/conf-enabled/
sudo ln -s /etc/phpmyadmin/apache.conf phpmyadmin.conf
service apache2 restart

I want to better understand what is actually being done here, for example:

  1. Why is the cd navigation even needed? Couldn't we specify which files we want to work on from the root (computer) folder and that's it?

  2. Why is the -s after the ln?

  3. I navigated to both directories in the ln command but I couldn't find phpmyadmin.conf in either of them – So, how can the system know where it is (assuming there is no system-wide search for it).

Best Answer

  1. The ln command creates the symlink in the current directory if no directory is specified. Thus, phpmyadmin.conf is put in /etc/apache2/conf-enabled/. You could have also done

    ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.conf
    

    This is standard behavior for pretty much all Unix commands.

  2. The -s option specifies that you are creating a soft link as opposed to a hard link. Read more here.

  3. I don't quite understand the question ("how can the system know where it is?"). phpmyadmin.conf is created in the current directory (in this case /etc/apache2/conf-enabled/).

Related Question