403 forbidden error in Apache with document root on an NTFS partition
I'm a beginner in Ubuntu hoping to find a better web development environment than WIndows. I'm trying to access http://localhost
but its always giving me a forbidden error. I've installed php, mysql, and apache separately. Files/web_files
is also my web directory in windows which when I access on windows is D:/Files/web_files
and on ubuntu is media/Files/web_files
. I also restart apache after editing the default
file located in etc/apache2/sites-available
Am I editing the wrong file? Please help.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /media/Files/web_files
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /media/Files/web_files/>
Options FollowSymLinks
AllowOverride All
order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Update
If I used var/www
instead it works like magic.
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
order allow,deny
allow from all
</Directory>
Here's the output from the mount
command
/dev/loop0 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
/dev/sda2 on /host type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,blksize=4096)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon on /home/wern/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=wern)
/dev/sr0 on /media/2022_21092011 type udf (ro,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,iocharset=utf8,umask=0077)
/dev/sda3 on /media/Files type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096,default_permissions)
/dev/sda1 on /media/System Rese
And here's the output from ls - laR/media
ls: cannot access -: No such file or directory
ls: cannot access laR: No such file or directory
/media:
2022_21092011 Files System Reserved
So I'm wondering if this is an issue in the filesystem or its permissions. But I don't think it has something to do with permissions since I can perfectly edit the files in media/Files/web_files
without having to run it as a superuser.
Thanks for those who has taken their time to help me so far.
It appears that your Windows drive D is mounted at /media/Files
In that case, your files are actually in /media/Files/Files/web_files
. Please try editing the default sites-available file with that path, restart Apache with sudo service apache2 restart
and see if it works.
Additionally, as Marty notes in the comments, it appears Nautilus mounts NTFS partitions with odd permissions so that no user but yourself (and root, of course) can read or write from/to it.
To solve that, close all Nautilus windows, stop apache2, open a terminal and do the following:
sudo umount /dev/sda3 mkdir /media/DriveD sudo ntfs-3g /dev/sda3 /media/DriveD
Now start apache2
and see if it works. If it does, it's best to put the mount in /etc/fstab
as Marty noted.
If you don't want to edit your /etc/fstab file, do this
-
Open a terminal and type
udisks --mount /dev/sda3 --mount-options umask=022
I suppose, your partition was already labeled as "Files". In this case, it will be mounted to /media/Files
directory. Then you can execute php files in them. But if it is not labeled as "Files", I recommend to do so by using disk-utility
. Or if you prefer not labeling, change your etc/apache2/sites-available/default
file, to the actual mount point.
Note: If you do not have a label with the partition, It will get mounted in /media/xxxx....
folder, where xxxx... is the UUID of the partition.
Credit goes to this answerer
Is your drive getting mounted at the time apache runs? I don't know if the automatic mounting will be sufficient or not, but if there is a problem, you may want to explicitly mount the drive is /etc/fstab
. I'm pretty sure that this automatic mounting is only done on demand; it isn't mounted until you open it in Nautilus, then it mounts.
I did a test with an NTFS partition mounted by opening in Nautilus, and it does not have permissions set for anyone other than the owner and the owner's group, so this is most likely the source of the problem. You will need to set the mount permissions so that everyone has read and execute (r-x
) permission for the partition. Do you know how to mount drives in `/etc/fstab' or any other method. There is some detailed instructions here.
The basics are that you need to create a directory to mount the partition, traditionally as a subdirectory of /mnt/
, not /media/
; /media/
is traditionally used for auto-mounted devices, like when you open an unmounted device in Nautilus, or for CD/USB drives.
Create the Directory
The directory you create should have the permissions and owner you desire; I usually set the owner to myself, with read only permissions for the rest of the universe (drwxr-xr-x). This directory should be empty, but doesn't have to be. But any files will be inaccessible when something is mounted to it. To create and set the permissions for this directory (change LOGIN_NAME to your login name):
cd /mnt
sudo mkdir Files
sudo chown LOGIN_NAME:LOGIN_NAME Files
sudo chmod 755 Files
Edit fstab
You then create an entry in the file /etc/fstab
to mount the partition to this directory. This is normally pretty straightforward, although for NTFS, some extra information is required to set up the owner and permissions. The line I use for NTFS is this (all on one line):
UUID=0000000000000000 /mnt/Files ntfs-3g auto,users,uid=LOGIN_NAME,gid=LOGIN_NAME,utf8,dmask=002,fmask=113 0 0
Notes: substitute the correct UUID for 0000000000000000; the UUID is obtained by entering the commandline sudo blkid
in the terminal. Also, substitute your login name for LOGIN_NAME.
Edit Apache configuration file
Then, in the file /etc/apache2/sites-available/default
, change the DocumentRoot that was originally /var/www/
to /mnt/Files/web-files
. Also, make the same change for your web site directory. This assumes that there is a directory /web-files/
in the root of the partition mounted in /mnt/Files/
.
Also, make sure you have an HTML/PHP file in the document root directory (.../web-files
)? It needs to be something like index.html, or index.php. Did you copy the files from /var/www/
to this directory?
Try keeping Apache root directory at the linux native partition (/var/www/html
) and do mounting instead, ie:
mount -o bind /media/Files/web_files /var/www/html/web_files
Keep in mind that folder web_files
must exist under folders /var/www/html/
and it has sufficient attributes for reading it.