1

I just create new virtual host from path /media/rahul/142E875C2E873630/xampp/htdocs/ that's the path of my mounted drive in ubuntu. Now when I created virtual host of this url its created successfully but now, when I am opening my host url it's showing 403 Forbidden.

My shared.conf:

<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName shared
ServerAlias www.shared.com
DocumentRoot /media/rahul/142E875C2E873630/xampp/htdocs
<Directory />
    Options FollowSymLinks
    AuthType None
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
<Directory /media/rahul/142E875C2E873630/xampp/htdocs/>
    Require all granted
    Options Indexes FollowSymLinks MultiViews
    AuthType None
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

I have also add url in host file but still getting same error.

Is there any idea why this happening?

About Permissions:

enter image description here

  • Check permissions on the folders. Check the apache user (www-data?) has access to the destination folder. – psad Apr 16 '17 at 17:06
  • i just set permissions with sudo chmod -R 777 htdocs but still same error – Rahul Sharma Apr 16 '17 at 17:07
  • Whether the parent directories are readable for www-data? – pa4080 Apr 16 '17 at 17:20
  • i did not getting your point..actually this is my windows directory of xampp and i am trying to create virtual host of this directory so that i can do changes in the same directory whether i am using windows or ubuntu – Rahul Sharma Apr 16 '17 at 17:22
  • even i am not able to access another sda4 directory if i am setting the path of those directory /media/rahul/One/shared – Rahul Sharma Apr 16 '17 at 17:23
2

It is all about the permissions. The system user (www-data) who runs your web server must have read permissions to the folder htdocs and to the whole path to this folder.

Here I will describe three ways how that could be done:

  1. The short way - just give enough permissions;
  2. The proper (according to my knowledge) way - using terminal and /etc/fstab;
  3. The easiest proper way - using GUI tool Disks.

1. Just give enough permissions

For this purpose open a terminal window and type:

sudo chmod 755 /media/rahul/

Or give these permissions through Nemo as it is shown in the screenshot from the question. Please remember 777 is not the best choice.


2. Make the partition part of the static file system tree: /etc/fstab

Specify static mount point and mount the partition (device) with right permissions through /etc/fstab:

1. Create an appropriate mount point - open a terminal window and type:

sudo mkdir /mnt/shared

2. Find the necessary preliminary information:

  • Find the partition (device) identification. Type sudo blkid and recognize your target partition (device). Let's assume it is /dev/sda4 with UUID=142E875C2E873630.

  • Find your user's uid (user-id) and gid (group-id). In the terminal type: id. The result shall looks something like: uid=1000(rahul) gid=1000(rahul) groups=1000(rahul),..

    For further, more complicated permissions settings the data for some other users will be needed, for example id www-data will return: uid=33(www-data) gid=33(www-data),...

3. Edit your /etc/fstab file as root (using sudo) and add new line:

  • When the device/partition is formatted under NTFS this new line could be:

    /dev/sda4 /mnt/shared ntfs uid=1000,gid=33,nls=utf8,umask=0022,fmask=111 0 0
    

    Where:

    • /dev/sda4 the partition (device) - by /dev location or UUID - that contain a file system.
    • /mnt/shared the location where the above partition (device) will be mounted.
    • ntfs the type of the target device file system.
    • uid=1000,gid=1000 will set ownership permissions for user and group rahul; uid=1000,gid=33 will set ownership permissions for user rahul and group www-data.
    • nls=utf8 means Use UTF-8 for converting file names.
    • umask=0022 will set the permissions for all folders to drwxr-xr-x or octal 755.
    • fmask=111 will set the permissions for all files to -rw-rw-rw- or octal 666.
  • When the partition (device) is formatted under ext4 this new line could be:

    /dev/sda4 /mnt/shared ext4 default 0 0
    

    Ant the permissions of its content can be further managed as usual - chown, chmod, etc.

4. Save the edits of /etc/fstab, and reload it: sudo mount -a.

Important note! If this is an external (USB) device, if it is unplugged, an error will be appeared. The solution is: 1) Go to Recovery mode, 2) edit /etc/fstab and 3) comment (#) the line described above.


3. Make the partition part of the static file system tree: Disks

1. Open Dash and type Disks:

enter image description here

2. Find your target device and select Edit Mount Options:

enter image description here

3. Edit Mount Options and click on OK:

enter image description here

4. Mount the device - click on the Play button:

enter image description here


Further steps

1. Find the new location of your htdocs folder. It should be something as:

/mnt/shared/xampp/htdocs

2. Edit your shared.conf file:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName shared
    ServerAlias www.shared.com
    DocumentRoot /mnt/shared/xampp/htdocs
    <Directory />
        #etc ...
    </Directory>
    <Directory /mnt/shared/xampp/htdocs/>
        #etc ...
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined   
</VirtualHost>

3. Restart Apache2 and try to access your site.


Sources and further reading

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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