Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save masudcsesust04/9e6e2b598e5eeab80dd80f2b5f54c1f1 to your computer and use it in GitHub Desktop.
Save masudcsesust04/9e6e2b598e5eeab80dd80f2b5f54c1f1 to your computer and use it in GitHub Desktop.
4 steps to change your apache default document root directory

Step - 1: Create a directory

$ mkdir /home/masud/www/

Step - 2: Open apache2 configuration file

$ sudo nano /etc/apache2/apache2.conf 
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Change it to

<Directory /home/masud/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        Allow from all
</Directory>

Step - 3: Open default virtual host configuration file from path

$ sudo nano /etc/apache2/sites-available/000-default.conf 
DocumentRoot /var/www/html

Change document root to

DocumentRoot /home/masud/www/

Step - 4: Finally restart apache

$ sudo service apache2 restart
@RedaBousserhane
Copy link

no working :/

Forbidden

You don't have permission to access this resource.
Apache/2.4.52 (Ubuntu) Server at ssh.kollchi.com Port 80

@JayGreentree
Copy link

no working :/

Forbidden

You don't have permission to access this resource. Apache/2.4.52 (Ubuntu) Server at ssh.kollchi.com Port 80

You have to add the www-data group to your directory:
https://paun.dev/2023/02/28/how-to-add-www-data-user-to-a-folder-in-home-directory/

@Hi-kue
Copy link

Hi-kue commented Jul 20, 2023

This is still not working for me

@ppazos
Copy link

ppazos commented Sep 17, 2023

This is still not working for me

chmod 755 /home/$user

change $user for your user

@Emile317
Copy link

This is still not working for me

chmod 755 /home/$user

change $user for your user

thanks a lot, this works

@Hi-kue
Copy link

Hi-kue commented Nov 23, 2023

This is still not working for me

chmod 755 /home/$user

change $user for your user

This works for me, thanks

@hoellthaler
Copy link

This is still not working for me

chmod 755 /home/$user

change $user for your user

Thanks to you and @masudcsesust04
It works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment