I am new to PHP, just downloaded it, and wrote a “Hello, World!” program:
<html> <body> <?php $fileName = "test.jpg"; $txt = "Hello, World!"; echo $txt; ?> </body> </html>
But it doesn’t work. I named the file
test.php and opened it with Firefox and nothing was displayed.
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
PHP is a server-side language, thus you can’t just open the PHP file in a browser. Instead, try googling some free PHP hosts, and upload your files there.
You could for example go for these solutions that will provide you with what you need:
- WAMP – http://www.wampserver.com/en/ (Windows)
- XAMPP – http://www.apachefriends.org/en/xampp.html – (Windows, Mac, and Linux)
Those solutions will install Apache, MySQL and PHP and allow you to play locally with PHP development. Later on, if you want to deploy your code, you will have to find an external host (or host it on your own computer).
You need to have a webserver that you open it through. Simply entering file:///whatever.php does not work, because the file is not parsed by PHP then.
There are several web servers you can chose from, but my advice is Apache, the worlds most popular webserver. I have it running on my Windows XP laptop along with PHP, and it’s easy to install and setup, and works great. There are lots of modules that can be installed later if you need them. It’s also free, not only as in free beer, but also as in open source.
If you have command-line PHP installed, you should be able to enter:
to invoke PHP to run your program and display the output on the console.
You need a webserver to view the PHP program like XAMPP or WAMP. If you are using XAMPP, put your file in htdocs and then access your file from any browser like Google Chorme, Firefox or Internet Explorer by typing
localhost/foldername/yourfile.php, in your case
Do you have a local server installed? PHP is a server-side scripting language, so it cannot just be run like a normal HTML file.
Try watching the first few videos on the New Boston’s PHP series. They show you simply how to download, install and use a local server to run your PHP on.
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂