By default on DirectAdmin, your domain's public web root is located at:
/domains/yourdomain.com/public_html
However, modern PHP frameworks (such as Laravel, Symfony, Statamic, or custom Web applications) store their public entry file inside a subfolder like public_html/public/ or public_html/web/. Pointing your server's Document Root to this subfolder is essential for application security, ensuring that private files (like your .env configuration file, database credentials, and vendor/ packages) cannot be accessed directly by web browsers.
This guide will show you how to change your website's document root in DirectAdmin.
Method 1: Changing Document Root via DirectAdmin Domain Setup (Recommended)
DirectAdmin allows you to customize the public document root path for your domains directly from the control panel interface.
- Log in to your Cubes Hosting DirectAdmin Control Panel.
- Navigate to Account Manager > Domain Setup.
- Click on your domain name.
- Look for the Document Root (or Private HTML / Web Root) option.
- Change the target directory from
public_htmlto your framework's public subfolder:public_html/public - Click Save (or Modify).
DirectAdmin will update your Apache/Nginx web server configuration automatically, and your domain will now serve files directly from /public_html/public/.
Method 2: Using .htaccess Rewrite (Alternative Method)
If you prefer not to change global domain settings or are running multiple sub-applications:
- Open your DirectAdmin File Manager and navigate to your main
/public_html/folder. - Create or edit the
.htaccessfile inside/public_html/. - Add the following mod_rewrite code to redirect incoming web requests into your
/public/subfolder:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect requests to the /public/ directory
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
- Save the
.htaccessfile.
Method 3: Using a Symbolic Link (Symlink) via SSH
For developers using Git deployments or CI/CD pipelines:
- Connect to your web server via SSH Terminal.
- Navigate to your domain directory:
cd ~/domains/yourdomain.com/ - Backup or remove the existing empty
public_htmldirectory:mv public_html public_html_backup - Create a symbolic link pointing
public_htmlto your framework'spublicfolder:ln -s /home/username/domains/yourdomain.com/my-laravel-app/public public_html
Security Verification
After updating your document root, verify that your private configuration files are inaccessible from the web:
- Open a browser and attempt to visit:
http://yourdomain.com/.env - You should receive a 404 Not Found or 403 Forbidden error. If the file downloads or displays text, your document root is still pointing to the main directory!
Conclusion
Changing your document root is a fundamental security step for hosting modern PHP frameworks like Laravel or Symfony. Update your document root via Domain Setup in DirectAdmin or via .htaccess, and keep your core application files protected!
