← ServerPilot Docs

How to Use a Custom Web Root Directory

The web root directory of an app is the directory that files are served from. Your ServerPilot apps use a directory called public. This directory is where you put your app's index.php file and directories containing other files, such as images.

In some cases, you may want to have a different directory be used as the web root. For example, you may be used to cPanel using the web root directory public_html or Plesk using httpdocs and want to use the same name instead of public.

With ServerPilot, instead of directly changing the web root directory, you can rename or remove the directory public and make public a symlink to a different directory, such as public_html.

Symlinks: A Brief Tutorial

You can think of symlinks as aliases. They're additional names to refer to the same thing. Using symlinks, you can give a file or directory any number of additional names. There's still only one file or directory. If you delete a symlink, you've only deleted the alias, you haven't deleted the real thing.

When you are SSH'd in to your server, the syntax for creating a symlink is:

ln -s path/to/real/directory name_of_symlink_to_create

Changing the Web Root Using a Symlink

First, SSH in to your server as the system user your app belongs to.

Next, change the directory to your app's directory:

cd apps/APPNAME

You should see your app's public directory, the web root, if you list the current directory's contents with ls -l ("l" means "long," so we see details):

SYSUSER@SERVERNAME:~/apps/APPNAME$ ls -l
total 4
drwxr-xr-x 2 SYSUSER SYSUSER 4096 Aug  4 16:55 public

Now, let's imagine we want to use public_html as the web root directory. First, we'll rename public to public_html. Then, we'll create the symlink from public to public_html.

mv public public_html
ln -s public_html public

If we now list our directory contents again, we'll see the symlink:

SYSUSER@SERVERNAME:~/apps/APPNAME$ ls -l
total 4
lrwxrwxrwx 1 SYSUSER SYSUSER   11 Aug  4 20:25 public -> public_html
drwxr-xr-x 2 SYSUSER SYSUSER 4096 Aug  4 16:55 public_html

The arrow (->) tells us that public is a symlink that points to the directory public_html.

With the above changes, your app will be using a custom web root directory. The name public will still be there, but it's no longer a directory. Instead, public is a symlink.

Launch your first site in 5 minutes