Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Re: cannot execute img src in localhost

Reply
Thread Tools

Re: cannot execute img src in localhost

 
 
Denis McMahon
Guest
Posts: n/a
 
      11-08-2012
On Thu, 08 Nov 2012 15:50:51 +0000, Marty wrote:

> Know of any newsgroups that could help with a localhost
> problem?


First of all, there is no such thing as a localhost problem, the problem
is either with your local webserver configuration, or with your html. Do
you even have a local webserver running?

Please try the following shell command:

sudo ps -A | grep apache

You should see something like:

1269 ? 00:03:17 apache2
9231 ? 00:00:00 apache2
9232 ? 00:00:00 apache2
9238 ? 00:00:00 apache2
9239 ? 00:00:00 apache2
9243 ? 00:00:00 apache2
9661 ? 00:00:00 apache2
9750 ? 00:00:00 apache2
10175 ? 00:00:00 apache2
10176 ? 00:00:00 apache2
10597 ? 00:00:00 apache2

If that shows several entries, then the webserver seems to be running.
Try typing the following 2 lines, both followed by return (note there may
be no visible response to the 'nc localhost 80', just type the GET
anyway.):

nc localhost 80
GET /webpage.php

This should display the content that your php file generates and delivers
via the webserver.

If the 'nc localhost 80' returns a normal (eg name@host$) prompt, then
it's possible your webserver, although running, isn't active on the
expected port.

Try the following command:

sudo netstat -t -l -p -v | grep http

This should output a line similar to the one below (the 1269 will
probably be a different number, and I've trimmed some whitespace):

tcp 0 0 *:http *:* LISTEN 1269/apache2

Finally, try opening the browser and enter the following in the location
bar:

http://localhost/name.ext

Where name.ext is the name and extension of your image file. If the image
file is in the root directory of the web server, then it should display
in the browser. If it does not display, then either:

a) There's no browser running
b) The file is not where the server is looking for it

Rgds

Denis McMahon
 
Reply With Quote
 
 
 
 
Jonathan N. Little
Guest
Posts: n/a
 
      11-09-2012
Marty wrote:

> I get You don't have permission to access /imagefile.jpg on this server.
> When I do localhost/imagefile.jpg
>


Your server is not setup properly. This is not an HTML problem this is a
Apache server setup problem, (assuming your are using Apache). Or your
have a permission problem, for example you put the file with your
profile and image is neither wwwdata user or group (marty:marty) OR your
file is not world readable (660).


sudo chown -R wwwdata:wwwdata /var/www/*

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
 
 
 
Jonathan N. Little
Guest
Posts: n/a
 
      11-09-2012
Marty wrote:
> On Thu, 08 Nov 2012 20:25:10 -0500, Jonathan N. Little wrote:
>
>> Marty wrote:
>>
>>> I get You don't have permission to access /imagefile.jpg on this
>>> server.
>>> When I do localhost/imagefile.jpg
>>>
>>>

>> Your server is not setup properly. This is not an HTML problem this is a
>> Apache server setup problem, (assuming your are using Apache). Or your
>> have a permission problem, for example you put the file with your
>> profile and image is neither wwwdata user or group (marty:marty) OR your
>> file is not world readable (660).
>>
>>
>> sudo chown -R wwwdata:wwwdata /var/www/*

>
> I know next to nothing about linux commands. Is it a chown I need to use
> or a chmod? Is the syntax you show here correct?
>

chown changes the owner and group

chmod change the permission for owner, group, and world.

Depends on what you need to do. I am assuming that your server's
document root is /var/www if so then post the output of the following:

ls -lha /var/www

if your document root is different change accordingly

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-09-2012
Marty <(E-Mail Removed)> writes:

> On Thu, 08 Nov 2012 20:25:10 -0500, Jonathan N. Little wrote:
>
>> Marty wrote:
>>
>>> I get You don't have permission to access /imagefile.jpg on this
>>> server.
>>> When I do localhost/imagefile.jpg
>>>
>>>

>> Your server is not setup properly. This is not an HTML problem this is a
>> Apache server setup problem, (assuming your are using Apache). Or your
>> have a permission problem, for example you put the file with your
>> profile and image is neither wwwdata user or group (marty:marty) OR your
>> file is not world readable (660).
>>
>>
>> sudo chown -R wwwdata:wwwdata /var/www/*

>
> I know next to nothing about linux commands. Is it a chown I need to use
> or a chmod? Is the syntax you show here correct?


Yes, chown not chmod (though if things are really screwed you might need
that as well) and, yes, the syntax is correct. It's something of a
sledgehammer, but with little information to go on it seems like a good
start. He's assuming that there is some permission problem and the
easiest solution is to make everything owned by the user id that the
apache server uses (that's wwwdata). The ":wwwdata" bit also sets the
group id that owns the files which is probably overkill, but won't do
any harm.

The meta answer is to type man sudo and then man chown. You won't
understand all of what you see but, in general, the basics are up the
top so you can read until you get baffled. Do that enough and you'll
find you don't get baffled so much after a while.

--
Ben.
 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      11-09-2012
Ben Bacarisse wrote:
> Marty <(E-Mail Removed)> writes:
>
>> On Thu, 08 Nov 2012 20:25:10 -0500, Jonathan N. Little wrote:
>>
>>> Marty wrote:
>>>
>>>> I get You don't have permission to access /imagefile.jpg on this
>>>> server.
>>>> When I do localhost/imagefile.jpg
>>>>
>>>>
>>> Your server is not setup properly. This is not an HTML problem this is a
>>> Apache server setup problem, (assuming your are using Apache). Or your
>>> have a permission problem, for example you put the file with your
>>> profile and image is neither wwwdata user or group (marty:marty) OR your
>>> file is not world readable (660).
>>>
>>>
>>> sudo chown -R wwwdata:wwwdata /var/www/*

>>
>> I know next to nothing about linux commands. Is it a chown I need to use
>> or a chmod? Is the syntax you show here correct?

>
> Yes, chown not chmod (though if things are really screwed you might need
> that as well) and, yes, the syntax is correct.


Yes is is possible to have it work with neither the owner or the group
set to wwwdata if world is set to read. But

-rw-rw---- marty marty imagefile.jpg

would give him the problem that he is experiencing and simply turning on
world read would fix it.

More info would help and that is why I ask for a listing of the dir. For
a private server to make thing easier to edit locally there are things
you can do to simplify the process. If you access the server from
Windows workstations you can make a samba share to the document root and
used "force group = wwwdata". Or if you access from Linux on the local
machine then edit apache config to set
"export APACHE_RUN_GROUP=marty"

Just depends on his situation.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      11-09-2012
On Thu, 08 Nov 2012 20:25:10 -0500, Jonathan N. Little wrote:

> sudo chown -R wwwdata:wwwdata /var/www/*


Bad advice.

He said he's using Ubuntu. On my Ubuntu server, the web user is www-data,
not wwwdata! This was the default user name set up by the installer.

What he could do is either of the following:

Method:

Easy Method A makes all the files in the /var/www tree the property of
the apache process.

1) sudo cat /etc/passwd | grep www

Hopefully there's only one line, and it will look something like:

www-user:999:999:www-group:/var/www:/bin/sh

The fields are separated by the colon characters.

user name : password : user id : group id : group name : home : shell

A password of "x" means an encrypted password is stored in another file.

2) Get the user name and group name from above line (which in this case
is www-user:www-group)

3) sudo chown -R wwwdata:wwwdata /var/www/*

Easy Method B:

Method B allows anyone to read all the files in the /var/www tree,
regardless of who actually owns them.

sudo chmod -R w+r /var/www/*

There are other methods, but they all require more knowledge of linux
users, groups and permissions than I'm prepared to contemplate getting
into with Marty here.

Rgds

Denis McMahon
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-09-2012
"Jonathan N. Little" <(E-Mail Removed)> writes:

> Ben Bacarisse wrote:
>> Marty <(E-Mail Removed)> writes:
>>
>>> On Thu, 08 Nov 2012 20:25:10 -0500, Jonathan N. Little wrote:
>>>
>>>> Marty wrote:
>>>>
>>>>> I get You don't have permission to access /imagefile.jpg on this
>>>>> server.
>>>>> When I do localhost/imagefile.jpg
>>>>>
>>>>>
>>>> Your server is not setup properly. This is not an HTML problem this is a
>>>> Apache server setup problem, (assuming your are using Apache). Or your
>>>> have a permission problem, for example you put the file with your
>>>> profile and image is neither wwwdata user or group (marty:marty) OR your
>>>> file is not world readable (660).
>>>>
>>>>
>>>> sudo chown -R wwwdata:wwwdata /var/www/*
>>>
>>> I know next to nothing about linux commands. Is it a chown I need to use
>>> or a chmod? Is the syntax you show here correct?

>>
>> Yes, chown not chmod (though if things are really screwed you might need
>> that as well) and, yes, the syntax is correct.

>
> Yes is is possible to have it work with neither the owner or the group
> set to wwwdata if world is set to read. But
>
> -rw-rw---- marty marty imagefile.jpg
>
> would give him the problem that he is experiencing and simply turning
> on world read would fix it.


Sure, but (to rather labour this detail) my point about maybe needing
both is just that if user and group read permission are missing,
changing the owner won't do it.

> More info would help and that is why I ask for a listing of the
> dir.


Absolutely. Further hints can also come from the error log.

To the OP: have a look at the error log. On my setup I just do

tail /var/log/apache2/error.log

to see that last few entries. When there is a misconfiguration you
might get lots of errors, in which case viewing the whole file is more
useful.

<snip>
--
Ben.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-09-2012
Denis McMahon <(E-Mail Removed)> writes:

> On Thu, 08 Nov 2012 20:25:10 -0500, Jonathan N. Little wrote:
>
>> sudo chown -R wwwdata:wwwdata /var/www/*

>
> Bad advice.
>
> He said he's using Ubuntu. On my Ubuntu server, the web user is www-data,
> not wwwdata!


Well spotted!

> This was the default user name set up by the installer.
>
> What he could do is either of the following:
>
> Method:
>
> Easy Method A makes all the files in the /var/www tree the property of
> the apache process.
>
> 1) sudo cat /etc/passwd | grep www


Or just "sudo grep www /etc/passwd". Indeed, on my default install (and
I think on many) there's no need for the sudo since /etc/passwd is
readable by all.

> Hopefully there's only one line, and it will look something like:
>
> www-user:999:999:www-group:/var/www:/bin/sh


Just to clarify (since the OP is new to this) you are most likely to see
www-data in both places.

> The fields are separated by the colon characters.
>
> user name : password : user id : group id : group name : home : shell
>
> A password of "x" means an encrypted password is stored in another file.
>
> 2) Get the user name and group name from above line (which in this case
> is www-user:www-group)
>
> 3) sudo chown -R wwwdata:wwwdata /var/www/*


I think you meant to edit that!

> Easy Method B:
>
> Method B allows anyone to read all the files in the /var/www tree,
> regardless of who actually owns them.
>
> sudo chmod -R w+r /var/www/*


I think you meant:

sudo chmod -R o+r /var/www/*

> There are other methods, but they all require more knowledge of linux
> users, groups and permissions than I'm prepared to contemplate getting
> into with Marty here.


It's a nightmare trying to guess what might or might not be wrong here.
I am still not convinced it's a file permission or ownership thing,
since the defaults work without change (at least on my setup) but
something is wrong so permissions do need to be checked.

--
Ben.
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      11-09-2012
On Fri, 09 Nov 2012 13:10:16 +0000, Ben Bacarisse wrote:

> Denis McMahon <(E-Mail Removed)> writes:


>> 2) Get the user name and group name from above line (which in this case
>> is www-user:www-group)
>>
>> 3) sudo chown -R wwwdata:wwwdata /var/www/*

>
> I think you meant to edit that!


Yes, it should have been something like:

3) Use the following, substituting the user name and group name from step
2 for user and group:

sudo chown -R user:group /var/www/*

>> sudo chmod -R w+r /var/www/*

>
> I think you meant:
>
> sudo chmod -R o+r /var/www/*


Damn it, I'm on a roll today.

Yes, I did, and in my defence, I still make the w+r (world+read) mistake
myself regularly, especially if I haven't had to chmod anything for a few
days.

Rgds

Denis McMahon
 
Reply With Quote
 
se
Guest
Posts: n/a
 
      11-09-2012

"Lewis" <(E-Mail Removed)> skrev i meddelelsen
news:(E-Mail Removed)...
> In message <k7ffae$8of$(E-Mail Removed)>
> se <(E-Mail Removed)> wrote:
>
>> <link href="mystyle.php" rel="stylesheet" type="text/css">
>> A stylesheet must have the extention .css

>
> What idiot told you that?


A .php extention won't work together with a rel="stylesheet"
At least not in EW2. I just made a trial. You should do.

>
> No, a stylesheet can have any name at all, and any (or no) extension.
>
>
> --
> For more than a thousand generations the Jedi were the guardians of
> peace and justice in the galaxy. Before the dark times. Before the
> Empire.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: cannot execute img src in localhost Ian HTML 0 11-08-2012 12:35 AM
Re: cannot execute img src in localhost Ben Bacarisse HTML 0 11-08-2012 12:17 AM
What does the SRC in <IMG SRC> stand for? pheadxdll HTML 16 06-06-2007 02:45 AM
<txt src= ...> equivalent of <img src= ...> Steve Richter ASP .Net 3 02-09-2006 08:44 PM
src.jar (src.zip) missing on Mac OSX Java 1.4.1 installation? Greg Johnson Java 4 09-18-2003 07:21 AM



Advertisments