I currently have wampserver running and I'm trying to do live preview of a php file using Brackets.io. However when I click live preview I'm getting
Project settings for: Getting Started
Live preview base URL: ______________
I'm following this tutorial on running PHP scripts.
My php file is in C:/wamp/wwww/php_proj1/php1.php so I've been trying to put this in my "Base URL"
http://localhost/php_proj1/php1.php
However everytime when I type that and enter it, it just asks me for the "Live Preview Base URL" again and nothing happens. I also tried putting the URL in my 'File->Project settings' and that also didn't work. I'm just running a basic php script that echos some words.
It works when I manually type
http://localhost/php_proj1/php1.php
in my Chrome URL but not when I use Bracets live preview.
What am I missing or doing wrong? Do I need to config anything in my wampserver? I've just started learning php and using wampserver so I'm not entirely sure what I'm doing wrong.
Thanks!
EDIT: I'm following these 2 tutorials on doing this and it's just not working for me.
tutorial 1 and tutorial 2
EDIT2: Found my mistake.. I did not do File->Open Folder to open the folder that I was working on... Thanks to everyone that helped me with this, I will definitely not make this mistake again. sigh
The Live Preview Base Url should be set to the same url that you would use to launch your project in a browser.
So if you have a project in C:/wamp/wwww/php_proj1/ you would launch that project in a browser by entering http://localhost/php_proj1/php1.php therefore that is what Brackets is expecting to be entered into the Base Url field minus the actual script file name.
Remember the DocumentRoot of localhost is pointing to the folder C:/wamp/www/
So enter
http://localhost/php_proj1/
into the dialog that requests the Base Url.
Assuming you are editing the file php1.php at the time you clicked the Live Preview icon that is the script that will be run in the browser.
Oh and of course you have to have WAMPServer and therefore Apache up and running when you do this as it is running the code through Apache so that the PHP code can be interpreted.
Found my mistake. I did not do File->Open Folder to open the folder that I was working on...
Try the same thing but with a simple HTML file.
Try launching your project with PHP's built-in server. Open a terminal/cmd window and go to the folder php_proj1. Now execute php -S localhost:8000. Now set your Live preview path to http://localhost:8000/. If this one does work, then there may be a problem with Wamp.
Now remember that no matter what, you're not supposed to contain a file in the Live Preview path, but only a folder path. When you contain it, you get to this URL: http://server/file.php/file.php (double) and that's not exactly what you want...
If none of these work - there may be a problem with either your computer, Brackets, Chrome, or both. Try to reinstall them (Brackets first).
My two cents, is the name of the project php_proj1 ? If not you'll have to use http://localhost/ as your base URL.
Also (When you are using Brackets) check the content of the Chrome Network tab. F12 Developer Tools -> Network -> Filter -> Documents
Try to investigate the URLs, probably that'll give you some insight
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.
Objective: debug a php script triggered from an HTML form with action=POST from within a WordPress Page.
What works: I can initiate a debugging session for index.php. This results in the web page displaying in the browser view. I can then click on any links on the page, which in turn triggers a new call to index.php. I can step through the WordPress code with no problems, set breakpoints and so on.
The apache server is on my workstation, localhost, running Ubuntu Linux.
In one page there is a form. When I click the submit button, I get a message in the browser view saying:
Unable to load page
Problem occurred while loading the URL file:///xyz.php
Error opening file: No such file or directory
It seemed to me that Eclipse is looking for the php file at the workstation root directory instead of the server root. So I put a symbolic link at the root level to the php script to see if Eclipse would find it.
Now when I click on the link I get a File Dialogue asking me do I want to download the php script.
It seems there must be a wrong setting somewhere but I am at a loss. As it stands I can only debug code that is triggered by a GET, not a POST.
If I run the script in Eclipse without debugging, I can post the data and the post script executes. It is only with the debugger that I get the file not found error, so it seems to be in the debugging config:
Server Name: Nip.yt
Base URL: http://nip.yt (127.0.0.1 - works fine in browser)
Document Root: /home/peter/Documents/localhost/html/nip
Path Mapping
Path on Server: /home/peter/Documents/localhost/html/nip
Path in Workspace: /nip
I have tried replacing Path on Server with / with identical results.
Any and all advice appreciated.
EDIT:
I am now using php5.6 with Zend Debugger, but exactly the same thing happens.
Hanging his head rather sheepishly, he says...
I solved the problem. I just put the full URL in the
Doh...
Why didn't I think of that sooner???
I built an HTML/CSS website and then added PHP functionality. Installed XAMPP. Since installing XAMPP, everything on the site works except the images. Image files don't display. They are all properly referencing the directory. In fact, before using XAMPP, the images displayed fine on the HTML webpages. After using XAMPP and re-saving as .php, they stopped working. Nothing else changed. I figure it must be a settings issue. Thoughts, anybody?
Thanks a billion in advance!
#john steve I had also the same issue. I tried lots of thing suggested on different forums but it did not work. Finally I set up permission for each images and it worked.
I just had the same problem. And the reason was that my images folder had no-access permission. I changed the permission to Read/Write for admin and Read-only for everyone else. It is possible to change permission for each individual time but it is time consuming, therefore changing the permission of parent folder is effective.
The following steps are for MAC OS:
Open applications folder
Locate XAMPP folder
Right click > get info.
In pop-up window locate the 'sharing & permission' section
Click the 'locked' padlock symbol
Enter admin password
Change 'Everyone' permissions to read & write
In the get info window still, select the 'cog' icon' drop down option
at the very bottom and select 'Apply to enclosed items' this will
adjust the permission across all sub-folders as well.
Re-lock the padlock symbol
Close the 'Get Info' window.
And for Windows:
-
Locate XAMPP folder
Right-click the folder, click Properties, and then click the Security tab.
Click Edit to open the Permissions for <Object> dialog box.
Click the name of the group or user.
In the Permissions for <User or Group> box, select the Allow check box.
References: Microsoft and Stackoverflow
#Manuel is right. If the problem persists, try absolute paths in image src. The absolute paths will be like http://localhost:8888/your-website-folder/your-images-folder/your-image-name
In windows you don't use port number (which is 8888) in this case
Good luck.
Its probably an issue with accessing local files on a "domain" that is not local. Just update you're images path to something relative or within localhost and it will be fine. Its a browser security thingy to not load local files when you are not opening a file directly from a file path. (Cross-domain or Same-origin policy). The idea is to not let any website sniff your local files and it doesn't work differently for localhost which can be an alias to any IP (doesn't nnecessarily to be 'local').
To fix this issue, move all your assets into the folder that is the root for localhost and e.g. use "images/someImage.jpg" instead of "c:\somePath\someImage.jpg". You cannot mix up c:\ with a page served from http://localhost/.
You will see this issue popping up in the network panel of chrome developer tools or Firebug extension when working with Firefox. It's really NOT recommended to, but it's possible to turn off this crucial security settings: http://joshuamcginnis.com/2011/02/28/how-to-disable-same-origin-policy-in-chrome/ - I would warn anybody to do it that way, though.
I figured out the problem: all of my images had permissions marked: "everyone: no access." I changed it to: "everyone: read only" I did this simply by right clicking (aka control-clicking) each image and then clicking "get info." I then scrolled down to "Sharing & Permissions." It's self explanatory from there. Thanks for the help everyone!
You have to set read and write permissions to each image you want to use. I assume you can probably do the entire folder in and it will cascade down. On mac right click (two finger) => get info => at bottom set all to read/write. reload page. Presto.
Please check the folder name. Don't use uppercase letter in folder names. I tried all solutions advices but finally found that solution. My pictures folder was "Resimler" then I couldn't see the pictures but I changed as "resimler" then it is worked.
I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.
Right now, when I notice a problem on a page on my PHP web site, I have to look at the URL, mentally deduce what file is responsible for displaying that page, then navigate the Eclipse PDT file tree to open that file. This is annoying and uses brain power that could have been applied to solving the issue instead.
I would like my PHP web site to display on every page a link that I could click to automatically open the correct file in Eclipse.
I can easily compute the complete absolute path for the file I need to open (for example, open C:/xampp/htdocs/controllers/Foo/Bar.php when visiting /foo/bar), and I can make sure that Eclipse is currently open with the correct project loaded, but I'm stuck on how I can have Firefox/Chrome/IE tell Eclipse to open that specific file.
Edit
I'm going along the way of a data: URI, by adding a link to my file that contains the name of the file, with an unusual MIME type.
<a href="data:link/php;base64,IkM6XHhhb[snip]GhwIgo=">
View controller
</a>
The base64-encoded content is the absolute path to the file on my computer. When I click the link, Firefox lets me bind the content type to a new application, so I chose a batch file I wrote myself:
for /f "delims=" %%i in (%1) do (
notepad.exe "%%i"
)
This works. Now, I would like the file to be opened in the already opened window of Eclipse. What do I have to replace notepad.exe with in the above batch?
[pathtoeclipse]\eclipsec.exe -name Eclipse --launcher.openFile [fullpathtoyourfilehere]
I am not sure if it works with Galileo (i am on Helios)
Further reading: https://bugs.eclipse.org/bugs/show_bug.cgi?id=4922 (it is a long, long story)
I've tried similar things in the past, but this isn't as easy as it should be. The end result was always that Firefox would need an extension to execute a local file (I never found one that would do the job), and IE won't do it at all any more (save, maybe, for some complicated proprietary VBScript/WScript).
I see two workarounds to do this:
A function that displays the file path on your page in a big fat dialog window, making it easy to copy and paste into the Windows + R "Execute" Dialog
Alternatively, registering a custom Protocol (e.g. eclipse://) in your operating system, and tying that protocol to Eclipse. This is a pretty great way actually, I haven't tried this yet but definitely will in the next project I need this. Mozillazine: Register protocol (see the .reg file example)
You get the local path with FILE.
Maybe you try something like this?
<?php
'127.0.0.1' == $_SERVER["REMOTE_ADDR"] and print __FILE__;
?>
Is integrating Eclipse with Xdebug an option? I've done this with TextMate so that generated error messages are clickable to take me to the correct line in the right file. (See this question for details).