Hi,

I am pretty new to this scripting language.
I have just installed the following s/w packages in my system via XAMPP.
>php
>MySQL
>Apache

Next,I started writing a basic script in notepad and saved it as "hello.php"

My question is where to run this script, either in the Command line or in the Browser?
When I tried in cmd prompt: D:\SQL\01>hello.php
A small window opens stating that:" Windows cannot open this file"
and When I tried opening in browser: http://localhost/hello.php
it shows "Object not found".


As I am a beginner, could any one please let me know what should be done to properly execute my first program!!!
my script is very simple ,it should display "HELLO WORLD"!!! But am not getting this output displayed.

Is it because am doing any blunder mistake? or any further packages needed?
Or it is because of not knowing how to execute my program.


Thanking in advance,
Mahaa.

Any reason that you wouldn't consult the XAMPP FAQ at:
XAMPP FAQ

Which says:
The DocumentRoot folder is "\xampp\htdocs". There is the index site (index.php) the real start page which is loaded after executing of "http://localhost/". Alternatively, this page can also be deleted and replaced by your own "index.php" or "index.html".

After changing the index page in DocumentRoot, you will still find the XAMPP demopage with the URI http://localhost/xampp/.

A web server has a root document folder as it says above. That is where you put your code and that is where you execute from (as http:/localhost...)

To run PHP on command line you probably want PHP CLI.

then you do something like: php-cli php_file.php

Any reason that you wouldn't consult the XAMPP FAQ at:
XAMPP FAQ

Which says:
The DocumentRoot folder is "\xampp\htdocs". There is the index site (index.php) the real start page which is loaded after executing of "http://localhost/". Alternatively, this page can also be deleted and replaced by your own "index.php" or "index.html".

After changing the index page in DocumentRoot, you will still find the XAMPP demopage with the URI http://localhost/xampp/.

A web server has a root document folder as it says above. That is where you put your code and that is where you execute from (as http:/localhost...)

.....................................................................................

Thank you so much Chrishea.

It worked!!! I just pasted the notepad (hello.php) in the document root folder
"\xampp\htdocs\", and executed in browser "http://localhost/hello.php"
I was able to view the output in my broswer, HELLO WORLD!!!

Is this the way we normally execute all php scripts?
Any '.php files' has to be placed in document root folder only?

To run PHP on command line you probably want PHP CLI.

then you do something like: php-cli php_file.php

......................................................................

Hi,
Thank you for the reply.

Could you pls let me know how to check out whether I have php-cli enabled in my system?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.