Home > Learn > Server > How to Change DocumentRoot in DirectAdmin
Understanding DocumentRoot and Its Importance
In the dynamic world of web hosting, effectively managing subdomains is key to maintaining organized, secure, and efficient websites. DirectAdmin, a widely-used control panel, simplifies tasks like domain and subdomain management, making it a go-to choice for hosting providers. A crucial aspect of this management is understanding the concept of DocumentRoot.
This article is part of Rackset’s Server guides — browse the rest of the category for more in-depth tutorials on this topic.
What is DocumentRoot?
DocumentRoot is the directory on your server where the web server looks for files to serve when a specific domain or subdomain is accessed. Essentially, it acts as the root directory for a particular web domain, determining where the server should look for the website’s files.
Importance of DocumentRoot
The DocumentRoot is vital for several reasons:
- Organization: It helps in structuring your files and directories logically, making it easier to manage multiple projects or applications.
- Security: By isolating applications into different DocumentRoots, you reduce the risk of unauthorized access between applications.
- Flexibility: It allows for easy restructuring of projects, enabling zero-downtime deployments by pointing to new directories seamlessly.
- Performance: It optimizes server performance by ensuring the server only accesses the necessary files for each domain or subdomain.
How DocumentRoot Works in DirectAdmin
In DirectAdmin, the DocumentRoot is configured for each domain or subdomain. For example, for a subdomain like sub.example.com under the user username, the default DocumentRoot might be:
/home/username/domains/example.com/public_html/sub
This path tells the server to look in the sub directory within the public_html folder for the files to serve whenever sub.example.com is accessed.
Why You Might Need to Change the DocumentRoot
There are several scenarios where changing the DocumentRoot is necessary:
- Project Restructuring: When reorganizing the directory structure for better management or new project requirements.
- Application Isolation: To separate different applications or environments, thereby enhancing security and manageability.
- Deployment Strategies: Implementing zero-downtime deployments by switching DocumentRoots to point to new versions of the application.
Understanding and managing your DocumentRoot effectively ensures that your web hosting environment remains robust, secure, and adaptable to changing needs.
Prerequisites for Changing DocumentRoot
Before you begin changing the DocumentRoot for a subdomain in DirectAdmin, it’s essential to ensure that you have the necessary prerequisites in place. These prerequisites will help you execute the changes smoothly and minimize potential disruptions to your website’s functionality.
Access and Permissions
- Administrator Access: Ensure that you have administrator access to the DirectAdmin control panel. This level of access is required to modify server configurations and DocumentRoot settings.
- File System Permissions: Verify that you have the necessary permissions to modify the web directory and any related configuration files. This typically requires root or sudo privileges on the server.
Backup and Recovery
- Data Backup: Create a complete backup of your current website files and configurations. This backup will be invaluable if you need to revert changes or if something goes wrong during the process.
- Configuration Backup: Specifically back up your current web server configuration files, such as
httpd.conffor Apache ornginx.conffor Nginx, to ensure you can restore them if needed.
Technical Knowledge
- Understanding of Web Servers: Familiarize yourself with the basics of web server operations, particularly Apache and Nginx, as these are commonly used in DirectAdmin setups.
- Command Line Proficiency: Be comfortable using the command line interface to navigate directories, edit configuration files, and restart services, as these skills are often necessary during the process.
Server Environment
- Server Type: Confirm that your server environment is correctly set up, whether it’s Apache, Nginx, or a combination of both. This guide assumes an Apache-based setup with an optional Nginx reverse proxy.
- DirectAdmin Version: Ensure that your DirectAdmin control panel is up-to-date. Older versions may lack certain features or have different interfaces that could affect the process.
Planning and Strategy
- Change Management: Plan the change during a low-traffic period to minimize the impact on users. Inform stakeholders of the planned maintenance to set expectations.
- Testing Environment: If possible, test the changes in a staging environment before applying them to the live server to identify potential issues without affecting the production site.
Assessing Your Server Environment
Before proceeding with changing the DocumentRoot for your subdomain in DirectAdmin, it’s crucial to understand your current server environment. This assessment will help you identify the necessary configurations and ensure a smooth transition. Here are the key factors to consider:
Server Type and Configuration
Determine the type of server and configuration you are working with. DirectAdmin supports various server types, but for this guide, we will focus on an Apache-based setup with an optional Nginx reverse proxy.
- Apache: Check the version and modules installed, as some configurations might require specific modules.
- Nginx: If using it as a reverse proxy, ensure you know the configuration files involved and how they interact with Apache.
- OpenLiteSpeed: If applicable, note any custom configurations that might affect DocumentRoot changes.
Directory Structure
Understanding the directory structure is vital for pinpointing the current DocumentRoot and planning the new path. Typically, DirectAdmin stores user web files in:
/home/username/domains/sub.example.com/public_html
Identify the current DocumentRoot by checking the user’s domain directory and any custom configurations that might override the default path.
Permissions and Ownership
File permissions and ownership are critical for security and functionality. Ensure that:
- The new DocumentRoot directory has the correct ownership, typically
username:username. - Permissions are set appropriately, usually
755for directories and644for files.
Backup and Testing Environment
Before making significant changes, always back up your current configuration and data. Consider setting up a testing environment to trial the DocumentRoot change without affecting your live site.
- Create a backup using DirectAdmin’s built-in backup tools or manually via SSH.
- Set up a staging subdomain or a local environment to test the new DocumentRoot.
By thoroughly assessing your server environment, you lay the groundwork for a successful DocumentRoot change, minimizing risks and ensuring your website continues to run smoothly.
Read more: Changing Your WordPress Password: A Step-by-Step Guide
Every website needs stable, fast hosting to stay online. Rackset’s web hosting runs on NVMe storage with high uptime and 24/7 support, giving your site a reliable foundation.
Back Up Your Current Configuration
Before making any changes to the DocumentRoot of your subdomain in DirectAdmin, it is crucial to back up your current configuration. This step ensures that you can restore the original settings if something goes wrong during the process. Here’s how you can safely back up your configuration.
Step 1: Access Your Server
To begin, you need to access your server via SSH. Open your terminal and connect to your server using the following command:
ssh username@your-server-ip
Replace username with your actual server username and your-server-ip with your server’s IP address.
Step 2: Navigate to the Apache Configuration Directory
Once connected, navigate to the directory where Apache stores its configuration files. Typically, this is located at:
cd /usr/local/directadmin/data/users/username/domains
Ensure you replace username with the actual user account name.
Step 3: Identify the Configuration File
In this directory, locate the configuration file related to your subdomain. The file is usually named in the format sub.example.com.conf. Use the following command to list files:
ls -l
Step 4: Create a Backup of the Configuration File
Once you have identified the correct configuration file, create a backup using the cp command:
cp sub.example.com.conf sub.example.com.conf.bak
This command creates a copy of the original configuration file with a .bak extension, preserving the current settings.
Step 5: Verify the Backup
Finally, verify that the backup was successful by listing the files again:
ls -l
You should see both the original and the backup configuration files listed.
By following these steps, you ensure that you have a fallback option if any issues arise during the DocumentRoot change process. This backup is a safeguard that can save you time and prevent potential disruptions to your website.
Methods to Change DocumentRoot in DirectAdmin
Changing the DocumentRoot for a subdomain in DirectAdmin can be accomplished through several methods. Each approach offers flexibility depending on your server setup and specific needs. Here, we’ll explore three reliable methods: using the DirectAdmin GUI, creating a symbolic link, and editing the custom virtual host file.
1. Using the DirectAdmin GUI
The DirectAdmin graphical user interface (GUI) provides a straightforward method to change the DocumentRoot for a subdomain. This method is user-friendly and does not require extensive technical knowledge.
- Log in to your DirectAdmin account.
- Navigate to Domain Setup and select the domain associated with your subdomain.
- Click on Subdomain Management.
- Select the subdomain you wish to modify, for example,
sub.example.com. - Change the DocumentRoot path to the desired directory.
- Save the changes and restart the web server to apply the new settings.
2. Creating a Symbolic Link
Creating a symbolic link is a flexible approach that allows the DocumentRoot to point to a different directory without changing the actual configuration files. This method is useful for developers who need to switch between different project directories frequently.
Read more: Installing Apache on Ubuntu 22.04: A Step-by-Step Guide
# Navigate to the public_html directory of the subdomain
cd /home/username/domains/sub.example.com/
# Remove the existing public_html directory
rm -rf public_html
# Create a symbolic link to the new DocumentRoot
ln -s /home/username/new_directory public_html
Ensure to restart the web server after creating the symbolic link to ensure the changes take effect.
If you need this service, Rackset’s team provides professional shared hosting with full support so you can rely on the quality and get set up quickly.
3. Editing the Custom Virtual Host File
For more advanced users, editing the custom virtual host file offers precise control over the DocumentRoot. This method is ideal for complex setups or when integrating with additional services like Nginx as a reverse proxy.
- Access the server via SSH.
- Locate the custom virtual host configuration file, typically found at
/usr/local/directadmin/data/users/username/httpd.conf. - Edit the file to update the
DocumentRootdirective for the subdomain:
ServerName sub.example.com
DocumentRoot /home/username/new_directory
...
After saving the changes, restart the web server to apply the new configuration.
Post-Change Tasks
Regardless of the method used, always perform the following post-change tasks:
- Test the subdomain to ensure it resolves correctly and serves content from the new DocumentRoot.
- Check error logs for any issues that might arise due to the change.
- Regularly maintain and update the DocumentRoot as needed to accommodate new projects or changes in your web setup.
Testing and Verifying the New DocumentRoot
Once you have successfully changed the DocumentRoot for your subdomain sub.example.com, it is crucial to test and verify that everything is functioning as expected. This ensures that your website remains accessible and that no issues arise from the recent changes. Follow these steps to confirm the new DocumentRoot is correctly configured:
1. Check the Configuration Files
Before testing the website, double-check your configuration files to ensure that the changes have been saved properly. Depending on your setup, this might involve verifying:
- The Apache configuration file, typically located at
/etc/httpd/conf/httpd.confor/etc/apache2/sites-available/. - The Nginx configuration if you are using it as a reverse proxy, usually found at
/etc/nginx/nginx.confor/etc/nginx/sites-available/.
2. Restart Web Server Services
After confirming the configuration changes, restart the web server services to apply the new settings:
sudo systemctl restart httpd # For Apache
sudo systemctl restart nginx # If using Nginx
3. Access the Subdomain
Open a web browser and navigate to http://sub.example.com. Check if the website loads correctly. If you see the expected content, it indicates that the DocumentRoot change is successful.
4. Verify with Command Line Tools
Use command line tools like curl to further verify the DocumentRoot change:
curl -I http://sub.example.com
This command should return a 200 OK status, confirming the server is serving content from the correct directory.
5. Check Error Logs
If you encounter issues, review the server error logs for any clues. Common log locations include:
/var/log/httpd/error_logfor Apache/var/log/nginx/error.logfor Nginx
6. Test with Different Devices
Access the subdomain from different devices and networks to ensure the changes are globally propagated and accessible. This step helps in identifying any caching issues or DNS propagation delays.
By following these steps, you can confidently verify that the new DocumentRoot for sub.example.com is correctly set up, ensuring your website continues to operate smoothly and efficiently.
Common Issues and Troubleshooting Tips
Changing the DocumentRoot in DirectAdmin is a straightforward process, but it can sometimes lead to issues if not executed properly. Here are some common problems you might encounter and tips on how to troubleshoot them effectively.
Read more: 10 Must-Do Steps to Secure Your WordPress Site from Hackers
Common Issues
- Permission Errors: Incorrect file permissions can prevent the web server from accessing the new DocumentRoot.
- Incorrect Path: Misconfiguring the path to the DocumentRoot can lead to 404 errors.
- Cache Problems: Cached data might cause old content to appear even after changing the DocumentRoot.
- Configuration Overwrite: Updates or changes in DirectAdmin might overwrite custom configurations.
Troubleshooting Tips
1. Verify File Permissions
Ensure that the web server has the correct permissions to access the new DocumentRoot. Use the following commands to set appropriate permissions:
For projects that need guaranteed resources and full root control, a VPS is the right step up from shared hosting. With VPS hosting you get dedicated CPU/RAM, NVMe storage, a dedicated IP and high uptime, deployed in minutes.
chown -R username:username /home/username/domains/sub.example.com/public_html
chmod -R 755 /home/username/domains/sub.example.com/public_html
2. Check the Path Configuration
Double-check the path specified in the DirectAdmin configuration to ensure it points to the correct directory. You can verify this in the httpd.conf file:
DocumentRoot "/home/username/domains/sub.example.com/public_html"
3. Clear Cache
If you are using a caching mechanism like Nginx or a browser cache, clear it to ensure the new DocumentRoot is being served. For Nginx, restart the service:
systemctl restart nginx
4. Preserve Custom Configurations
To prevent DirectAdmin from overwriting your custom configurations, use the custom vhost method to ensure your settings are preserved even after updates:
Include /usr/local/directadmin/data/users/username/httpd.conf
5. Review Error Logs
Check Apache or Nginx error logs for specific error messages that can provide clues to any underlying issues:
tail -f /var/log/httpd/error_log
By following these troubleshooting steps, you can resolve common issues effectively, ensuring a smooth transition to the new DocumentRoot in DirectAdmin.
Maintaining DocumentRoot Changes Over Time
After successfully changing the DocumentRoot for your subdomain in DirectAdmin, ongoing maintenance is crucial to ensure continued performance and security. Here are some strategies and best practices to help you maintain these changes effectively over time.
Regular Backups
Always maintain regular backups of your website files and configurations. This practice ensures that you can quickly restore functionality if any issues arise from future changes or updates.
- Schedule automated backups through DirectAdmin or a third-party tool.
- Store backups in a secure and accessible location.
- Test backup restoration periodically to ensure data integrity.
Monitor and Update Configuration Files
Configuration files, such as httpd.conf and nginx.conf, are integral to your server setup. Regularly review these files to confirm that changes remain intact and make adjustments as necessary.
- Use version control systems like Git to track changes in configuration files.
- Document any modifications for future reference.
- Ensure that any new software updates do not overwrite custom settings.
Security Audits
Conduct periodic security audits to identify vulnerabilities that could arise from misconfigurations or outdated software.
- Regularly update your web server and applications to the latest versions.
- Implement security headers and SSL/TLS certificates for encrypted connections.
- Use tools like SSL Labs to test your server’s security posture.
Performance Monitoring
Keep an eye on your website’s performance to ensure that the DocumentRoot changes do not negatively impact load times or server responsiveness.
- Utilize monitoring tools like New Relic or Google Analytics for insights.
- Analyze server logs to detect unusual patterns or errors.
- Optimize your website content and server settings for better performance.
Documentation and Training
Maintain comprehensive documentation of all changes made to the DocumentRoot and related configurations. Ensure that your team is trained to handle these changes and understands the implications of any modifications.
- Create a centralized repository for all documentation.
- Regularly update documents to reflect current configurations.
- Provide training sessions for team members to stay informed about best practices.
By following these maintenance strategies, you can ensure that your DocumentRoot changes remain effective and your subdomain continues to operate smoothly within DirectAdmin.
Seamlessly Manage Your Hosting
Mastering the DocumentRoot change in DirectAdmin is just the beginning. With Rackset’s reliable web hosting, experience unparalleled control and flexibility for all your hosting needs.
Elevate your web management game today!
Conclusion
Changing the DocumentRoot in DirectAdmin is a straightforward process that can significantly enhance your website management capabilities. By following the steps outlined in this guide, you can easily configure your server to point to the desired directory, ensuring that your website files are organized and accessible as needed. This adjustment can improve your workflow, especially when managing multiple websites or applications on the same server.
We hope this guide has been helpful in assisting you with modifying the DocumentRoot in DirectAdmin. If you encounter any challenges or have further questions, feel free to reach out to our support team for assistance. Additionally, explore more of our tutorials and resources to optimize your hosting experience with Rackset. Your feedback is invaluable to us, so don’t hesitate to share your thoughts and suggestions.
Frequently Asked Questions
What is the DocumentRoot in DirectAdmin?
The DocumentRoot is the directory from which the web server serves files for a domain. In DirectAdmin, it typically defaults to the ‘public_html’ folder within a user’s home directory.
How do I change the DocumentRoot in DirectAdmin?
To change the DocumentRoot in DirectAdmin, you need to modify the ‘httpd.conf’ file for the specific domain. This involves accessing the server via SSH, locating the configuration file, and updating the DocumentRoot path to your desired directory.
Why would I need to change the DocumentRoot?
Changing the DocumentRoot can be necessary for organizing files, enhancing security, or running multiple applications from different directories under the same domain.
Is it necessary to restart the server after changing the DocumentRoot?
Yes, after changing the DocumentRoot in the configuration file, you must restart the web server to apply the changes. This ensures that the server reads the new configuration.
What precautions should I take before changing the DocumentRoot?
Before changing the DocumentRoot, ensure you back up your current configuration and files. Verify the new directory has the correct permissions and contains the necessary files to avoid downtime.

Leave a Reply