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 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>UpdateIf 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 ReseAnd 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 ReservedSo 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.
7 Answers
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
26Is 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 FilesEdit 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_filesKeep in mind that folder web_files must exist under folders /var/www/html/ and it has sufficient attributes for reading it.
Personally I didn't tried on NTFS, but this saved me:
The only thing you need to do is :
<Directory "/www/mywebdirectoryinapartitioneddisk"> Require all granted
</Directory>this will solve the issue
here the post in my blog explaining everything in detail. It could work on NTFS
For everyone who doesn't want to deal with mounting and remounting partitions just make sure you have the correct mount path in apache.conf and 000-default.conf then edit /etc/apache2/envvars
Modify the www-data
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-dataTo your username
export APACHE_RUN_USER=youruser
export APACHE_RUN_GROUP=youruserRestart apache, done.
1The DocumentRoot needs to be changed in two apache configuration files:
/etc/apache2/sites-available/default
/etc/apache2/apache2.conf Here are the steps I did to overcome the same error. My situation was that I wanted point to my Windows Dropbox projects folder while coding using Ubuntu.
Settings for NTFS partition
First you need to be able to access your NTFS partition via Ubuntu. Do the following steps if you haven't.
$ sudo apt-get install ntfs-3gFind the name of your NTFS partition(s). Example:
$ sudo fdisk -l | grep NTFSGet the UUID of your NTFS partition.
$ sudo blkid/dev/sda1: LABEL="windows" UUID="4ED2A451B2A23F59" TYPE="ntfs"
Configure the partition in /etc/fstab (make a backup just in case).
$ sudo cp /etc/fstab /etc/fstab.bak
$ sudo vim /etc/fstabI created mine as follows (based on the UUID. The following options set read, write, execute permissions and uid=1000 sets you as the user of the NTFS partition during OS boot. This will also ensure that Apache user can access your virtual host direction (this is what solved my problem).
/dev/disk/by-uuid/4ED2A451B2A23F59 /media/windows ntfs-3g defaults,permissions,users,uid=1000,utf8 0 0Note that you may need to create /media/windows directory if it doesn't exist.
$ cd /media
$ sudo mkdir windows
$ sudo chown sagun:users windowsReboot your computer and confirm that your NTFS drive automounts with read, write, execute permissions enabled.
Settings for configuring Virtual Host in Apache
Create directories to place your log files (if you want):
$ sudo mkdir /var/log/apache2/projects.devCreate a new config file inside /etc/apache2/sites-available directory. Example:
$ sudo vim /etc/apache2/sites-available/projects.devSet your configuration similar to this and save the file:
<VirtualHost *:80> ServerAdmin ServerName projects.dev ServerAlias projects DocumentRoot /media/windows/Users/sagun/Dropbox/projects <Directory /> Options FollowSymLinks AuthType None AllowOverride None Order deny,allow Deny from all </Directory> <Directory /media/windows/Users/sagun/Dropbox/projects/> Options Indexes FollowSymLinks MultiViews AuthType None AllowOverride None Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/ LogLevel warn CustomLog ${APACHE_LOG_DIR}/ combined
</VirtualHost>Next, edit the /etc/hosts file.
$ sudo vim /etc/hostsAdd the following line and save:
127.0.0.1 projects.dev
Activate the host with the following command:
$ sudo a2ensite projects.devRestart Apache
$ sudo service apache2 restartFinally I was able to go to from my Browser with all my code residing in NTFS partition from both Windows and Ubuntu. I hope someone finds this useful. Cheers!