Question:
simple PHP file which i created is not being executed ?
anonymous
2010-01-22 05:56:20 UTC
I Created a simple php file..



echo "hello world";
?>



And saved it with the extension .php but when i double click the file ,it is opening up in text editor.and then i tried ti open in mozilla firefox , it shows the download window and asked me where to save the file.I tried to give different extensions such as .phtml ,but still no way. When i run it as plain HTML , the script is not being executed.What can i do ? .Is there anything to be added in the file ? or there is something more to be installed ?

note : I've php installed already :)
Four answers:
anonymous
2010-01-22 06:26:14 UTC
Double-clicking the file will not work.



You rarely 'run' a PHP program in the same way you'd run a Java program or a C++ program. PHP was designed from the beginning to be integrated with a web server.



You really need to have a web server enabled in order to test your PHP programs. You've got two choices here: Post your work on a remote server for testing, or install your own. Neither is difficult.



The easiest solution is to use a hosting service. Freehostia has a free hosting account with adequate PHP and MySQL service (it also does not have any advertisements on the pages.) http://freehostia.com

Sign up for a free account and then use the control panel to upload your php file to the server. Then point your browser at that page on the server, and it should run. Uploading your file every time you want to change it could be a pain, but many programmer's editors come with integrated FTP support that automate this task.



If you want to test on your local machine, you need more than PHP. PHP won't do much without a web server, and you'll need the server to be configured to handle PHP. The best way is to get a complete package that installs everything together. XAMPP is my favorite solution. It includes apache (a popular and powerful web server,) PHP, MySQL (a database tool) and a bunch of other great tools, and pre-configures them to all work together. XAMPP is available free for all major platforms:

http://www.apachefriends.org



Once you've got apache installed, begin by running your web server (via a control panel that comes with xampp) Then look for the htdocs directory of your apache installation. All your PHP files need to go in this directory, so move your program there. Open your browser, and point it to http://localhost/myFile.php (where of course myFile.php is your file's name) It should work.



Hope this helps!
anonymous
2016-05-26 15:10:03 UTC
PHP is a cross platform. You write a php file for windows based IIS running PHP. And this file will work, without any change in code, on all other operating systems running any web server with PHP installed.
just "JR"
2010-01-22 06:13:00 UTC
I think you are trying to run it from your computer.

You may have Php installed, but that is not the way it works...

Your "hello.php" must be installed on a server that has a connection to the web, and Php installed.

Your PC must then load Firefox, and you must call the DOMAIN that holds your code, with the name of the file if it is not "index.php".

If you have set-up your PC as a server, you WILL run into trouble if trying to call your "server" from the same PC.

(Ideally, set-up a small "intranet", with two PCs. One acts as a server, and yours as the "client". It is always a bad idea to have both on the same machine.)
anonymous
2010-01-22 08:45:27 UTC
you will have to execute it on a server running php. PHP is not a static language like HTML.

Try installing WAMP or Apache and PHP.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...