Originally, I would select my php files and it would open the site on my local browser, I accidently opened it to notepad and now it will only open the code to editors. Does anyone know how to change the file setting back to when it would execute in the local browser? Ive tried resetting the filetype associations and resetting the file extension settings in the registry editor. I am currently using Windows 11
If you are not using a servlet like wamp or xampp you cannot process the php file on localhost.As long as the files have a php extension and are in the target folder of the servlet, while the servlet is active (example: if there is an index.php in the www folder in wamp. It will work if you type localhost/index.php in the browser.) your php files will work.
Related
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
I just started learning php and this is what I have done:
I copied the code from the left panel on this page and pasted them into a local html file. But when I open the html in browsers (firefox and chrome), the page doesn't look like what it should be: There is no format and the word 'echo' and some symbols are shown on the page. Why does this happen? How can I fix this issue?
PHP is a serverside scripting language. It has to be interpreted by a PHP interpreter that is in some way connected or integrated into an HTTP (web) server. There are a number of different ways to do that, with varying degrees of complexity.
How and where you setup your php + webserver is up to you, and the ways to do that typically start with the operating system you are running your workstation on, assuming you want to do so, locally.
You can go right to here for a jumpstart: http://www.phptherightway.com/#getting_started
The extension for a page that has php codes must be .php and not .html. Also, for the PHP code to execute you must be running Apache server on your machine.
This is a good tutorial for beginners, which tells you how to run PHP codes.
The steps are as follows
Open any Text Editor. Install new if you don't already have any good Text Editor installed. (My Favorite is Sublime Text & Notepad++)
Write the following PHP Program / CODE in the Text Editor: '; ?> This is
test.php File.
Save the file in XAMPP Installation Directory \ Web Root Directory Note-1: Default XAMPP Installation Directory in Windows is C:\xampp
Note-2: Default Web Root Directory in XAMPP is htdocs. All your php
files will have to be in this htdocs folder. That means, for a typical
installation of XAMPP in Windows, you will have to save the PHP CODE
in C:\xampp\htdocs folder.
When you save the file, name it test.php (just as an example, any valid file name with .php in the end will work). Note: when you save
this file, make sure it has no .txt extension at the end. Some text
editors place .txt at the end of file name, so it becomes test.php.txt
instead of test.php. To avoid this, when you save the file using any
text editor, place double quote around the file name: e.g. "test.php"
Then, go to XAMPP installation folder (typically, C:\xampp) and run xampp-control.exe by double clicking it.
In the xampp-control window, click the start button beside Apache. Later, if you need other options like MySQL, you'll also have to start
MySQL by clicking the start button beside MySQL in the XAMPP control
Panel. Note: if your OS hides common file extensions, then you'll see
xampp-control, instead of xampp-control.exe
Now, in your web browser's address bar, type the address: http://localhost/test.php
Wamp is installed correctly and it works fine. However, when I try to open a file with Chrome (or any other) from the file explorer it opens the file with raw code: file:///C:/wamp/www/testing/built-in.php
But when I manually change the URL to localhost/tesing/built-in.php then the php code is executed fine.
So my question is: is there a way to open a PHP file in "localhost" instead of the "file:///" directly from the file explorer?
WAMP is a server, therefore the files can only be executed whilst being called from the server rather than from the local drive. When opening from the local drive, the file "by-passes" the server and it is directly displayed via the browser.
Using mac OS, installed MAMP. Everything seems to be running fine. Created a PHP file in the htdocs folder, tried to open it with Firefox but won't recognize PHP file. Asks me which program I want to use to open the file, when I choose firefox, blank screen comes up.
Open it by typing in your browser localhost/path/to/your/file.php and MAMP (assuming everything is in fact working) will then parse the file and return the output from the request.
For Mac & MAMP, the path in the address bar should be:
http://localhost:8888/folder_name/your_page_name.php
Also, this will help you configure MAMP appropriately
http://sawmac.com/mamp/
inspite of all bad configuration of mamp,opening file with firefox must show something written over it,so please show code u wrote there as said by Dan and DarkXphenomenon
I'm running xampp version 2.5 on windows 7 and ftp'd over a website I'm working on (www.dfwcertautos.com). None of the .php pages load, however the .html pages load fine. I created a test.php page with "hello world" and it loaded correctly. Any suggestions for getting it to run properly? The site has no database, however it does have an XML feed coming in to it from another service. I didn't make any changes to the htaccess file.
What FTP client did You use?
It is possible that when copying the files in "Text" and not "Binary" mode there was a special whitespace added on the beginning of each PHP file so the PHP file cannot be executed on APACHE server...
EDIT: another idea - aren't You using PHP short tags <? instead of <?php on Your localhost while on the server the short opening tag (<?) is not permitted...?
Trying to get MAMP running with Dreamweaver.
When I preview a php file inside Dreamweavers 'Live View' mode instead of working direct from my file:
http://localhost/php_test/timetest.php
it creates its own temp file which looks like:
http:// 127.0.0.1/php_test/ TMPWY5ZEM.php
(I've added the additional spaces as stockoverflow assumed I was spamming)
I know the localhost runs correctly as if I type the URL directly into a browser it runs fine.
I've set up the Dreamweaver site correctly to the best of my knowledge, the details are below:
Local site folder:
/Applications/MAMP/htdocs/php_test
Server Folder:
/Applications/MAMP/htdocs/php_test
Web URL:
http://localhost/php_test/
Testing Server:
PHP MySQL
Any help?
This typically means that you have the preview using temporary file preference set (which I believe may be a default setting). Do the following:
Edit (Dreamweaver on Mac) Preferences, Preview in Browser category, uncheck Preview using temporary file
setup a testing server, if you have some problems from there, set your site type to localhost.