PHP TUTORIALPHP TutorialPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP CommentsPHP VariablesPHP Variable ScopePHP ConstantsPHP StringsPHP OutputPHP Data TypesPHP Type CastingPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP String FunctionsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP AdvancedPHP Include and RequirePHP HTTP & HTTPSPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms FinishingPHP OOPPHP OOP IntroductionPHP OOP ClassesPHP OOP PropertiesPHP OOP ObjectsPHP OOP MethodsPHP OOP $this KeywordPHP OOP Constructors and DestructorsPHP OOP VisibilityPHP OOP InheritancePHP OOP Abstract Classes and MethodsPHP OOP InterfacesPHP OOP TraitsPHP OOP ConstantsPHP OOP StaticPHP OOP NamespacesPHP OOP Autoloading

PHP Hello World

Default Extension

The default file extension for PHP is .php. The web server will recognize and execute the files with the .php extension as PHP files by default.

Hello World Script

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

echo 'Hello World'; 

Run Example ››
Default root directories:
  • WAMP Server - C:\wamp\www\
  • XAMPP Server - C:\xampp\htdocs\
  • Linux OS - /var/www/
  • Mac OS - /htdocs/
  • Now, enter your web server's URL in your browser, ending with /hello.php. As you are using a web server installed on PC, the full URL might be http://localhost/hello.php or

    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 one (or more) of the following could be the reason.

    • PHP is not enabled in your server
    • Something went wrong on configuring
    • You haven't saved the file with the extension .php

    What should you do now?

    • First, make sure that your file is named as hello.php and saved in the root directory of your web server.
    • Follow our installation guide again.
    • Find an answer on the internet. Type your question in a search engine and find an answer from the websites that the search engine suggests.
    • StackOverflow! It is a great community of developers where you can get help from. Before you ask a question there, mind searching if your question is already answered. If you find any answer that is written for a question similar to your one, try to follow the instructions given in the answer. If you don't find any related question, ask your own question adding the appropriate tags to it (ex: PHP, MYSQL, Apache, WAMP, etc.)

    The Logic of the Localhost

    After you install a server in your computer, it reserves the address 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 hello.php in its root directory. Then the server will send back a response after executing the PHP file.

    How does localhost work?
    How does localhost work?

    If you didn't get everything mentioned here, don't worry. You will learn everything gradually.

    Visit PHP Help group to get some help from experts.
    Profile Picture
    Supun Kavinda
    I'm the Founder of Hyvor, Web Developer, Physics Lover, Flutist, and a Table Tennis Player.
    My Websites