Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
are you mounting drive D under /media/Files? –  izx Jul 15 '12 at 3:36
    
yes I guess its mounted since when I right click on the drive it says unmount. –  Ieyasu Sawada Jul 15 '12 at 3:38
    
This is a permission problem. www-data does not have permission to access the /media/Files/web_files. –  Manula Waidyanatha Jul 15 '12 at 3:42
    
@ManulaWaidyanatha: what do I do to make it accessible? –  Ieyasu Sawada Jul 15 '12 at 3:48
    
@ManulaWaidyanatha: why is that? On my system, /var/www is owned by root, and the group is root; the group permissions are the same as the permissions for everyone, and there is no mention of "www-data" anywhere. The directories in /media seem to have the exact same permissions as /var/www. –  Marty Fried Jul 15 '12 at 5:02
show 6 more comments

5 Answers 5

up vote 3 down vote accepted

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

share|improve this answer
    
he has already done that and the path you have posted is wrong "Files/Files" –  Manula Waidyanatha Jul 15 '12 at 3:47
    
is that the case? but I can actually access a file from the terminal when I do: gedit /media/Files/file.txt –  Ieyasu Sawada Jul 15 '12 at 3:48
    
@IeyasuSawada: Please share the content or output of the following commands/files to better help us troubleshoot your problem (instructions in this answer): command(s): mount, ls -laR /media –  izx Jul 15 '12 at 3:50
    
@ManulaWaidyanatha: Wubi does not mount NTFS drives at /media by default -- it's always under a subfolder. –  izx Jul 15 '12 at 3:52
1  
@IeyasuSawada: the issue is the permissions and path, NOT whether the files are there or not... –  izx Jul 15 '12 at 5:06
show 21 more comments

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?

share|improve this answer
    
it appears that its a problem in the filesystem because if I use /var/www as the web directory it works. Maybe I need to set permissions or something but I don't know how to do it. Please help. –  Ieyasu Sawada Jul 15 '12 at 4:05
1  
    
I've already edited the 000-default file. I still can't access localhost when I use /media/Files/web_files as document root but I can access it when I used /var/www as document root. –  Ieyasu Sawada Jul 15 '12 at 4:17
    
The permissions should be OK, I would think. what filesystem does the partition use - FAT32, NTFS? –  Marty Fried Jul 15 '12 at 4:23
    
It's using NTFS –  Ieyasu Sawada Jul 15 '12 at 4:26
show 4 more comments

The DocumentRoot needs to be changed in two apache configuration files:

/etc/apache2/sites-available/default
/etc/apache2/apache2.conf
share|improve this answer
add comment

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.

share|improve this answer
add comment

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-3g

Find the name of your NTFS partition(s). Example:

$ sudo fdisk -l | grep NTFS

Get 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/fstab

I 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 0

Note that you may need to create /media/windows directory if it doesn't exist.

$ cd /media
$ sudo mkdir windows
$ sudo chown sagun:users windows

Reboot 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.dev

Create a new config file inside /etc/apache2/sites-available directory. Example:

$ sudo vim /etc/apache2/sites-available/projects.dev

Set your configuration similar to this and save the file:

<VirtualHost *:80>
    ServerAdmin webmaster@projects.dev
    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}/projects.dev/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/projects.dev/access.log combined
</VirtualHost>

Next, edit the /etc/hosts file.

$ sudo vim /etc/hosts

Add the following line and save:

127.0.0.1 projects.dev

Activate the host with the following command:

$ sudo a2ensite projects.dev

Restart Apache

$ sudo service apache2 restart

Finally I was able to go to http://projects.dev from my Browser with all my code residing in NTFS partition from both Windows and Ubuntu. I hope someone finds this useful. Cheers!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.