PHP Hello World
Create a file named hello.php and save it in the root directory of your web server with the following content.
PHP Hello World Example
Run Example ››
<?php echo 'Hello World';
Now, enter your web server's URL in your browser, ending with /hello.php. If you are using a web server installed on PC, the full URL might be http://localhost/hello.php or http://127.0.0.1/hello.php.
If you are using a host use the domain or sub-domain they have provided.
If everything configures correctly, you will see "Hello World" message in your browser. Great! you have just created your first PHP web page!
If you do not see any output, browser prompt for a download, or you see PHP file as text, then, either PHP is not enabled in your server or something went wrong on configuring. Read installation guide to learn more. If you are using a host, contact them to find a solution.
Didn't find a solution yet? The best place to ask for help is StackOverflow. Ask a new question there adding the appropriate tags to it (ex: PHP, MYSQL, Apache, WAMP, etc.).
Learn how to ask questions on StackOverflow here.
The Logic of the Localhost
After you install a server in your computer, it reserves the domain http://localhost for itself. When you enter the address http://localhost/hello.php, the browser will send an HTTP request to the server in your computer. The server will find for hello.php in its root directory. Then the server will send back a response after executing the PHP file.
If you didn't get everything, don't worry. You will learn everything gradually.