4

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.

ish
  • 139,926
  • are you mounting drive D under /media/Files? – ish Jul 15 '12 at 03:36
  • yes I guess its mounted since when I right click on the drive it says unmount. – Wern Ancheta Jul 15 '12 at 03: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 03:42
  • @ManulaWaidyanatha: what do I do to make it accessible? – Wern Ancheta Jul 15 '12 at 03: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 05:02
  • Hi, do a ls -l /var/www and ls -l /media/Files you will see that /media/Files is only accessible for owner, but www is accessible by others as well – Manula Waidyanatha Jul 15 '12 at 05:07
  • I don't have /media/Files. I only have ext4 partitions available for /media, and they have the same permissions as /var/www. But this is why I suggested he explicitly mount the drive, so he could set the permissions to exactly what he needs. – Marty Fried Jul 15 '12 at 05:13
  • I just tested with NTFS, and it does not have the same permissions as ext4, so that is probably his problem. I edited my answer for this information. – Marty Fried Jul 15 '12 at 05:29
  • @MartyFried I've added this line in /etc/fstab #Windows-Partition UUID=7258CB9858CB598D /media/Files rw,auto,users,exec,nls=utf8,umask=003,gid=46,uid=1000 0 2 do I need to restart ubuntu for the changes to take effect? – Wern Ancheta Jul 15 '12 at 05:36
  • No, it's best not to. You can test it by entering this at a commandline in the terminal: sudo mount -a, and it will mount everything in /etc/fstab. If there is an error, you will see it right away, and have a chance to fix it or disable it. – Marty Fried Jul 15 '12 at 05:59
  • Oh, and the directory will need to exist in order to mount there. Usually, you mount in /mnt/somedirectory rather than /media/, but I think it will work if you make sure it's not currently mounted by the system, then create the directory and mount it. But if it were my system, I'd mount it in /mnt, and change the apache config file to match. – Marty Fried Jul 15 '12 at 06:07

7 Answers7

4

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

ish
  • 139,926
3

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?

Marty Fried
  • 18,466
  • 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. – Wern Ancheta Jul 15 '12 at 04:05
  • 1
    check this http://unix.stackexchange.com/questions/14671/mounting-an-ext3-fs-with-user-privledges – Manula Waidyanatha Jul 15 '12 at 04:07
  • 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. – Wern Ancheta Jul 15 '12 at 04:17
  • The permissions should be OK, I would think. what filesystem does the partition use - FAT32, NTFS? – Marty Fried Jul 15 '12 at 04:23
  • It's using NTFS – Wern Ancheta Jul 15 '12 at 04:26
  • I edited my answer, but did you copy the HTML or PHP file from /var/www to this new directory? Perhaps there is no default file to open? – Marty Fried Jul 15 '12 at 04:29
  • @MartyFried yes I copied it. – Wern Ancheta Jul 15 '12 at 04:29
  • Is this partition mounted at the time you start or restart apache? I think it is only mounted when you open it in Nautilus, so you would need to open it explicitly first, then restart Apache. It's probably best to mount it at startup in /etc/fstab, where you can also set permissions and ownership exactly how you want. It's really not too hard to edit this file, although I believe there may be a newer way to mount the drive that I've never used. – Marty Fried Jul 15 '12 at 04:42
  • @ManulaWaidyanatha: he is on NTFS, your link refers to ext3 – ish Jul 15 '12 at 05:07
1

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-data

To your username

export APACHE_RUN_USER=youruser
export APACHE_RUN_GROUP=youruser

Restart apache, done.

nodws
  • 111
1

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.

Janosik
  • 11
  • 2
1

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

http://www.tbogard.com/2014/09/12/making-apache-server-to-read-a-partitioned-disk-the-definitive-solution/

Erick
  • 31
0

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

/etc/apache2/sites-available/default
/etc/apache2/apache2.conf
Braiam
  • 67,791
  • 32
  • 179
  • 269
0

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!