How to Change the Root Directory on a VPS?
Changing the root directory on a VPS might be necessary in various situations, such as when migrating a website or changing the file system structure. To do this, you need to follow a few simple steps.
Step 1: Installing the Necessary Utilities
The first step is to install the necessary utilities. To do this, connect to the server via SSH and run the following commands:
sudo apt update
sudo apt install vim
Step 2: Modifying the Apache Configuration File
Next, you need to edit the Apache configuration file. To do this, run the following command:
sudo vim /etc/apache2/sites-enabled/000-default.conf
In the opened file, find the DocumentRoot line and change it to the new path to the root directory. For example:
DocumentRoot /var/www/html/new_directory
Save the changes and restart Apache with the command:
sudo service apache2 restart
Step 3: Changing Access Permissions
To ensure that the access permissions to the new root directory are set correctly, run the following command:
sudo chown -R www-data:www-data /var/www/html/new_directory
Now the root directory has been successfully changed on the VPS. Check the website to ensure that everything is working correctly.