0

How can i get access to files in hostname/var/www/folder? I get an error saying not found - the requested URL /phpfiler(my created folder) was not found on this server?

2 Answers2

1

Establish a [folder] at /var/www

Change the directory owner and group:

sudo chown www-data:www-data /var/www/[folder]

Allow the group to write to the directory with appropriate permissions:

sudo chmod -R 775 /var/www

Add yourself to the www-data group:

sudo usermod -a -G www-data [user]
An0n
  • 2,225
0

Instead of adding yourself to a system group as suggested here I would recommend to just set your file ownerships to

 sudo chown <yourUser>:www-data -R /var/www

On this way you can set different permissions for your user and www-data on any file (or again on everything within a certain folder using -R as before):

The permissions you can set are

  • w write
  • r read
  • x execute (also needed to access folders)

A + grants the permission, a - revokes it.

=> So

  • to set your users' permissions on a file e.g.

    sudo chmod u+wr /path/to/file
    
  • to set www-data's permissions on a file e.g. only read permission

    sudo chmod g+r /path/to/file
    sudo chmod g-wx /path/to/file
    

The same methods also apply to folders so to allow the www-data group to write into a folder:

sudo chmod g+w /path/to/folder

and if you want also to be able to write to any file within that folder

sudo chmod g+w -R /path/to/folder

For accessing folders different from /var/www/html you'll have to add a redirection.

I'll quote from here (they did it for something in /home)

If you are using apache you'll have to create an alias that makes that images accesible via the web server.

Here comes an example for apache2

  Alias /img /home/path/to/images
  <Directory "/home/path/to/images">
     Order allow,deny
     Allow from all
  </Directory>

Place this configuration snippet in the proper place of your apache installation e.g. end of httpd.conf or a separate file. Don't forget to restart your webserver.

Now you should be able to access the images like:

<img style="vertical-align:bottom" src="http://www.myserver.com/img/buy_button.png"border="0" />
derHugo
  • 3,376
  • 5
  • 34
  • 52