I have a local version of Windows php to test my webpage. I run it using php.exe. It has a built-in webserver so pages can be accessed from a browser through localhost:/path.
If I enter an URL pointing to a file it opens that file in browser. I would like to configure it so that it shows the content of a directory if URL points to a directory. E.g. after inserting URL http://localhost:1234/foo/bar/ into the browser I would want to see the files in the bar directory listed in the browser. Similarly how other webservers do it when configured so.
My local PHP returns 404 instead.
Is there any way how to achieve that for this built-in webserver in php.exe? How?
The built-in server is specifically for quick development and debugging as stated in the command line server doc and directory listing is one of the features is lacks. This answer provides an example for building yours though.
Related
I'm loading a html file hosted on the OS X built in Apache server, within that file I am linking to another html file in the same directory as follows:
<a href="2ndFile.html"><button type="submit">Local file</button>
This works. However (for reasons too lengthy to go into) I am experimenting using the file: scheme instead, however I cannot get anything to work. Here is how I am re-writing the above line using file:
<a href="file://192.168.1.57/~User/2ndFile.html"><button type="submit">Local file</button>
(192.168.1.57 is my current IP address)
Changing it to the following does also not work:
<a href="file://Name-Of-MacBookPro/~User/2ndFile.html"><button type="submit">Local file</button>
But the file cannot be found, how should it be specified using the file: scheme?
The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html. Notice the three slashes; the hostname part of the URL is empty, so the slash at the beginning of the path immediately follows the double slash at the beginning of the URL. You will also need to expand the user's path; ~ does no expand in a file: URL. So you would need file:///home/User/2ndFile.html (on most Unixes), file:///Users/User/2ndFile.html (on Mac OS X), or file:///C:/Users/User/2ndFile.html (on Windows).
Many browsers, for security reasons, do not allow linking from a file that is loaded from a server to a local file. So, you may not be able to do this from a page loaded via HTTP; you may only be able to link to file: URLs from other local pages.
the "file://" url protocol can only be used to locate files in the file system of the local machine. since this html code is interpreted by a browser, the "local machine" is the machine that is running the browser.
if you are getting file not found errors, i suspect it is because the file is not found. however, it could also be a security limitation of the browser. some browsers will not let you reference a filesystem file from a non-filesystem html page. you could try using the file path from the command line on the machine running the browser to confirm that this is a browser limitation and not a legitimate missing file.
The 'file' protocol is not a network protocol. Therefore file://192.168.1.57/~User/2ndFile.html simply does not make much sense.
Question is how you load the first file. Is that really done using a web server? Does not really sound like. If it is, then why not use the same protocol, most likely http? You cannot expect to simply switch the protocol and use two different protocols the same way...
I suspect the first file is not really loaded using an apache http server at all, but simply by opening the file? href="2ndFile.html" simply works because it uses a "relative url". This makes the browser use the same protocol and path as where he got the first (current) file from.
I had similar issue before and in my case the file was in another machine
so i have mapped network drive z to the folder location where my file is
then i created a context in tomcat
so in my web project i could access the HTML file via context
For apache look up SymLink or you can solve via the OS with Symbolic Links or on linux set up a library link/etc
My answer is one method specifically to windows 10.
So my method involves mapping a network drive to U:/ (e.g. I use G:/ for Google Drive)
open cmd and type hostname (example result: LAPTOP-G666P000, you could use your ip instead, but using a static hostname for identifying yourself makes more sense if your network stops)
Press Windows_key + E > right click 'This PC' > press N
(It's Map Network drive, NOT add a network location)
If you are right clicking the shortcut on the desktop you need to press N then enter
Fill out U: or G: or Z: or whatever you want
Example Address: \\LAPTOP-G666P000\c$\Users\username\
Then you can use <a href="file:///u:/2ndFile.html"><button type="submit">Local file</button> like in your question
related: You can also use this method for FTPs, and setup multiple drives for different relative paths on that same network.
related2: I have used http://localhost/c$ etc before on some WAMP/apache servers too before, you can use .htaccess for control/security but I recommend to not do so on a live/production machine -- or any other symlink documentroot example you can google
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.
When I right click my local PHP file and select "open with Firefox" Firefox gets the focus for a second, but then the file opens in Dreamweaver instead. The same happens when I drag the file onto Firefox, or enter the URL ("file:///...") manually, or expressly select Firefox as the default application for PHP files. How can I get Firefox to show the file?
Firefox is not capable of handling PHP files, therefore it delegates their handling to a program that can do so (in your case, this is Dreamweaver).
PHP files should be served by a web server to the client (Firefox), which will display you the rendered content (probably HTML). PHP files are rendered by the PHP interpreter and then they are served using the HTTP protocol to a client as a web resource. So actually, you never open a PHP file with a browser, you just consume the HTTP resource that corresponds to the rendered output of that file.
Firefox can show .html-files. You have to install a webserver (xampp) to interprete .php-files. When xampp is installed, start xampp-control-panel, open your browser and (in case ur file is "test.php" in "c:\xampp\htdocs\test.php") and type http://localhost/test.php.
But first, right-click any php-file->Open with...->choose program, then select Firefox in the list.
You must install a local web server like xamp, wamp or easyphp.
Then you locate your files in that's www directory and see your file in browser with path:
localhost/myphp.php
Have a good time.
I have this solution to open a php on linux :
php -S localhost:8000
and open a firefox and go to the page :
http://localhost:8000/index.php
It works well for me.
The quickest way is to rename localhost/yourfile.php onto localhost/yourfile.html. (Tested on loop's Ubuntu 16.04 LTS)
You should deactivate adblock for localhost (or your domain), it should runs.
ABP icon -> click on deactivate on localhost -> F5
I'm following directions to set up a debugging in FlashDevelop in web browser. I'm getting confused on 'Configure your project' step. It says:
Open the Project properties and change the "Test Movie" option to
"Open Document...". Click on the button which should appear,
and enter bin/index.html (path to html page, relative to project root)
in the prompt.
What is the bin/index.html file? Is it where my SWF is loaded? I currently have a SWF that loads from a PHP page. So I pointed it to my PHP project's index.php page build project. After build I get a generic Windows message that Windows cannot open the file with that extension.
Is it possible for me to debug my SWF from my PHP page which loads it?
I don't have experience directly with what you're talking about, but I guess you have to point to a PHP file which is running in a webserver. Otherwise it can't be interpreted and run.
If you are running locally, you can use xampp, put your things in htdocs, and use localhost url to reference the file: http://localhost/projectname/index.php