Good Morning,
I am currently setting up and apache2 server on my raspberry pi. My index.html file is in the directory /var/www/html and the file is loading fine when I go to the IP address. However, the images located in /var/www/html/img are not loading. The html is like this: <img alt="image1" src="img/picture1.png">. When I right click on the alternative image icon, and select open image in new tab, I get:
You don't have permission to access /img/picture1.png on this server.
Server unable to read htaccess file, denying access to be safe
How can I prevent this and make the user able to access the image?
Many thanks,
Try
chmod -R 755 /img/
this will set the permission for all files in the folder readable and executable for all, and also writable by the owner.
The output will be in the form
-rwxr-xr-x 1 root root 0 Apr 5 12:38 picture1.jpg
Related
I have installed Apache 2.4 on Ubuntu 16, all works.
I have a website sitting on localhost, this also works fine.
I need to be able to access files on a USB drive to use within the website.
I'm using PHP to access the USB drive and obtain information of files, this works fine, however the issue arises when I try to display an image on the web page.
I'm using the .htaccess file and trying to use mod_alias to add a folder on the USB drive into the website, here is the content on my .htaccess file
DirectoryIndex index.php
Alias "/USB" "/mnt/sdb1/images"
<Directory "mnt/sdb1/images">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AddType audio/mpeg .mp3
So I know the .htaccess file is working because it loads my index.php file as the main file when I go to LocalHost.
I know the file path of the USB drive is correct because the PHP script has accessed it and collected the image files to display on the page, so PHP uses scandir to get all of the images in a folder (/mnt/sdb1/images) and it echos to the page correctly to show the images, for example;
<img src="/USB/image1.jpg" />
But the images aren't loading on the page itself and I presume it's because the Alias doesn't appear to be working.
Please help.
One possibility is that you need to grant www-data access to the USB files. Usually in Apache directories, you set the owner to something like:
chown root:www-data *
chmod 750 * (for directories)
chmod 640 * (for files)
But, you may not be able to do that on a USB drive (sorry, never dealt with USB), but if it is a particular group, you could add www-data to that group:
sudo usermod -a -G <USBGroup> www-data
So, for example, I have a shared drive on my Virtual Machine (/media/sf_node), which I am guessing works a lot like a USB drive. So when I run the following command:
ls -la /media/sf_node
I see:
drwxrwx--- 1 root vboxsf 4096 Jan 27 11:10 web
That shows the group vboxsf for that directory. Then I can do a:
usermod -a -G vboxsf www-data
I'm using Ubuntu 14 server from DO, with LAMP stack installed, i followed the instruction here to install flask on ubuntu because my main purpose was to use Flask on my website.
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
During the test, when user connects to "http:/myvpsip/createfile/" which creates a new file on the current folder /var/www/, I got error from Apache saying that the file cannot be created, "permission denied".
I tried again using PHP script that create a new file on the same directory /var/www/ but got the same problem. Both of the trials were done using root account. I tried to chmod the www folder to 755 or 777 and they are not working.
My question is, how do I set permission for apache2 that when users browse the website they will be able to create/edit file on the current directory?
Thank you
This is because when you installed your application, you did so as the root user. All your application files and directories are owned by root.
If you ls -l on /var/www and look inside the FlaskApp folder structure, you will likely see permissions set like this:
-rw-r--r-- 1 root root
When Apache runs, it runs on behalf of a main process owned by the user root and several child processes owned by the user www-data. So essentially, Apache is running as if logged in as user www-data.
When your application needs to do a file or folder operation (its running on behalf of Apache www-data user), the public/world permission bits are used since Apache child processes are not running as root user and not as root group.
Looking above, we see that only the read bit is set for the public/world permissions - no write. And that is where the problem lies.
One way to solve this is to make everything under /var/www/mywebsite owned by the user root and the group www-data. This sets things up so that only the root user can have full permissions and www-data (everyone else) can only read and execute (no write).
When you setup your website, you should set it up to be under its own separate folder. This way you can have multiple virtual domains (i.e. more websites) added later on. Assuming 'mywebsite' is where your domain is and you have already installed your application software (Flask) within it:
cd /var/www/mywebsite
chown -R root:www-data /var/www
You then as the system administrator, need to understand the application and go through the folders and files setting permissions. Apply permissions generally, then on a case by case basis.
For most directories (750)
- Only root can rwx directory
- www-data can only read and execute directory
- no public/world bits set as it makes no sense (*)
For directories that can be changed by web application (770)
- Root can rwx directory
- www-data can rwx directory
- no public/world bits set as it makes no sense (*)
- for uploading files, creating images, documents, etc by the users of the site
For most files (640)
- Never set the execute bit to avoid execution of misplaced shell or executable files
- PHP, Perl, etc. are just text files. They have nothing to do with exec permission
- No group write bit set
- Read must be set for owner and group else they cant see the web document
For special case where files need to be changed (660)
- Set group write bit if you want www-data users to create things
(*) Because all users who visit Apache are running on behalf of www-data
I'm newbie in the web development, and I'm trying to make a website. So, my website works fine on the server but not on my own (Apache). My sources are in ~/public_html/. The problem is I don't have permissions on the sub/sub directory, I mean, when it's a directory, it works fine, when it's directory in a directory, it doesn't. (403 Forbidden). I don't change my default Apache configuration excluding for include mysql and php.
All my directories have the same permissions. Maybe I need to configure something for that?
Thanks
I used this little script found at this link http://boomshadow.net/tech/fixes/fixperms-script/
Fixperms – for one single user
To use the fixperms script, simply log into your server as root, wget the file from our server, then run it. Type in the cPanel username and it will run only for that particular account.
It does not matter which directory you are in when you run fixperms. You can be in the user’s home directory, the server root, etc. The script will not affect anything outside of the particular user’s folder.
Should be done in SSH
root#example [~]# wget boomshadow.net/tools-utils/fixperms.sh
root#example [~]# sh ./fixperms.sh -a USER-NAME
Fixperms – for all of the users
If you would like fix the permissions for every user on your cPanel server, simply use the ‘-all’ option:
root#example [~]# wget boomshadow.net/tools-utils/fixperms.sh
root#example [~]#sh ./fixperms.sh -all
Maybe it is not a right channel to ask this question but I donot know where to ask.
I want to know how to run html file with apache on my ubuntu. I have written program with javascript and a html file and I want to run it via apache. I could not find htdocs folder in to copy my files there beside that I do not have permission to do that in ubuntu. My apache is installed in /usr/share/apache2.
When I write http://localhost it says:
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
but I do not know where to add the contents.
any help.
The default folder that it serves the HTML files from is /var/www.
For example, /var/www/test.html would be http://localhost/test.html.
In my case where I have installed and running the Apache 2 and if I type localhost/ into the browser it opens the Apache 2 Ubuntu default Page.
Now what I did was:
Suppose your HTML webpage Demo.html is located in the Website directory then copy the HTML page using one of the commands:
:~$ cp ~/Website/Demo.html /var/www/html
If this command does not work then try with the following command:
:~$ sudo cp ~/Website/Demo.html /var/www/html
And then open your browser and type this the browser search bar:
localhost/Demo.html
It will open the copied Demo.html.
Also if you want to access this hosted webpage from the outside of the machine where Apache 2 is running then use it's external IP address instead of localhost as follows:
ExternalIP/Demo.html
I am trying to have Apache follow a symlink to a raid array server that will contain some large data files. I have tried modifying httpd.conf to have an entry like this
<Directory "/Users/imagine/Sites">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
to have Apache follow any sym link in the Sites folder.
I keep getting an error return that seems to indicate I don't have any permissions to access the files. The error is:
Forbidden
You don't have permission to access
/~imagine/imageLibraryTest/videoClips/imageLibraryVideos/imageLibraryVideos/Data13/0002RT-1.mov
on this server.
The sys link file is the last "imageLibraryVideos" in the line with the Data13 being the sub dir on the server containing the file.
The 0002RT-1.mov file hase these permissions:
-rwxrwxrwx 1 imagine staff 1138757 Sep 15 17:01 0002RT-1.mov
and is in this path:
cd /Volumes/ImagineProducts-1/Users/imagine/Sites/imageLibraryVideos/Data13
the link points to:
lrwxr-xr-x 1 imagine staff 65 Sep 15 16:40 imageLibraryVideos -> /Volumes/ImagineProducts-1/Users/imagine/Sites/imageLibraryVideos
I had the same problem last week and the solution was pretty simple for me.
Run:
sudo -i -u www-data
And then try navigating the path, directory by directory. You will notice at some point that you don't have access to open the dir.
If you get into the last directory, check that you can read the file (with head for example).
Look in the enclosing directories. They need to be at least mode 711. (drwx--x--x)
Also, look in /var/log/apache2/error_log (Or whatever the concatenation of ServerRoot and ErrorLog is from the httpd.conf) for a possibly more-detailed error message.
Finally, ensure you restart apache after messing with httpd.conf.
You should also look at bind mounts rather than symlinks - that would allow you to remount a given path at a new point. The following is an example:
mount --rbind /path/to/current/location/somewhere/else /new/mount/point
You can also edit your fstab to do this at boot:
/path/to/original /new/path bind defaults,bind 0 0
This is a permissions problem where the user that your web server is running under does not have read and/or execute permissions to the necessary directories in the symbolic link path. The quick and easy way to check is to su - web-user (where web-user is the user account that the web server is running under) and then try to cd into the path and view the file. When you come across a directory that you don't have permission to enter, you'll have to change the permissions and/or ownership to make it accessible by the web server user account.