Ok, so I have just set up a server using Ubuntu Server 12.04 but I have hit a bit of a brick wall when attempting to view webpages.
I chown'ed the /var/www folder so I could add my files to it and all is working fine from this front but it comes to when I try and display the webpage. My server doesn't seem to like accessing the folders for example in my main folder (/var/www) I have the index and then three other folders, StyleSheets, Resources, and Pages.

When accessing the website, the index.php page displays as if it doesn't have a stylesheet attached to it and when attempting to access one of the folders or pages using I get a 403 Forbidden which if I am not mistaken means that there isn't the appropriate permissions for Apache to view them.

How would I be able to allow Apache access to all the folders?
Thank you

Dani AI

Generated

As described, Apache is serving the index but linked assets and subfolders return 403 (forbidden). and correctly pointed at ownership/recursion as a common root cause. Ownership is one piece of the puzzle; other frequent causes include missing execute bits on directories, Apache directory access directives (different between Apache 2.2 and 2.4), .htaccess denies, AppArmor profile blocks on Ubuntu, and simple path/case mismatches that make CSS links fail.

Useful diagnostic commands (examples):

ls -ld /var/www /var/www/Pages
stat -c '%U:%G %a %n' /var/www/Pages/Login.php

Set safe, standard permissions (directories need the execute bit; files must be readable):

find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;

To avoid changing ownership every time, make the developer account a member of Apache’s group:

sudo usermod -aG www-data <username>
# then re-login the shell session for group changes to take effect

Apache config and .htaccess: a Directory block without the proper allow directive will cause 403. Example syntax for both Apache versions:

# Apache 2.4
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

# Apache 2.2
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Check logs, AppArmor and HTTP headers:

tail -n 50 /var/log/apache2/error.log
curl -I http://192.168.0.11/StyleSheets/style.css
sudo aa-status
sudo service apache2 restart

Look for "permission denied" messages in the error log or AppArmor denials; confirm the browser’s network inspector shows 403 vs 404 (case-sensitive filenames on Linux are a common gotcha). Avoid world-writable permissions (0777); prefer group-based access and minimal privileges. These combined checks usually surface the exact cause when ownership alone does not.

Recommended Answers

All 2 Replies

Make sure that your chown command has the -R flag for recursive, otherwise it's not going to be able to work.

chown -R www-data.www-data /var/www/
<SNIPPED URL>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.