PHP TUTORIALPHP IntroductionPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP CommentsPHP VariablesPHP Variable ScopePHP ConstantsPHP OutputPHP Data TypesPHP Type CastingPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP StringsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms Finishing

PHP Hello World

Create a file named hello.php and save it in the root directory of your web server with the following content.

Default root directories:
  • WAMP Server - C:\wamp\www\
  • XAMPP Server - C:\xampp\htdocs\
  • Linux OS - /var/www/
  • Mac OS - /htdocs/
  • PHP Hello World Example

    echo 'Hello World'; 
    Run Example ››

    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

    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!

    No Message?

    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.).

    StackOverflow is a huge community of developers and programmers.

    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.