DocumentRoot 403 Forbidden

Hi there,

I am trying to change my DocumentRoot “/srv/http” to “/home/username/Web/var/www” but getting a forbidden error (403).
I’ve changed the value of DocumentRoot to my desired destination in /etc/httpd/conf/httpd.conf and also used chmod o+x Web. But the result remains the same.

Thank you.

Access forbidden!

You don’t have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.

Error 403

Apache/2.4.46 (Unix) PHP/7.4.10

It is because the http user is not allowed to access your Home folder.

If you don’t care about security simply make sure your Home ( /home/username/ ) folder can be accessed by every user on your system or just by the http user with a group setting.

If you do care about security place the webroot in a folder you and the http user can access and place it not in your Home. Or run the Webserver as your user (not recommend).

I do care about security. It’s just that, I’m new to using linux and the IDEs I’m trying to use to code can’t modify the files in the /srv/http directory. What dir can I use to code without being root which is accessible by apache as well and to not compromise security?

You can use nearly every folder you want if it is not in your Home. For example /mycoolproject or if you don’t want to create a folder in / , maybe use /srv/mycoolproject

You need root privileges to create is folder, but after that appoint it to your user and group. Make sure “others” can access it. Also all files and folders in that project folder need to readable by the http user.

For example

sudo mkdir  /srv/mycoolproject
sudo chown $USER:$GROUP /srv/mycoolproject

the $GROUP variable is not a default, it might not work on your system.

and just to be sure

chmod o+rx /srv/mycoolproject

After that you should be able to place files and folders in that directory. Make sure the files and folders are also readable for the http user.


If this is just for development and you run your Websever on localhost, there is nothing wrong with starting httpd as your user. So you could use a folder in your Home as a webroot.

1 Like

It worked! Thanks a lot. Also, how can I run httpd with user? When using systemctl start httpd, it prompts me to be root.

httpd by default always starts as root. It is necessary to bind to port 80. After that it drops privileges and runs as the user and group specified in /etc/httpd/conf/httpd.conf

If you really want you could create your own systemd file or even a systemd user service that starts httpd without root. But you can’t use port 80.