Tip: Start typing to get instant search results.
How to Deploy a Laravel Application on DirectAdmin
Laravel is one of the most popular and powerful PHP frameworks, known for its elegant syntax and rich feature set. However, when we want to host a Laravel application in a hosting environment running DirectAdmin, there is an important peculiarity we need to take into account.
Unlike most popular CMS platforms (such as WordPress), a web application built on the Laravel framework does not serve its root folder, but rather the public/ subfolder (which is located inside the root folder). In a DirectAdmin environment, the folder that is served is public_html/, that is, the root folder of the application. This difference creates a problem that requires the proper configuration to be resolved.
The solution is to move the application into a new folder and convert public_html into a symbolic link that points directly to the application’s public folder.
This way, DirectAdmin publicly serves only the files in the public/ folder, while the rest of the application’s code remains inaccessible from the internet.
💡 Laravel Deployer Tool: If you are using the Laravel Deployer Tool to deploy your application, pay attention to the notes marked with this icon at each step, as some commands differ.
Converting public_html into a symbolic link
WARNING: Before running the following commands, make sure you have taken a backup of your account. Renaming public_html and removing files are irreversible actions.
First, we connect to the server via SSH and navigate to our domain’s folder.
cd /home/user/domains/mydomain.com
We assume that your Laravel application is initially located in the public_html folder. Next, we run the following commands:
mv public_html laravel ln -s laravel/public public_html cd public_html rm storage
With the commands above, we:
- Rename the existing
public_htmlfolder that contains your Laravel project tolaravel. - Create a symbolic link named
public_htmlthat points to the application’spublicsubfolder. - Remove the application’s existing
storagesymlink, so that we can recreate it in the next step.
💡 Deployer: If you are using Deployer, the symbolic link should point to laravel/current/public instead of laravel/public, since Deployer manages releases through the current folder. In other words, the command to create the symbolic link becomes: ln -s laravel/current/public public_html.
Configuring the Laravel application
We navigate to the application’s folder:
cd /home/user/domains/mydomain.com/laravel/
And run the following commands:
php artisan cache:clear php artisan config:cache php artisan storage:unlink php artisan storage:link
With the commands above, we:
- Clear the application’s cache and then rebuild it, so that the settings of the new environment are loaded correctly.
- Remove the old
storagesymlink (if it exists) and recreate it, so that the application’s files are stored in the correct folder.
💡 Deployer: If you are using Deployer, navigate to the laravel/current folder instead of laravel before running the commands above. Subsequent deployments will automatically update the current symlink, without you needing to repeat these steps.
Once the steps above are complete, your Laravel application will be served from the expected public folder. DirectAdmin’s standard public_html will now be a symbolic link pointing to your application’s public folder.
If you are using Managed Dedicated Hosting (Managed Bare-metal or Managed Cloud), the steps above won’t concern you. We take care of the complete setup, configuration, and optimization of your managed Laravel hosting environment, so that it is ready for your Laravel application.