"Hello world" in PHP shows nothing

I'm new to PHP, just downloaded it and wrote "Hello, World!" :

<html> <body> <?php $fileName = "test.jpg"; $txt = "Hello, World!"; echo $txt; ?> </body> </html> 

But that will not work. I named the file test.php and opened it with Firefox and nothing was shown.

+4
source share
6 answers

You will need to pass it through some kind of web server like IIS or Apache for it to work.

PHP is a server-side language, so you cannot just open a PHP file in a browser. Instead, try running some free PHP hosts and upload your files there.

You can, for example, go for these solutions that will provide you with what you need:

These solutions will install Apache, MySQL and PHP and allow you to play locally with the development of PHP. Later, if you want to deploy your code, you will have to find an external host (or host it on your own computer).

+16
source

You need to have a web server through which you open it. Just entering the file: ///whatever.php does not work, because then the file is not processed by PHP.

You can select multiple web servers, but my advice is Apache is the most popular web server in the world. It works for me on my laptop with Windows XP along with PHP, and it is easy to install and configure, and it works fine. There are many modules that can be installed later if you need them. It is also free, not only in free beer, but also in open source.

+6
source

You will need to install a web server on your computer for it to work. Take a look at XAMPP at http://www.apachefriends.org/en/index.html .

+5
source

If you installed command-line PHP , you should be able to enter:

 php test.php 

to call PHP to run your program and display the output on the console.

+2
source

You need a web server to view a PHP program, such as XAMPP or WAMP . If you use XAMPP, put your file in htdocs and then access your file from any browser such as Google Chorme, Firefox or Internet Explorer by typing localhost/foldername/yourfile.php , in your case localhost/test.php .

+2
source

Is a local server installed? PHP is a server-side scripting language, so you cannot just run it like a regular HTML file.

Try watching the first few videos on the New Boston PHP series . They show you how to download, install and use a local server to run your PHP.

+1
source

All Articles