PHP Tutorials

Create a Symlink (Symbolic Link) Using PHP

There are many cases that you want to create SymLink in the web server. However not all web hosts allows for shell access. Considering PHP is the most common scripts supported by almost all the web hosts, in below, we will show you how to create symlink using PHP. And we have test the script in the web server of Bluehost (, a leading PHP hosting service provider in the industry.

Create Symlink without Shell Access

By default, Bluehost customers of its Shared hosting don’t have access to the shell. In this case, to create Symlink, you could do by leverage php script. You could create a very simple php file with the content as below:

<?php symlink(‘<target_filename>’, ‘<symlink_filename>’); ?>

 Notes: You need to replace target file name and Symlink file name according to the server environment

Then, revoking this PHP file in your browser, after which the symlink should have been created.

Create Symlink with Shell Access

Bluehost allow its customers to apply for shell access by submitting Personal ID Card, Passport, or Driver License. As its customers, you could sent an email to them and ask for shell access, they will guide you on the details.

After you get shell access, things become very easy. Just login the shell and type below command:

ln -s target_filename symlink_filename

You done!

Limitation when Creating Symlik with Bluehost

Bluehost does not allow symlinking PHP files on its server, as it thinks this could cause security issues. There is not a way around this unfortunately, even if you parse HTML as application/x-httpd-php. You will be able to symlink to other files and folders, only PHP should give you the error 500.

Leave a Reply

Your email address will not be published. Required fields are marked *