Sunday, July 14, 2019

Creating a symbolic link on Ubuntu 18.04 for xampp htdocs

So I have been struggling to run code inside xampp htdocs on Ubuntu since I did not have the sudo privileges. As one may know, when you navigate to http://localhost in your browser you are being sent to the htdocs directory within XAMPP (specifically /opt/lampp/htdocs). This folder’s read and write permissions are limited to the root user and will not let you create files and folders within it.

I did a bit of Googling to find a resolution. To my luck, I found what is called a symbolic link, this is a special kind of file (entry) that points to the actual file or directory on a disk. Essentially this means that your projects will technically exist in this new folder which will reside in your Home folder, but XAMPP will treat it as if it were located within htdocs.

There are two types of links:
  • symbolic links, Refer to a symbolic path indicating the abstract location of another file
  • hard links, Refer to the specific location of physical data.
We will be using the symbolic link a.k.a soft link. My work generally resides in the Documents folder then I'd make subfolders. E.g.,  there is a folder for programming, a folder for University, a folder for Media and so on.

Creating a symbolic link

-s, make symbolic links instead of hard links
sudo -s <directory that must be linked> <directory that is linked to>
sudo -s <target file> <symbolic file>

Type in:
sudo ln -s /home/banele/Documents/programming/php/Projects/PHPExcelLibrary /opt/lampp/htdocs

Enter your password when prompted. This is all it takes to create the symbolic link. We use sudo because of the htdocs permissions. For most symbolic links you create in Ubuntu it is not necessary.

Extra bonus I also created a symbolic link for the php file for the system variables.
sudo ln -s /opt/lampp/bin/php /usr/bin/php

Removing a symbolic link

You can remove existing links attached to files or directories by the unlink or rm command.

  • unlink <system link name to remove> unlink /home/banele/Documents/programming/php/Projects/PHPExcelLibrary
  • rm <system link name to remove> rm /home/banele/Documents/programming/php/Projects/PHPExcelLibrary



No comments:

Post a Comment

Good bye Windows, hello Ubuntu!

After years of using Microsoft Windows, from the days of Windows XP through to Windows 11 (though I'd be lying if I said I've actua...