0

This is my first time trying to use wamp and I'm having trouble viewing my php project. I know the code works just fine (because it is a copy of currently live site). Basically when I try to view the site on my localhost only the index.php file loads and the image folder. No css folders/files are loading. The links work, so I can navigate my site, but no css.

My project folder is inside the www folder in my localhost. See below my project is called movies. C:\wamp64\www\movies

When I go to view it at - http://localhost/movies/ , it displays only the html. When I view the sources tab in the console it shows the localhost/movies and inside movies an image folder and index, there should be many other folders including CSS and PHP folder called process.

PPS
  • 69
  • 1
  • 8

2 Answers2

0

If you saved the Webpage by CTRL+S the sources to your wamp dir then maybe it didn't download all sources.

I suppose you are using Windows and maybe chrome or firefox. Inspect Element the page you are currently trying to view and find sources .CSS|.JS|.JPG in console then navigate to the file and see if it's working like http:/localhost/assets/js/something.css.

Remember all your files should be inside www folder because it is the root dir accessible for server.

If you are using <? (short open tag) then for Wamp, Left click on wamp, Hover on PHP then hover over PHP Settings, find "short open tag" and finally Click it. Restart Wamp Server.

  • Hi, all files are located in 'movies' folder which is located in the www folder. Also, I did inspect/view source and although I don't see the folders in the console I can navigate to them. For example even though the console doesn't have the css file there I can still navigate to css/style.css folder. It displays all the css code in the browser. I did CTRL+C CTRL+S the project to the www folder, but I can open the copied folder in my editor and everything is there. – PPS May 12 '19 at 07:43
  • Are you using an .htaccess file? maybe you are writing / as movies in .htaccess. Also inside Console click on Elments, find a file and the open it in new tab check if it's accessable Like this! https://serving.photos.photobox.com/46119550a9614b85748fdcc36d8ad1eab366ecf396d6b3b187662564032ddf1afa339a4a.jpg – C0deB0untyHunter May 12 '19 at 08:08
  • When I right click and view source on index.html – PPS May 12 '19 at 08:27
  • Developer Tools... CTRL+SHIFT+I or RIght Click and Inspect Elements. Or in view source find css file and try to open in in new window! – C0deB0untyHunter May 12 '19 at 08:36
  • Sorry as I was typing the response above I found out the issue. It was my php code.My code was on webfaction hosting before and they don't require all of your php code to start like this , however wampserver does. I don't suppose you know how to adjust this somewhere so I don't have to comb through all files and change the '' to ' – PPS May 12 '19 at 08:50
  • 1
    Instead of changing all tags from (short open tag) to – C0deB0untyHunter May 12 '19 at 20:12
  • @C0deB0untyHunter That's a bad idea. PHP voted to deprecate `` in PHP 7.4. https://wiki.php.net/rfc/deprecate_php_short_tags – ceejayoz May 12 '19 at 21:54
  • @ceejayoz He's using wamp maybe to test so as long as he wants to be able to use his current project i think it's okay because he's testing Local. Though if it's going live on site then yes it's a bad idea and if server is managed by an admin who can update PHP version or so then it's worst idea. – C0deB0untyHunter May 13 '19 at 00:17
0

The reason for this might be due to the links. If your website is example.com and you link to an image /directory/file.jpg, the browser will request domain+uri -> example.com/directory/file.jpg and it works fine.

You run in a directory called movies and you access it via localhost/movies/. You expect that the browser used localhost/movies/directory/file.jpg, but it's not. It's domain+uri -> localhost/directory/file.jpg. As you can see, "/movies" is missing from it, thus it's not finding the file.


There are a few possible solutions. The best one is to add alocal test domain in your vhost file. You can do this by clicking the wamp logo -> 'your virtual hosts' -> 'virtual host management'. This solution is a bit more difficult and might require some more research, but is the long term best solution.

  • The first input is your website, eg movies.test.
  • The second is the path, which is c:/wamp64/www/movies/ (or where-ever you have wamp).
  • Then click start and restart wamp.

You can also set a base path in you html header.

<base href="/localhost/movies" >

And you could also link to your files relative

<img src="./images/file.jpg" />

These last two are easier, but require different values local vs on your production server. That works annoyingly if you have to keep updating it.

Martijn
  • 15,365
  • 4
  • 34
  • 66