I have recently been drafting a website in HTML and CSS, but since the scope of the site is larger than originally planned I want to use PHP as well (for e.g. shared nav menus). After getting my server set up (VSCode, PHP w/ Xdebug, XAMPP) I simply changed my index.html to index.php and previewed the page.
The website was identical except some images were broken. I noticed the ones that worked were sourced as images/... and there ones that were broken were sourced as /images/....
Is there a difference between /images/ and images/?
Some extra information that may play into this: When setting up PHP it was a fresh install of XAMPP and using the PHP debug with Xdebug extension in VSCode. When debugging and launching the server to preview my website I kept getting the XAMPP dashboard even though my website source was set as "webRoot": "${workspaceFolder}". The only way I could bypass this was for the project to set it absolutely by removing webroot and replacing it with "url": "http://localhost:8080/WebsiteDirectory/".
Yes, it is.
/images/ is an absolute path starting from the root of your page
images/ is relative from subfolder you're in.
And actually it's HTML question, not PHP.
Related
This question already has answers here:
Project Links do not work on Wamp Server
(13 answers)
Closed 3 years ago.
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.
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.
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.
I need to change/rearrange a website built by a developer I don't have contacts to, but I'm having a problem with setting up the local test server.
I've downloaded all of the website's "public_html" files through FTP and they appears as below. (numbers indicate which level they're located in)
0.public_html
1.resources
2.subfolder
3.index.blade.php (includes content for index page)
3.template.blade.php (includes contents i.e. for index)
2.public
3.index.php (loads laravel php framework, no other code included)
When I open the page source code of the index page (through chrome), it reads contents from index.blade.php, template.blade.php, and other php files into one html document.
I'm using MAMP on mac, and when I set the document root to "public" where index.php is located I get an error message:
This page isn’t working localhost is currently unable to handle this
request. HTTP ERROR 500
When I set the document root to "public_html" I get an index of folders in "public_html", including "public" and "resources"
How do you set up a localhost for a website like this (index.php loading multiple php files from folders outside of "public" folder)? Is it possible?
ps: Hope I made sense, if not I can clarify. I've worked with html/css/js and wordpress sites but am a complete noob with php. Any help would be much appreciated. Thanks in advance!
I purchased a marketplace template. I am used to see index.html files when I load them into brackets for editing. This template however has an index.php file.
My question is how do I go about editing the index.php file? Would it be the same as I would with an index.html file? Brackets also does not read PHP and I would have to run it from a server with the host name url (something I also don't know how to do).
To execute php files, you have to use a local web server as Billy points out. On Windows and Mac you can use XAMPP to do so, on Linux you should prefer setting up a LAMP-Server (Tutorial).
After you installed your webserver you have to save your files under the server's document root. You can find it at the place where you installed XAMPP under the folder /htdocs (the place on Linux varies, on the latest Ubuntu flavors it should point to /var/www/html) You have to move all the files there. Now, you can open those files in your web browser by opening localhost/your-folder/index.php.
Edit your PHP files as you'd normally do in Brackets, it can handle PHP files. To use the Live Preview feature you have to go to File → Project Settings and enter your path with localhost here (don't add the file name, Brackets will do that for you) e.g. http://localhost/your-folder and you should be all set and running.
You can use live editor to edit your php file such as https://c9.io/ and its one installation is free and that's how you can upload your files: https://docs.c9.io/discuss/5582d455ea39a93900224238 . Just start custom php project and make it private.
I have been using "Delphi PHP XE2". The file structure has worked fine for over a year on the development machine and the production.
The folders are organised as follows.
src/app_login.php
src/add
src/css
src/js
src/fnc
src/db
src/images
etc.
I am just trying out PHPSTORM. The include files work fine. When I run it in Firefox it can find all images, JavaScript files, etc. But it can not find the CSS files as it is looking for them in
css
rather than
src/css
I haven't changed anything.
Why is the browser now looking at absolute path rather than relative?
How did PHPStorm manage to tell it that?
And how do I coerce it to treat them as relative paths?
I see that in the browser it runs it as:
http://localhost:63342/SRC/app_login.php
instead of
http://localhost:63342/app_login.php
I guess this the problem. How do I coerce it to move down one directory level?
I am trying to set up IIS, I think this might be best for later on. Here are the screen shots:
I configured the hosts file so that when I type wys.com in the browser it tries to run it and shows a blank page. If I type in 192.168.1.0 it just shows a blank page. View Source shows nothing. I was expecting it to run the index.html at d:\wys\src. Why is the browser not running it?
You are using PhpStorm's own simple built-in web server which uses URLs like http://localhost:63342/ProjectName/app_login.php. You cannot make http://localhost:63342/app_login.php using such server as it will not be able to tell what files to serve.
Either use your own Apache/IIS/whatever web server .. or the best you can get with built-in server would be http://ProjectName:63342/app_login.php(IDE needs to know what site/files to serve somehow). For that:
Edit your hosts file (or local DNS server, if preferred and have one) and point ProjectName to your computer's IP (e.g. 127.0.0.1).
Create Deployment entry of correct type (In Place should do), configure it (provide desired URL etc -- http://ProjectName:63342/) and mark it as Default for this project -- now IDE will use URL from there when generating "open in browser" URLs.
I'm trying to use Dreamweaver with an existing code base (not WP, Drupal, or Joomla!) in a PHP/MySQL site. I continue to receive "Dynamically related files could not be found because of an internal server error." I've been googling all day and have read plenty of WP-specific solutions, including the thread on this site. I've tried all the methods listed, no luck.
Setup Info
MAMP 2.0.1
Mac OS X 10.6.8
Dreamweaver CS 5.5
Site's local address: /Users/myName/Sites/siteName
Testing server address: /Applications/MAMP/htdocs/siteName
Attempted solutions:
1) added library to site root (/Users/myName/Sites/siteName/library)
2) added library to MAMP root (/Applications/MAMP/library)
3) added include path for both locations to applied php.ini listed in phpinfo
4) set Dreamweaver to use Site Root paths instead of page-relative paths
5) switched back to page relative paths
6) Restart MAMP, reset ports in Preferences to 8888/8889, or 80/3306
7) checked site info to make sure paths are correctly defined
When I insert the following code, or any require function with a relative path, live view and preview in browser display empty pages.
<?php require_once('includes/initialize.php'); ?>
I'm incredibly frustrated. I had been using XAMPP and a plain text editor for previous work and never had an issue with relative paths. Any help would be appreciated.
Answering my own question; bad form, I'm aware.
EDIT:
Adding to previous list of attempted solutions:
8) tried designating the server ports as 8888/8889 and defining server route as http://localhost:8889/mySite/, like setting up a Drupal/WP/Joomla! testing environment.
9) Uninstalled/Reinstalled MAMP, Dreamweaver, disabled the out-of-the-box Apache server included with OS X, the redefined the site in Dreamweaver.
Fix attempt 8 led to packet error discussed here. Fix attempt 9, plus error reporting that hadn't been working, but did now:
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
showed that the testing server was using the local definition to refer to dynamically related files and, even though that should work, it wasn't working.
After reinstall, created new site with "Site > Manage Sites" and defined Local Site Folder in "Site" menu and the Server Folder in the "Server" Menu as the same directory. (/Applications/MAMP/htdocs/mySite)
Refer to the Setup info in the OP to see my system variables; this may be specific to any/all settings. But only identical local definition and server definition solved the problem. I've recreated previous settings to be sure, and different local/server definitions don't work.
This error can happen with Dreamweaver and PHP sites if the contents of the included file make additional dynamic calls using PHP syntax that Dreamweaver doesn't recognize. Without seeing the contents of initialize.php, I can't be 100% sure this is the case but I am pretty sure that DW is not able to parse the code there and figure out what files to get for display.
Problem Dynamically related files that I see a lot of people run into:
Dreamweaver is scanning whatever is in you Local Copy, it should be a the full installation of WordPress. If you're working locally, download everything on your "Testing server" to your "Local view" in the Files panel.
If you're working with two sets of files, your local copy and what is in MAMP's htdocs or on your "Testing server" should be nearly identical, except for what you're working on of coarse. That's the problem I see people have.
If you're working in kind of "pho-FTP" environment.