Skip to main content

Change Linux/Ubuntu Webserver home directory

This guide explains how to change the root directory of a Linux web server by changing the default directory from /var/www/html to a different one.

Create new home directory

Example
sudo mkdir /home/user/MyWeb

Open Apache2 Config file

sudo nano /etc/apache2/sites-available/000-default.conf

Edit Apache2 Config file

<VirtualHost *:80>
#ServerName www.example.com
#ServerAdmin webmaster@localhost
DocumentRoot /home/user/MyWeb

<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost"
</FilesMatch>

ErrorLog /error.log
CustomLog /access.log combined
</VirtualHost>

Restart Apache2 Service

sudo service apache2 restart

Optional - Copy existing web files into new directory

sudo cp /var/www/* /home/user/MyWeb