Israel Science and Technology Directory

Internet Apache2 server

3. Set up directory permissions and ownership

Updated on December 14, 2025.

Apache2 server uses /var/www/html as the default directory for hosting a website. This directory is not under the user Home directory (/home/$USER/), and running Bash commands in it requires preceding each command with sudo as root.
Note: In Linux, $USER is a variable that has the name of the currently logged in user.

For various reasons, some users prefer to setup the localhost directory under the home directory, for example, /home/$USER/example.com. However, this option may lead to many "403 -Access Forbidden" errors, preventing display of pages as a result of Apache's security restrictions on /home directory. Therefore, setting the default directory under /home/$USER/ is not recommended.

1. Change the owner of the directory to $USER

As noted above, the default owner of the /var/www/html directory is root. To edit the pages in the directory, change the owner from root to your user name entering the following command in a terminal:

sudo chown -R $USER:www-data /var/www/html

In Linux, each file has an owner and a group. This command sets $USER as the user, and sets $www-data as the group. In Linux, www-data is a standard name used for user and group in web servers.

The "-R" option that follows chown specifies recursive change of ownership of all files and subdirectories.

2. Set read and write permissions for each directory and file

Prior to this task you may need to read an introduction to Linux permissions.

Set directory permissions to 755 (string notation rwxr-xr-x):

sudo find /var/www/html -type d -exec chmod 755 {} \;

Set file permissions to 644 (string notation -rw-r--r--):

sudo find /var/www/html -type f -exec chmod 644 {} \;