3

so here is the issue: I'm running phpmyadmin to administrate my localhost server,now I've put my project files in the path: /var/www/html/user/register.html I am using Ubuntu OS Everyting seems perfect when accessing to my 'register.html' from this url: file:///var/www/html/user/register.html However when I try to access to the same file from localhost server, This url:'localhost/user/register.html' ,my images are not showing up in the webpage,everything else in the css is good, I tried everything I could think of, changed directories etc.. I googled this for whole morning, but found nothing! can you please help me with this guys...

PS: the images path is correct since they show up when accessing from the first url.

EDIT: I am new to the forum, excuse my lack of experience here, and I put the html/css code below, for the css, I've only put the part of the image

body
{
 background-image: url('pics/1.jpg');
 background-attachment: fixed;
}
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <title>Registration form</title>
 <link rel="stylesheet" href="style1.css">

</head>
<body> 

 <header>
  <div id="sign">
  <a href="#0">Register</a> \\ <a href="signup.html">Sign Up</a>
  </div>
 </header>
 <div class="formulaire">
 <h2>Registration form:</h2>
  <form action="register.php" method="post" >
   
   <label for="first">First name</label><input class="inputs" type="text" name="FIRST_N" id="first"><br><br>
   
   <label for="last">Last name</label><input class="inputs" type="text" name="LAST_N" id="last"><br><br>

   <label for="birth">Birthday date</label><input class="inputs" type="date" name="B_D" id="birth"><br><br>

   <label for="gender">Gender</label>
    <select class="inputs" name="GENDER" id="gender">
     
     <option selected="selected"></option>
     <option>MALE</option>
     <option>FEMALE</option>
    
   </select><br><br>

   <label for="user">Username</label><input type="text" name="USERNAME" id="user" class="inputs"><br><br>

   <label for="pass">Password</label><input class="inputs" type="password" name="PASS" id="pass"><br><br>

   <label for="rpass">Retype password</label><input class="inputs" type="password" id="rpass"><br><br>

   <label for="phone">Phone number</label><input class="inputs" type="text" name="PHONE" id="phone"><br><br>

   <div id="buttons">
    <input class="but" type="submit" name="SUBMIT" value="Sign In">
    <input class="but" type="reset" name="RESET" value="Reset">
   </div>
  </form>
 </div>


</body>
</html>
giorgio
  • 10,111
  • 2
  • 28
  • 41
Yassir Khaldi
  • 1,452
  • 1
  • 17
  • 30
  • 3
    share your `css` code – Afsar Nov 30 '15 at 11:58
  • Where's your code? At the very least we need to see an example `img` tag. – Shaggy Nov 30 '15 at 12:02
  • Ok sorry I'll provide it – Yassir Khaldi Nov 30 '15 at 12:04
  • could be a permissions problem. Eg. `640`, which allows your ubuntu user to open/read the images, but not user `apache`. Check in dev tools what error message you get. If it's a `404`, the url is not correct (or apache is not configured correctly). If it's `403` it's a permissions problem. If it's `500`, check your error log en post back. – giorgio Nov 30 '15 at 12:06
  • @giorgio hello thanks for the suggest, how can I check the dev tools error please? – Yassir Khaldi Nov 30 '15 at 12:12
  • Depends on your browser. In Chrome and FF: ctrl+shift+i. Safari I don't know, but google will surely [help](https://www.google.com/search?q=safari+developer+tools) you here. And don't use IE for development. Just don't. – giorgio Nov 30 '15 at 12:17
  • oh and look in the network tab, or just check the console for errors – giorgio Nov 30 '15 at 12:18
  • @giorgio ok I looked in var/apache2/log.ini and Found this particular line [Mon Nov 30 11:43:37.647781 2015] [core:error] [pid 1236] (13)Permission denied: [client ::1:60638] AH00132: file permissions deny server access: /var/www/html/user/pics/1.jpg, referer: http://localhost/user/style1.css – Yassir Khaldi Nov 30 '15 at 12:18
  • 1
    yup, thought so. Run this in terminal and you should be good: `chmod 644 /var/www/html/user/pics/1.jpg` – giorgio Nov 30 '15 at 12:19
  • @giorgio Thank you! it worked! BTW, do I have to set this code for every image in my webpage? Ok I'll look it up anyways thanks again! – Yassir Khaldi Nov 30 '15 at 12:21
  • dunno, depends on your settings. run `umask` in the terminal. If it is higher then `0022` you should indeed either change the default settings, or alter the permissions by hand everytime. For more background, check [this old answer](http://stackoverflow.com/questions/18473104/chmod-for-php-web-application/18474838#18474838) I've written myself, about unix permissions in general, and [this excellent post](http://askubuntu.com/questions/44542/what-is-umask-and-how-does-it-work) about umask in particular. – giorgio Nov 30 '15 at 12:27

2 Answers2

2

The problem is that your file has too little file permissions, probably 640. Because your user is owner, you can see the images in the browser when accessing the .html in your browser with url file://.... Because now your own linux user is opening the file.

But; when you try to open the file with url http://localhost/..., your linux user itself is trying to open the file, but the user apache is running from (probably apache or www-data). So this time, the file has too little permissions (the last 0 in the bitmask).

If you run give the image more permissions you should be good;

chmod 644 /var/www/html/path/to/the-image.jpg

And if you don't want to do this everytime you save an image on your pc, open up $HOME/.profile (in a terminal: vim ~/.profile, or the more easy editor pico -w ~/.profile) and add the following line at the very end of the file:

umask 0022

That's it! Don't forget to logout and login again to have this line to have effect.

Note: the instruction about adding the umask command to ~/.profile only applies to (most) Debian systems (including Ubuntu). It might differ for your linux distribution, so please check the documentation for your distro, or ask our omniscient friend google.

giorgio
  • 10,111
  • 2
  • 28
  • 41
1

Ok thanks to the user @giorgio I found the answer, seems like it only had to do with Ubuntu, restricting permissions to read files, I managed to make it work by running this in terminal:

chmod 644 /var/www/html/*Image path here*
Yassir Khaldi
  • 1,452
  • 1
  • 17
  • 30
  • Lol :p giving you +1 for the trouble. Hey and while your at it, give yourself an extra reward by accepting this answer as the correct one (should give you some rep points extra. Not sure though, as your answering your own question). – giorgio Nov 30 '15 at 12:30
  • hehe no you can actually put your answer so That I can accept it – Yassir Khaldi Nov 30 '15 at 12:41
  • yeah sure why not ;) elaborated it a bit to make it more useful for others. – giorgio Nov 30 '15 at 12:53